Overview

You can use the 360 Monitoring API to add metrics to a server. This can be useful to post statistics to our API from inside your applications (for example, error counts).

CURL with PHP

The following example code demonstrates how to add metrics with PHP via CURL:

<?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.monitoring.platform360.io/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;
?>


CURL via command line

The following example code demonstrates how to add metrics via CURL on 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.monitoring.platform360.io/v1/server/5aafddba3a2bbd3ae5230aa30/store?token=3318e3223ac57e7aa5269a4aaf1abc1a2
Was this answer helpful? 0 Users Found This Useful (0 Votes)