Get Bandwidth Usage
Posted: Tue Apr 21, 2015 3:41 pm
Can anyone tell me how to get the disk usage by using the API from php?
Thanks
Thanks
From current API I don't see a way to get disk usage. ;-(patstan wrote:Can anyone tell me how to get the disk usage by using the API from php?
Actually the "List User Account" API code shows it, but it returns many other items including package name etc. I need a way to isolate the bandwidth/disk usage.skurudo wrote:From current API I don't see a way to get disk usage. ;-(patstan wrote:Can anyone tell me how to get the disk usage by using the API from php?
https://vestacp.com/docs/api
May be you can parse output?patstan wrote:Currently print_r($data) is printing everything. I just want to print the disk/bandwidth usage if that makes sense.
Doesnt seem to workskurudo wrote: May be you can parse output?
Code: Select all
<?php
// Server credentials
$vst_hostname = '';
$vst_username = 'admin';
$vst_password = '';
$vst_command = 'v-list-user';
// Account
$username = 'admin';
$format = 'json';
// Prepare POST query
$postvars = array(
'user' => $vst_username,
'password' => $vst_password,
'cmd' => $vst_command,
'arg1' => $username,
'arg2' => $format
);
$postdata = http_build_query($postvars);
// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Parse JSON output
$data = json_decode($answer, true);
echo 'Total BANDWIDTH '.$data[$username]['BANDWIDTH'].'<br>';
echo 'Total USED BANDWIDTH '.$data[$username]['U_BANDWIDTH'].'<br>';
echo 'Total DISKSPACE '.$data[$username]['DISK_QUOTA'].'<br>';
echo 'Total USED DISKPACE '.$data[$username]['U_DISK'].'<br>';
?>
joem wrote:Code: Select all
// Parse JSON output $data = json_decode($answer, true); echo 'Total BANDWIDTH '.$data[$username]['BANDWIDTH'].'<br>'; echo 'Total USED BANDWIDTH '.$data[$username]['U_BANDWIDTH'].'<br>'; echo 'Total DISKSPACE '.$data[$username]['DISK_QUOTA'].'<br>'; echo 'Total USED DISKPACE '.$data[$username]['U_DISK'].'<br>';