📜 ⬆️ ⬇️

Munin: Monitoring Rackspace Storage

image Good day!

We store pictures in the Rackspace CDN. The task was set: to display graphics using the CDN, namely the number of objects and occupied space.

As for me, the best tool for breeding this kind of grfik is Munin. It is very easy to write a plugin for it in almost any language, and the data can be output as you please.
')
I wrote 2 plug-ins to Munin, which, according to the Rackspace API, can indicate to you how many files you have in the stack and their total size.


Plugin number 1: rackspace_cdn_count.php

#!/usr/bin/php <?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; ?> 


Plugin # 2: rackspace_cdn_size.php
 #!/usr/bin/php <?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; ?> 


The subject looks like this:
image

The expected result is an increase in the number of objects and their volume.

Source: https://habr.com/ru/post/138805/


All Articles