Permalink
Browse files

Add RackSpace monitoring plugins

  • Loading branch information...
1 parent 62f9a34 commit b354f28110a174c67084de0726673bd9ffe28467 @korjik korjik committed Feb 25, 2012
Showing with 145 additions and 0 deletions.
  1. +8 −0 plugins/rackspace/README
  2. +70 −0 plugins/rackspace/rackspace_cdn_count.php
  3. +67 −0 plugins/rackspace/rackspace_cdn_size.php
View
@@ -0,0 +1,8 @@
+======================================================================================
+These plugins are made to monitor RackSpace Cloudfiles storage usage and files
+count.
+
+======================================================================================
+
+Andrey Kozhokaru
+andrey@kozhokaru.com
@@ -0,0 +1,70 @@
+#!/usr/bin/php
+# Author Andrey Kozhokaru <andrey@kozhokaru.com>
+# Plugin to monitor Rackspace File count
+#
+# Parameters:
+#
+# config (required)
+#
+#
+#%# family=manual
+
+
+<?php
+$x_auth_user='###NAME';
+$x_auth_key='###KEY';
+$api_url='https://auth.api.rackspacecloud.com/v1.0/';
+
+function SplitTwice($content,$first,$second) {
+ $s1=split($first,$content);
+ $splitted=split($second,$s1[1]);
+ return trim($splitted[0]);
+ }
+
+
+if ($argv[1]=='config'){
+ print "graph_title Rackspace CDN files count\n";
+ print "graph_vlabel Files Count\n";
+ print "graph_category rackspace\n";
+ print "count.label files count\n";
+ print "graph_args --base 1000\n";
+
+ exit;
+}
+
+$header_auth = array("X-Auth-User:$x_auth_user","X-Auth-Key:$x_auth_key");
+
+//Authentication
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $api_url);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header_auth);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
+ $data = curl_exec($ch);
+ curl_close($ch);
+
+
+$cdn_url= SplitTwice($data,'X-Storage-Url: ','Cache');
+$token= SplitTwice ($data,'X-Auth-Token:','X-Storage-Token:');
+
+
+$header_cdn = array ("X-Auth-Token:$token");
+
+
+//Get data
+ $ch1 = curl_init();
+ curl_setopt($ch1, CURLOPT_URL, $cdn_url);
+ curl_setopt($ch1, CURLOPT_HEADER, true);
+ curl_setopt($ch1, CURLOPT_HTTPHEADER, $header_cdn);
+ curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30);
+ $data1 = curl_exec($ch1);
+ curl_close($ch1);
+
+$objects_count = SplitTwice($data1,'X-Account-Object-Count:','X-Account-Bytes-Used:');
+$objects_bytes_used = SplitTwice ($data1,'X-Account-Bytes-Used:','X-Account-Container-Count:');
+
+echo 'count.value '.$objects_count;
+
+?>
@@ -0,0 +1,67 @@
+#!/usr/bin/php
+# Author Andrey Kozhokaru <andrey@kozhokaru.com>
+# Plugin to monitor Rackspace CloudFile storage usage
+#
+# Parameters:
+#
+# config (required)
+#
+#
+#%# family=manual
+
+<?php
+$x_auth_user='###NAME';
+$x_auth_key='###KEY';
+$api_url='https://auth.api.rackspacecloud.com/v1.0/';
+
+function SplitTwice($content,$first,$second) {
+ $s1=split($first,$content);
+ $splitted=split($second,$s1[1]);
+ return trim($splitted[0]);
+ }
+
+
+if ($argv[1]=='config'){
+ print "graph_title Rackspace CDN storage usage\n";
+ print "graph_vlabel CDN storage usage\n";
+ print "graph_category rackspace\n";
+ print "usage.label storage usage\n";
+ print "graph_args --base 1024\n";
+
+ exit;
+ }
+
+$header_auth = array("X-Auth-User:$x_auth_user","X-Auth-Key:$x_auth_key");
+
+//Authenticate
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $api_url);
+ curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header_auth);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
+ $data = curl_exec($ch);
+ curl_close($ch);
+
+
+$cdn_url= SplitTwice($data,'X-Storage-Url: ','Cache');
+$token= SplitTwice ($data,'X-Auth-Token:','X-Storage-Token:');
+
+
+$header_cdn = array ("X-Auth-Token:$token");
+
+//Get data
+ $ch1 = curl_init();
+ curl_setopt($ch1, CURLOPT_URL, $cdn_url);
+ curl_setopt($ch1, CURLOPT_HEADER, true);
+ curl_setopt($ch1, CURLOPT_HTTPHEADER, $header_cdn);
+ curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30);
+ $data1 = curl_exec($ch1);
+ curl_close($ch1);
+
+$objects_bytes_used = SplitTwice ($data1,'X-Account-Bytes-Used:','X-Account-Container-Count:');
+
+echo 'usage.value '.$objects_bytes_used;
+
+?>

0 comments on commit b354f28

Please sign in to comment.