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::Plugins::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");
42 my $vl = { plugin => 'monitorus', type => 'gauge' };
44 # Only retrieve a value occasionally in order to not overload mon.itor.us
45 if (++$intervalcnt<NUM_OF_INTERVALS) { # e.g. 180 * 10 secs / 60 seconds/min = 30 minutes
46 $vl->{'values'} = [ $prev_value ];
47 plugin_dispatch_values ($vl);
53 my $site = 'http://mon.itor.us';
54 my $username = 'me@example.org';
55 my $target = $site.'/user/api/'.$username.'/secretpassword';
57 my $ua = LWP::UserAgent->new;
58 my $req = HTTP::Request->new(GET => "$target");
59 $req->header('Accept' => 'text/html'); #Accept HTML Page
62 my $res = $ua->get($target);
63 if ($res->is_success) {# Success....all content of page has been received
64 $res->content() =~ m/\[CDATA\[(.*)\]\]/;
67 INFO("monitorus: Error in retrieving login page.");
70 $target = $site.'/test/api/'.$key.'/testNames';
72 $res = $ua->get($target);
73 if ($res->is_success) {# Success....all content of page has been received
74 $res->content() =~ m/<test id='(.*)'><!\[CDATA\[sitetest_http\]\]/;
77 INFO("monitorus: Error in retrieving testNames page.");
80 #$target = $site.'/test/api/'.$key.'/testinfo/'.$testid.'/-240';
81 #$target = $site.'/test/api/'.$key.'/test/'.$testid.'/27/5/2009/1/3/-240';
82 $target = $site.'/test/api/'.$key.'/testsLastValues/1/3';
86 $res = $ua->get($target);
87 if ($res->is_success) {# Success....all content of page has been received
88 $res->content() =~ m/\<\/row\>\s*(\<row\>.*?sitetest_http.*?\<\/row\>)/s;
90 $result =~ s/\<cell\>.*?CDATA.*?\<\/cell\>//g;
91 $result =~ m|\<cell\>([0-9]*)\<\/cell\>|;
94 INFO("monitorus: Error in retrieving testsLastValues page.");
98 $vl->{'values'} = [ $value ];
99 plugin_dispatch_values ($vl);