Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Scripting / API
  • Search

Get Bandwidth Usage

Questions regarding the API
Application Programming Interface
Locked
  • Print view
Advanced search
9 posts • Page 1 of 1
patstan
Posts: 117
Joined: Wed Jul 30, 2014 10:53 am

Get Bandwidth Usage

Post by patstan » Tue Apr 21, 2015 3:41 pm

Can anyone tell me how to get the disk usage by using the API from php?

Thanks
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Get Bandwidth Usage

Post by skurudo » Thu May 07, 2015 8:21 am

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
Top

patstan
Posts: 117
Joined: Wed Jul 30, 2014 10:53 am

Re: Get Bandwidth Usage

Post by patstan » Thu May 07, 2015 8:35 am

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.
Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Get Bandwidth Usage

Post by skurudo » Thu May 07, 2015 8:37 am

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?
Top

patstan
Posts: 117
Joined: Wed Jul 30, 2014 10:53 am

Re: Get Bandwidth Usage

Post by patstan » Thu May 07, 2015 9:16 am

skurudo wrote: May be you can parse output?
Doesnt seem to work
Top

joem
Posts: 378
Joined: Thu Nov 13, 2014 8:33 am

Os: CentOS 6x
Web: nginx + php-fpm
Re: Get Bandwidth Usage

Post by joem » Thu May 07, 2015 11:42 am

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>';

?>

Top

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Get Bandwidth Usage

Post by skurudo » Thu May 07, 2015 1:50 pm

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>';
Top

patstan
Posts: 117
Joined: Wed Jul 30, 2014 10:53 am

Re: Get Bandwidth Usage

Post by patstan » Thu May 07, 2015 2:31 pm

@joem

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

skurudo
VestaCP Team
Posts: 8099
Joined: Fri Dec 26, 2014 2:23 pm
Contact:
Contact skurudo
Website Facebook Google+ Skype
Twitter

Re: Get Bandwidth Usage

Post by skurudo » Fri Sep 23, 2016 12:33 pm

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
Top


Locked
  • Print view

9 posts • Page 1 of 1

Return to “Scripting / API”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password