Posting metrics to the API
You can use the API to add metrics to a server at Nixstats. This can be useful to post statistics to our API from inside your applications (error counts for example).
Using CURL with PHP
<?php
$timestamp = time();
$api_token = '3318e3223ac57e7aa5269a4aaf1abc1a2';
$server_id = '5aafddba3a2bbd3ae5230aa30';
// Creating 5 data points of the last 5 minutes.
$data_points[] = array($timestamp, 45);
$data_points[] = array($timestamp-60, 42);
$data_points[] = array($timestamp-120, 49);
$data_points[] = array($timestamp-180, 55);
$data_points[] = array($timestamp-240, 95);
$payload['metrics'][] = array("metric" => "motherboard.temp", "points" => $data_points);
//Submit several metric sets at once...
//$payload['metrics'][] = array("metric" => "motherboard.fanspeed", "points" => $data_points);
$ch = curl_init('https://api.eu.nixstats.com/v1/server/'.$server_id.'/store?token='.$api_token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($payload)))
);
$result = curl_exec($ch);
echo $result;
?>
Using CURL from the command line
curl -X POST -H "Content-type: application/json" -d "{ \"metrics\" :
[{\"metric\":\"motherboard.temp\",
\"points\":[[1523439139, 20],[1523439339, 40],[1523439539, 70]]}]
}" https://api.eu.nixstats.com/v1/server/5aafddba3a2bbd3ae5230aa30/store?token=3318e3223ac57e7aa5269a4aaf1abc1a2
Updated on: 11/04/2018
Thank you!