Get Virtualizor

VPS Statistics

Use the VPS Statistics API to display data about your VPSes. By default stats of all the VPSes are returned by the API, for getting statistics of individual VPS you need to pass in the VPS ID as POST parameter. The data is returned in the form of array where pie_data consist of server_bandwidth which shows monthly usage of each day from 1st day of the month to the 31st i.e. last day of the month. Which is again shown in terms of "in" and "out" where "in" means data received and "out" means data sent from the vps. The "server_cpu" key consists of the name of the cpu, the processing limit of the cpu and how much is being utilized and how much of it is free. The "server_ram" consists of the amount of ram being utilized and amount which is free. The "vps_data" key shows the statistics related to each vps.

HTTP Request

https://hostname:4085/index.php?act=vps_stats

Parameters

NameMethodValueDescriptionRequired
actGETvps_statsReturns the VPS StatisticsYes
svsPOSTvpsidIf Set, it will return VPS Statistics.Set if you want vps_stat month wise
showPOSTmonthIf Set, it will return VPS Statistics month wise. For eg :- 201909 (y-m)Set if you want vps_stat month wise
vpsidPOSTIntID of the vps. If set returns vps_data per vps.No
seridPOSTIntID of the serverNo

Sample Code (if you set vpsid only)

<?php

    require_once('/usr/local/virtualizor/sdk/admin.php');

    $key =  'your_api_key';
    $pass = 'your_api_pass';
    $ip = 'your_server_ip';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    $post['vpsid'] = 45; //Set this only when you want vps_data
    $output = $admin->vps_stats($post);

    print_r(json_encode($output));

?>

Output

{
    "title": "VPS Statistics",
    "pie_data": {
        "server_bandwidth": {
            "limit": 5349.67,
            "used": 5348.67,
            "usage": {
                "1": 0,
                "2": 0,
                "3": 211.57,
                "4": 2186.15,
                "5": 1848.27,
                "6": 307.55,
                "7": 569.66,
                "8": 31.48,
                "9": 0,
                "10": 193.99,
                "11": 0,
                "12": 0,
                "13": 0,
                "14": 0,
                "15": 0,
                "16": 0,
                "17": 0,
                "18": 0,
                "19": 0,
                "20": 0,
                "21": 0,
                "22": 0,
                "23": 0,
                "24": 0,
                "25": 0,
                "26": 0,
                "27": 0,
                "28": 0,
                "29": 0,
                "30": 0
            },
            "in": {
                "usage": {
                    "1": 0,
                    "2": 0,
                    "3": 197.9,
                    "4": 2006.43,
                    "5": 1689.59,
                    "6": 270.1,
                    "7": 555.76,
                    "8": 28.44,
                    "9": 0,
                    "10": 171.24,
                    "11": 0,
                    "12": 0,
                    "13": 0,
                    "14": 0,
                    "15": 0,
                    "16": 0,
                    "17": 0,
                    "18": 0,
                    "19": 0,
                    "20": 0,
                    "21": 0,
                    "22": 0,
                    "23": 0,
                    "24": 0,
                    "25": 0,
                    "26": 0,
                    "27": 0,
                    "28": 0,
                    "29": 0,
                    "30": 0
                },
                "used": 4919.46,
                "limit": 4920.46,
                "free": 1,
                "limit_gb": 4.80513671875,
                "used_gb": 4.8,
                "free_gb": 0.0009765625,
                "percent": 99.979676696894,
                "percent_free": 0.020323303105812
            },
            "out": {
                "usage": {
                    "1": 0,
                    "2": 0,
                    "3": 13.67,
                    "4": 179.72,
                    "5": 158.68,
                    "6": 37.45,
                    "7": 13.9,
                    "8": 3.04,
                    "9": 0,
                    "10": 22.74,
                    "11": 0,
                    "12": 0,
                    "13": 0,
                    "14": 0,
                    "15": 0,
                    "16": 0,
                    "17": 0,
                    "18": 0,
                    "19": 0,
                    "20": 0,
                    "21": 0,
                    "22": 0,
                    "23": 0,
                    "24": 0,
                    "25": 0,
                    "26": 0,
                    "27": 0,
                    "28": 0,
                    "29": 0,
                    "30": 0
                },
                "used": 429.2,
                "limit": 430.2,
                "free": 1,
                "limit_gb": 0.4201171875,
                "used_gb": 0.42,
                "free_gb": 0.0009765625,
                "percent": 99.767549976755,
                "percent_free": 0.23245002324501
            },
            "free": 1,
            "limit_gb": 5.22,
            "used_gb": 5.22,
            "free_gb": 0,
            "percent": 99.98,
            "percent_free": 0.02
        },
        "server_cpu": {
            "manu": "intel",
            "cpumodel": " Intel(R) Pentium(R) CPU G620 @ 2.60GHz",
            "limit": 2600,
            "used": 2.6,
            "free": 2597.4,
            "percent": 0.1,
            "percent_free": 99.9
        },
        "server_ram": {
            "0": {
                "used_ram": 806,
                "ram": 1989
            },
            "-1": {
                "used_ram": 0,
                "ram": 0
            }
        }
    },
    "vps_stats": null,
    "vps_data": {
        "74": {
            "status": 1,
            "net_in": 52,
            "net_out": 0,
            "used_cpu": "0.0",
            "used_ram": "128",
            "ram": "128",
            "used_disk": 0.68312072753906,
            "disk": "2",
            "used_inode": 20124,
            "inode": 122880,
            "used_bandwidth": 0,
            "bandwidth": 1,
            "virt": "kvm",
            "io_read": 0,
            "io_write": 0,
            "vpsid": "74",
            "vps_name": "v1001",
            "hostname": "www.mydomain.com",
            "vps_ram_info": false,
            "speed_cap": null
        },
        "75": {
            "status": 0,
            "net_in": 0,
            "net_out": 0,
            "used_cpu": 0,
            "used_ram": 0,
            "ram": 0,
            "used_disk": 0.68306732177734,
            "disk": "2",
            "used_inode": 20109,
            "inode": 122880,
            "used_bandwidth": 0,
            "bandwidth": 1,
            "virt": "kvm",
            "io_read": 0,
            "io_write": 0,
            "vpsid": "75",
            "vps_name": "v1002",
            "hostname": "www.mydomain.com",
            "vps_ram_info": false,
            "speed_cap": null
        },
        "77": {
            "status": 1,
            "net_in": 52,
            "net_out": 0,
            "used_cpu": "1.0",
            "used_ram": "128",
            "ram": "128",
            "used_disk": 0.68425369262695,
            "disk": "2",
            "used_inode": 20067,
            "inode": 122880,
            "used_bandwidth": 0,
            "bandwidth": 1,
            "virt": "kvm",
            "io_read": 0,
            "io_write": 0,
            "vpsid": "77",
            "vps_name": "v1003",
            "hostname": "www.mydomain.com",
            "vps_ram_info": false,
            "speed_cap": null
        }
    },
    "month": null,
    "notice": null,
    "timenow": 1536602202,
    "time_taken": "2.156"
}

Sample Code (if you set svs and show)

NOTE: This will fetch the data as per the value passed for show parameter.
E.g. If you set show=201905 then it will fetch the values for May 2019.

<?php

    require_once('/usr/local/virtualizor/sdk/admin.php');

    $key =  'your_api_key';
    $pass = 'your_api_pass';
    $ip = 'your_server_ip';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    //set svs and show only when you want vps_stat month wise.
    $post['svs'] = 45; //if you want vps stats per vps
    $post['show'] = 201910; //if you want vps_stat month wise format (y-m)

    $output = $admin->vps_stats($post);

    print_r(json_encode($output));

?>

Output

{
   "title":"VPS Statistics",
   "pie_data":null,
   "vps_stats":[
      [
         "45", //vpsid
         "1570776006", //time
         "1", //status
         "0", //disk
         "0", //inode
         "0", //ram
         "0.60", //cpu
         "0.60", //actual_cpu
         "1266", //net_in
         "0", //net_out
         "0", //io_read
         "0" //io_write
      ],
      [
         "45", //vpsid
         "1570776060", //time
         "1", //status
         "0", //disk
         "0", //inode
         "0", //ram
         "0.70", //cpu
         "0.70", //actual_cpu
         "1350", //net_in
         "0", //net_out
         "0", //io_read
         "0" //io_write
      ]
   ],
   "vps_data":null,
   "month":{
      "current_month":"201910",
      "prev_month":"201909",
      "next_month":"201911"
   },
   "notice":null,
   "timenow":1570776103,
   "time_taken":"0.076"
}

    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list