Stat Event

Event that fires when the Stat of a specified entity is updated.

Event name

stat

Request

This event requires you to specify the entity, whose stat you’ll be retrieving. The format is entityType:entityId. Entity type can be 1 for object, 2 for link.

You also need to use add-filtered-topic and remove-filtered-topic events to subscribe and unsubscribe instead of add-topics and remove-topics.

  • Subscribe

  • Unsubscribe

cn.emit('add-filtered-topic', 'stat', '1:634023d414d3e37c5d8c865b')
cn.emit('remove-filtered-topic', 'stat', '1:634023d414d3e37c5d8c865b')

Response

Response contains the following fields:

Field Type Description

entityId

String

ID of the entity whose stat was retrieved.

entityType

Integer

Type of the entity whose stat was retrieved.

timestamp

String

Time when the stat was received.

payload

Stat

Body of the stat that was retrieved.

Example

Request

const comet = require('socket.io-client');

// Comet settings
const COMET_CONNECT_TIMEOUT = 5000;
const sessionId = "..."
const conf = {
    cometHost: 'https://example.com',
    cometPort: '1234',
};

const url = `${conf.cometHost}` + (conf.cometPort ? `:${conf.cometPort}` : '');
const cn = comet.connect(url, {
    query: { forceNew: true, sessionId },
    timeout: COMET_CONNECT_TIMEOUT,
});

cn.emit('add-filtered-topic', 'stat', '1:634023d414d3e37c5d8c865b')

cn.on('stat', msg => {
      console.log(msg);
});

Response

{
  "entityId":"634023d414d3e37c5d8c865b",
  "entityType":1,
  "timestamp":1667386124534,
  "payload":{
    "taskType":"ping",
    "period":1000,
    "timestamp":1667386124534,
    "agentId":"625439c60db03e3f4504b548",
    "payload":{
      "packetsTransmitted":5,
      "packetsReceived":5,
      "packetLossPercentile":0,
      "numberOfErrors":0,
      "numberOfDuplicates":0,
      "roundTripMinimal":15.341,
      "roundTripAverage":15.408,
      "roundTripMaximum":15.453,
      "exitCode":0
      }
    }
}