root / plugins / rackspace / rackspace_cdn_size.php @ c5ab6538
Historique | Voir | Annoter | Télécharger (1,71 ko)
| 1 |
#!/usr/bin/php
|
|---|---|
| 2 |
# Author Andrey Kozhokaru <andrey@kozhokaru.com>
|
| 3 |
# Plugin to monitor Rackspace CloudFile storage usage
|
| 4 |
#
|
| 5 |
# Parameters:
|
| 6 |
#
|
| 7 |
# config (required)
|
| 8 |
#
|
| 9 |
#
|
| 10 |
#%# family=manual
|
| 11 |
|
| 12 |
<?php |
| 13 |
$x_auth_user='###NAME'; |
| 14 |
$x_auth_key='###KEY'; |
| 15 |
$api_url='https://auth.api.rackspacecloud.com/v1.0/'; |
| 16 |
|
| 17 |
function SplitTwice($content,$first,$second) { |
| 18 |
$s1=split($first,$content); |
| 19 |
$splitted=split($second,$s1[1]); |
| 20 |
return trim($splitted[0]); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
if ($argv[1]=='config'){ |
| 25 |
print "graph_title Rackspace CDN storage usage\n"; |
| 26 |
print "graph_vlabel CDN storage usage\n"; |
| 27 |
print "graph_category rackspace\n"; |
| 28 |
print "usage.label storage usage\n"; |
| 29 |
print "graph_args --base 1024\n"; |
| 30 |
|
| 31 |
exit;
|
| 32 |
} |
| 33 |
|
| 34 |
$header_auth = array("X-Auth-User:$x_auth_user","X-Auth-Key:$x_auth_key"); |
| 35 |
|
| 36 |
//Authenticate
|
| 37 |
$ch = curl_init();
|
| 38 |
curl_setopt($ch, CURLOPT_URL, $api_url); |
| 39 |
curl_setopt($ch, CURLOPT_HEADER, true); |
| 40 |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header_auth); |
| 41 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 42 |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
| 43 |
$data = curl_exec($ch); |
| 44 |
curl_close($ch);
|
| 45 |
|
| 46 |
|
| 47 |
$cdn_url= SplitTwice($data,'X-Storage-Url: ','Cache'); |
| 48 |
$token= SplitTwice ($data,'X-Auth-Token:','X-Storage-Token:'); |
| 49 |
|
| 50 |
|
| 51 |
$header_cdn = array ("X-Auth-Token:$token"); |
| 52 |
|
| 53 |
//Get data
|
| 54 |
$ch1 = curl_init();
|
| 55 |
curl_setopt($ch1, CURLOPT_URL, $cdn_url); |
| 56 |
curl_setopt($ch1, CURLOPT_HEADER, true); |
| 57 |
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header_cdn); |
| 58 |
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); |
| 59 |
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30); |
| 60 |
$data1 = curl_exec($ch1); |
| 61 |
curl_close($ch1);
|
| 62 |
|
| 63 |
$objects_bytes_used = SplitTwice ($data1,'X-Account-Bytes-Used:','X-Account-Container-Count:'); |
| 64 |
|
| 65 |
echo 'usage.value '.$objects_bytes_used; |
| 66 |
|
| 67 |
?>
|
