-
Notifications
You must be signed in to change notification settings - Fork 1
/
golang_stats_
executable file
·103 lines (76 loc) · 2.08 KB
/
golang_stats_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env perl
# -*- cperl -*-
=head1 NAME
golang_stats_ - Goblin stats value
=head1 APPLICABLE SYSTEMS
=head1 CONFIGURATION
This shows the default configuration of this plugin. You can override
the stats URL.
[golang_stats_*]
env.stats_api_url http://localhost:8080/api/stats
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
0.0.1
=head1 BUGS
None known
=head1 AUTHOR
Tatsuya Fukata <tatsuya.fukata@gmail.com>
=head1 LICENSE
Apache License 2.0
=cut
use strict;
use warnings;
use Munin::Plugin;
my $ret = undef;
if (! eval "require LWP::UserAgent;"){
$ret = "LWP::UserAgent not found";
}
if (! eval "require JSON;") {
$ret = "JSON not found";
}
unless ( $0 =~ /golang_stats_(.+)/ ) {
$ret = "item name not found";
}
if ($ret){
print "no ($ret)\n";
exit 0;
}
my $URL = exists $ENV{stats_api_url} ? $ENV{stats_api_url} : "http://localhost:8080/api/stats";
my $item = $1;
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
my $ua = LWP::UserAgent->new(
timeout => 30,
agent => sprintf("munin/%s (libwww-perl/%s)", $Munin::Common::Defaults::MUNIN_VERSION, $LWP::VERSION)
);
my $response = $ua->request(HTTP::Request->new('GET',$URL));
unless ($response->is_success) {
print "no (no golang stats on $URL)\n";
exit 0;
} else {
print "yes\n";
exit 0;
}
}
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_title $item\n";
print "graph_args --base 1000\n";
print "graph_category golang\n";
print "graph_vlabel $item\n";
print "total.label $item\n";
print "total.info $item\n";
print "total.draw LINE2\n";
exit 0;
}
my $ua = LWP::UserAgent->new(
timeout => 30,
agent => sprintf("munin/%s (libwww-perl/%s)", $Munin::Common::Defaults::MUNIN_VERSION, $LWP::VERSION)
);
my $response = $ua->request(HTTP::Request->new('GET',$URL));
my $json = JSON::decode_json($response->decoded_content);
if ( defined $json->{$item} ) {
print "total.value " . $json->{$item} . "\n";
} else {
print "total.value U\n";
}