We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Get Bandwidth Usage
Get Bandwidth Usage
Can anyone tell me how to get the disk usage by using the API from php?
Thanks
Thanks
Re: Get Bandwidth Usage
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
Re: Get Bandwidth Usage
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
Currently print_r($data) is printing everything. I just want to print the disk/bandwidth usage if that makes sense.
Re: Get Bandwidth Usage
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.
Re: Get Bandwidth Usage
Doesnt seem to workskurudo wrote: May be you can parse output?
Re: Get Bandwidth Usage
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>';
?>
Re: Get Bandwidth Usage
joem, you're awesome! Cool.
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>';
Re: Get Bandwidth Usage
@joem
You sir are an absolute genius. I owe you one!
You sir are an absolute genius. I owe you one!
Re: Get Bandwidth Usage
API documentation and examples:
http://vestacp.com/docs/API.pdf
CLI commands list and descriptions:
http://vestacp.com/docs/CLI.txt
-> viewtopic.php?f=18&t=12610
http://vestacp.com/docs/API.pdf
CLI commands list and descriptions:
http://vestacp.com/docs/CLI.txt
-> viewtopic.php?f=18&t=12610