@jambonz/time-series 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +44 -1
- package/package.json +1 -1
- package/test/docker_start.js +1 -1
- package/test/docker_stop.js +1 -1
- package/test/unit-tests.js +17 -0
package/index.js
CHANGED
|
@@ -103,6 +103,17 @@ const schemas = {
|
|
|
103
103
|
'system_component',
|
|
104
104
|
'state'
|
|
105
105
|
]
|
|
106
|
+
},
|
|
107
|
+
krisp_usage: {
|
|
108
|
+
measurement: 'krisp_usage',
|
|
109
|
+
fields: {
|
|
110
|
+
usage_seconds: Influx.FieldType.INTEGER
|
|
111
|
+
},
|
|
112
|
+
tags: [
|
|
113
|
+
'service_provider_sid',
|
|
114
|
+
'account_sid',
|
|
115
|
+
'feature'
|
|
116
|
+
]
|
|
106
117
|
}
|
|
107
118
|
};
|
|
108
119
|
|
|
@@ -261,7 +272,7 @@ const createCdrCountQuery = ({trunk, direction, answered, filter, days, start, e
|
|
|
261
272
|
/* for Service Provider */
|
|
262
273
|
const createAlertsQuerySP = ({target_sid, alert_type, page, page_size, days, start, end}) => {
|
|
263
274
|
// eslint-disable-next-line max-len
|
|
264
|
-
let sql = 'SELECT
|
|
275
|
+
let sql = 'SELECT * FROM alerts WHERE service_provider_sid = $service_provider_sid ';
|
|
265
276
|
if (target_sid) sql += 'AND target_sid = $target_sid ';
|
|
266
277
|
if (alert_type) sql += 'AND alert_type = $alert_type ';
|
|
267
278
|
if (days) sql += 'AND time > $timestamp ';
|
|
@@ -528,6 +539,26 @@ const writeSystemAlerts = async(client, systemAlerts) => {
|
|
|
528
539
|
await writeData(client);
|
|
529
540
|
return;
|
|
530
541
|
};
|
|
542
|
+
|
|
543
|
+
const writeKrispUsage = async(client, usage) => {
|
|
544
|
+
if (!client.locals.initialized) await initDatabase(client, 'krisp_usage');
|
|
545
|
+
const {service_provider_sid, account_sid, feature, ...fields} = usage;
|
|
546
|
+
const data = {
|
|
547
|
+
measurement: 'krisp_usage',
|
|
548
|
+
timestamp: new Date(),
|
|
549
|
+
fields,
|
|
550
|
+
tags: {
|
|
551
|
+
service_provider_sid,
|
|
552
|
+
account_sid,
|
|
553
|
+
feature
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
client.locals.data = [...client.locals.data, ...[data]];
|
|
557
|
+
if (client.locals.data.length >= client.locals.commitSize) {
|
|
558
|
+
await writeData(client);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
|
|
531
562
|
const queryCdrsSP = async(client, opts) => {
|
|
532
563
|
if (!client.locals.initialized) await initDatabase(client, 'cdrs');
|
|
533
564
|
const response = {
|
|
@@ -784,6 +815,8 @@ module.exports = (logger, opts) => {
|
|
|
784
815
|
// eslint-disable-next-line max-len
|
|
785
816
|
const callCountAppClient = new Influx.InfluxDB({database: 'app_call_counts', schemas: schemas.app_call_counts, ...opts});
|
|
786
817
|
const systemAlertClient = new Influx.InfluxDB({database: 'system_alerts', schemas: schemas.system_alerts, ...opts});
|
|
818
|
+
// eslint-disable-next-line max-len
|
|
819
|
+
const krispUsageClient = new Influx.InfluxDB({database: 'krisp_usage', schemas: schemas.krisp_usage, ...opts});
|
|
787
820
|
|
|
788
821
|
cdrClient.locals = {
|
|
789
822
|
db: 'cdrs',
|
|
@@ -833,6 +866,14 @@ module.exports = (logger, opts) => {
|
|
|
833
866
|
commitInterval: opts.commitInterval || 10,
|
|
834
867
|
data: []
|
|
835
868
|
};
|
|
869
|
+
krispUsageClient.locals = {
|
|
870
|
+
db: 'krisp_usage',
|
|
871
|
+
initialized: false,
|
|
872
|
+
writing: false,
|
|
873
|
+
commitSize: opts.commitSize || 1,
|
|
874
|
+
commitInterval: opts.commitInterval || 10,
|
|
875
|
+
data: []
|
|
876
|
+
};
|
|
836
877
|
|
|
837
878
|
if (opts.commitSize > 1 && opts.commitInterval && opts.commitInterval > 2) {
|
|
838
879
|
setInterval(writeData.bind(null, callCountClient), opts.commitInterval * 1000);
|
|
@@ -840,6 +881,7 @@ module.exports = (logger, opts) => {
|
|
|
840
881
|
setInterval(writeData.bind(null, callCountAppClient), opts.commitInterval * 1000);
|
|
841
882
|
setInterval(writeData.bind(null, cdrClient), opts.commitInterval * 1000);
|
|
842
883
|
setInterval(writeData.bind(null, alertClient), opts.commitInterval * 1000);
|
|
884
|
+
setInterval(writeData.bind(null, krispUsageClient), opts.commitInterval * 1000);
|
|
843
885
|
}
|
|
844
886
|
|
|
845
887
|
return {
|
|
@@ -856,6 +898,7 @@ module.exports = (logger, opts) => {
|
|
|
856
898
|
queryAlerts: queryAlerts.bind(null, alertClient),
|
|
857
899
|
queryAlertsSP: queryAlertsSP.bind(null, alertClient),
|
|
858
900
|
writeSystemAlerts: writeSystemAlerts.bind(null, systemAlertClient),
|
|
901
|
+
writeKrispUsage: writeKrispUsage.bind(null, krispUsageClient),
|
|
859
902
|
AlertType: { ...AlertType }
|
|
860
903
|
};
|
|
861
904
|
};
|
package/package.json
CHANGED
package/test/docker_start.js
CHANGED
|
@@ -2,7 +2,7 @@ const test = require('tape');
|
|
|
2
2
|
const exec = require('child_process').exec ;
|
|
3
3
|
|
|
4
4
|
test('starting docker network..', (t) => {
|
|
5
|
-
exec(`docker
|
|
5
|
+
exec(`docker compose -f "${__dirname}/docker-compose-testbed.yaml" up -d`, (err, stdout, stderr) => {
|
|
6
6
|
setTimeout(() => {
|
|
7
7
|
t.pass('docker started');
|
|
8
8
|
t.end(err);
|
package/test/docker_stop.js
CHANGED
|
@@ -3,7 +3,7 @@ const exec = require('child_process').exec ;
|
|
|
3
3
|
|
|
4
4
|
test('stopping docker network..', (t) => {
|
|
5
5
|
t.timeoutAfter(10000);
|
|
6
|
-
exec(`docker
|
|
6
|
+
exec(`docker compose -f "${__dirname}/docker-compose-testbed.yaml" down`, (err, stdout, stderr) => {
|
|
7
7
|
//console.log(`stderr: ${stderr}`);
|
|
8
8
|
process.exit(0);
|
|
9
9
|
});
|
package/test/unit-tests.js
CHANGED
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
writeAlerts,
|
|
16
16
|
queryAlerts,
|
|
17
17
|
queryAlertsSP,
|
|
18
|
+
writeKrispUsage,
|
|
18
19
|
AlertType
|
|
19
20
|
} = require('..')(consoleLogger, '127.0.0.1', {commitSize: 1});
|
|
20
21
|
|
|
@@ -266,4 +267,20 @@ test('write timeseries data', async(t) => {
|
|
|
266
267
|
//console.log(JSON.stringify(result));
|
|
267
268
|
t.ok(result.data.length === 2 && result.data[0].calls_in_progress === 21, 'queried call counts by application_sid');
|
|
268
269
|
|
|
270
|
+
result = await writeKrispUsage({
|
|
271
|
+
service_provider_sid: 'zzzzz',
|
|
272
|
+
account_sid: 'yyyy',
|
|
273
|
+
feature: 'noise_cancellation',
|
|
274
|
+
usage_seconds: 120
|
|
275
|
+
});
|
|
276
|
+
t.pass('wrote krisp usage for noise cancellation');
|
|
277
|
+
|
|
278
|
+
result = await writeKrispUsage({
|
|
279
|
+
service_provider_sid: 'zzzzz',
|
|
280
|
+
account_sid: 'yyyy',
|
|
281
|
+
feature: 'turn_taking',
|
|
282
|
+
usage_seconds: 45
|
|
283
|
+
});
|
|
284
|
+
t.pass('wrote krisp usage for turn taking');
|
|
285
|
+
|
|
269
286
|
});
|