2 # collectd - mon.itor.us collectd plugin
3 # Copyright (C) 2009 Jeff Green
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; only version 2 of the License is applicable.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 # Jeff Green <jeff at kikisoso.org>
22 package Collectd::Plugin::Monitorus;
27 use Collectd qw( :all );
31 use constant NUM_OF_INTERVALS => 90;
33 my $intervalcnt :shared;
34 $intervalcnt=NUM_OF_INTERVALS;
35 my $prev_value :shared;
38 plugin_register (TYPE_READ, "monitorus", "monitorus_read");
39 plugin_register (TYPE_LOG, "monitorus", "monitorus_log");
43 my $vl = { plugin => 'monitorus' };
45 # Only retrieve a value occasionally in order to not overload mon.itor.us
46 if (++$intervalcnt<NUM_OF_INTERVALS) { # e.g. 180 * 10 secs / 60 seconds/min = 30 minutes
47 $vl->{'values'} = [ $prev_value ];
48 plugin_dispatch_values ('gauge', $vl);
54 my $site = 'http://mon.itor.us';
55 my $username = 'me@example.org';
56 my $target = $site.'/user/api/'.$username.'/secretpassword';
58 my $ua = LWP::UserAgent->new;
59 my $req = HTTP::Request->new(GET => "$target");
60 $req->header('Accept' => 'text/html'); #Accept HTML Page
63 my $res = $ua->get($target);
64 if ($res->is_success) {# Success....all content of page has been received
65 $res->content() =~ m/\[CDATA\[(.*)\]\]/;
68 INFO("monitorus: Error in retrieving login page.");
71 $target = $site.'/test/api/'.$key.'/testNames';
73 $res = $ua->get($target);
74 if ($res->is_success) {# Success....all content of page has been received
75 $res->content() =~ m/<test id='(.*)'><!\[CDATA\[sitetest_http\]\]/;
78 INFO("monitorus: Error in retrieving testNames page.");
81 #$target = $site.'/test/api/'.$key.'/testinfo/'.$testid.'/-240';
82 #$target = $site.'/test/api/'.$key.'/test/'.$testid.'/27/5/2009/1/3/-240';
83 $target = $site.'/test/api/'.$key.'/testsLastValues/1/3';
87 $res = $ua->get($target);
88 if ($res->is_success) {# Success....all content of page has been received
89 $res->content() =~ m/\<\/row\>\s*(\<row\>.*?sitetest_http.*?\<\/row\>)/s;
91 $result =~ s/\<cell\>.*?CDATA.*?\<\/cell\>//g;
92 $result =~ m|\<cell\>([0-9]*)\<\/cell\>|;
95 INFO("monitorus: Error in retrieving testsLastValues page.");
99 $vl->{'values'} = [ $value ];
100 plugin_dispatch_values ('gauge', $vl);
105 # This function is called when plugin_log () has been used.
111 print "LOG: $level - $msg\n";