Page 1 of 1

Get Bandwidth Usage

Posted: Tue Apr 21, 2015 3:41 pm
by patstan
Can anyone tell me how to get the disk usage by using the API from php?

Thanks

Re: Get Bandwidth Usage

Posted: Thu May 07, 2015 8:21 am
by skurudo
patstan wrote:Can anyone tell me how to get the disk usage by using the API from php?
From current API I don't see a way to get disk usage. ;-(
https://vestacp.com/docs/api

Re: Get Bandwidth Usage

Posted: Thu May 07, 2015 8:35 am
by patstan
skurudo wrote:
patstan wrote:Can anyone tell me how to get the disk usage by using the API from php?
From current API I don't see a way to get disk usage. ;-(
https://vestacp.com/docs/api
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.

Currently print_r($data) is printing everything. I just want to print the disk/bandwidth usage if that makes sense.

Re: Get Bandwidth Usage

Posted: Thu May 07, 2015 8:37 am
by skurudo
patstan wrote:Currently print_r($data) is printing everything. I just want to print the disk/bandwidth usage if that makes sense.
May be you can parse output?

Re: Get Bandwidth Usage

Posted: Thu May 07, 2015 9:16 am
by patstan
skurudo wrote: May be you can parse output?
Doesnt seem to work

Re: Get Bandwidth Usage

Posted: Thu May 07, 2015 11:42 am
by joem

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

Posted: Thu May 07, 2015 1:50 pm
by skurudo
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

Posted: Thu May 07, 2015 2:31 pm
by patstan
@joem

You sir are an absolute genius. I owe you one!

Re: Get Bandwidth Usage

Posted: Fri Sep 23, 2016 12:33 pm
by skurudo
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