Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing a problem with peripherals data collection #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions Datadog/datadog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const xapi = require('xapi'); // should be require('xapi')
const xapi = require('xapi');

const DD_TOKEN = 'REPLACE_ME'; // get a Client Token from your Datadog account here: https://app.datadoghq.com/organization-settings/client-tokens
const DD_URL = `https://browser-http-intake.logs.datadoghq.com/v1/input/${DD_TOKEN}`; // if your Datadog instance is in the EU region, use "datadog.eu" instead of "datadog.com"
Expand All @@ -19,13 +19,12 @@ const IN_CALL_STATUS_COMMAND_LIST = [
// configure the check frequency and status commands to run all the time, regardless of whether the room kit device is in a call
const GENERAL_CHECK_FREQUENCY = 300000; // 5 minutes by default; NOTE: must be larger (in seconds) than the number of STATUS_LIST commands + the number of peripherals connected to the roomkit.
const GENERAL_STATUS_COMMAND_LIST = [
'network',
'peripherals connecteddevice'
'network'
];
const MONITOR_PERIPHERALS = true; // perhipherals monitoring requires extra logic and processing

var tags = '';
const version = 'version:0.2.0';
const version = 'version:0.2.3';
if (DD_TAGS) {
tags = `${version},${DD_TAGS}`;
}
Expand Down Expand Up @@ -106,27 +105,13 @@ function sendHealthData(message){
// getting data

function getEachPeripheralData(perifData){
// the `xStatus Perhipherals ConnectedDevice [n]` commands must be run
// per peripheral device and with the id as an argument. we get the
// peripheral id list first from `xCommand Peripherals List`.
// we schedule the sending of data in 1s increments so as to avoid running out of HttpClient handlers on the device
// TODO: confirm that the results capture all device data. Early results suggest that some devices might be getting missed.
if (perifData['Device'].length > 0) {
for (let i = 0; i < perifData['Device'].length; i++) {
setTimeout(() => xapi.status.get('peripherals connecteddevice '+perifData['Device'][i]['id'])
.then((stat) => { sendHealthData(formatHealthResults(
Object.assign(stat, {'peripherals_list_data': perifData['Device'][i]}),
'peripherals connecteddevice'
));
}), (i + STATUS_LIST.length + 1)*1000);
// iterate through the peripherals data and send them as unique events
if ((Object.prototype.toString.call(perifData) === '[object Array]') && perifData.length >= 1) {
for (let i = 0; i < perifData.length; i++) {
setTimeout(() => sendHealthData(formatHealthResults([perifData[i]], 'peripherals connecteddevice')), (i + GENERAL_STATUS_COMMAND_LIST.length + 1)*1000);
}
} else {
setTimeout(
() => sendHealthData(formatHealthResults(
[{'command_response': 'none'}],
'peripherals connecteddevice'
)), (STATUS_LIST.length + 1)*1000
);
setTimeout(() => sendHealthData(formatHealthResults([{'command_response': 'none'}], 'peripherals connecteddevice')), (GENERAL_STATUS_COMMAND_LIST.length + 1)*1000);
}
}

Expand Down Expand Up @@ -158,14 +143,16 @@ function getSystemData(){
});
}


function runInCallStatusCheck() {
checkStatus(IN_CALL_STATUS_COMMAND_LIST);
}


function runGeneralStatusCheck() {
checkStatus(GENERAL_STATUS_COMMAND_LIST);
if (MONITOR_PERIPHERALS) {
xapi.command('peripherals list').then((perifs) => { getEachPeripheralData(perifs); })
xapi.status.get('peripherals connecteddevice').then((perifs) => { getEachPeripheralData(perifs); })
}
}

Expand Down Expand Up @@ -201,4 +188,4 @@ function monitorRoomKit() {
});
}

monitorRoomKit();
monitorRoomKit();