Agentless postbacks

You can postback metrics to Server Density without using our monitoring agent. This is useful for complex environments, custom applications, firewalls or where it's not possible to install the agent.

In the PHP example below, we're posting back the amount of active sessions on a website. We then print the payload, the status of the postback request and the time it was posted at.

Scripts could be ran on a cron every minute, or whenever appropriate. You'll see these metrics under the "Custom Plugins" tab. See troubleshooting custom plugins.

Replace $agentKey, $account and $token with your details. Note that you must have first created a device in Server Density in order to obtain an agent key.


// replace with your details
$agentKey = '5ee51eb1aa62a198c8c80ac83448a32c';
$account  = 'example';
$token    = 'b97da06a41c5f61bav05975ee51lt1aa';

$sessions = count(Session::all());

$payload = '{"agentKey": "'.$agentKey.'", "plugins": {"website": {"sessions": "'.$sessions.'"}}}';
$hash = md5($payload);

$data = array("payload" => $payload, "hash" => $hash);
$ch = curl_init(''.$token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Forwarded-Host: '.$account.''

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "Payload:" . $payload;
echo "\r\n";
echo "Postback status: " . $result;
echo "\r\n";
echo "Posted at " . date("h:i:sa") . ' ' . date_default_timezone_get();