@jambonz/time-series 0.2.10 → 0.2.11
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 +40 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -89,6 +89,17 @@ const schemas = {
|
|
|
89
89
|
'account_sid',
|
|
90
90
|
'application_sid'
|
|
91
91
|
]
|
|
92
|
+
},
|
|
93
|
+
system_alerts: {
|
|
94
|
+
measurement: 'system_alerts',
|
|
95
|
+
fields: {
|
|
96
|
+
detail: Influx.FieldType.STRING,
|
|
97
|
+
host: Influx.FieldType.STRING
|
|
98
|
+
},
|
|
99
|
+
tags: [
|
|
100
|
+
'system_component',
|
|
101
|
+
'state'
|
|
102
|
+
]
|
|
92
103
|
}
|
|
93
104
|
};
|
|
94
105
|
|
|
@@ -495,6 +506,25 @@ const writeCdrs = async(client, cdrs) => {
|
|
|
495
506
|
return;
|
|
496
507
|
};
|
|
497
508
|
|
|
509
|
+
const writeSystemAlerts = async(client, systemAlerts) => {
|
|
510
|
+
if (!client.locals.initialized) await initDatabase(client, 'system_alerts');
|
|
511
|
+
systemAlerts = (Array.isArray(systemAlerts) ? systemAlerts : [systemAlerts])
|
|
512
|
+
.map((systemAlert) => {
|
|
513
|
+
const {system_component, state, fields} = systemAlert;
|
|
514
|
+
return {
|
|
515
|
+
measurement: 'system_alerts',
|
|
516
|
+
timestamp: new Date(),
|
|
517
|
+
fields,
|
|
518
|
+
tags: {
|
|
519
|
+
system_component,
|
|
520
|
+
state
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
});
|
|
524
|
+
client.locals.data = [...client.locals.data, ...systemAlerts];
|
|
525
|
+
await writeData(client);
|
|
526
|
+
return;
|
|
527
|
+
};
|
|
498
528
|
const queryCdrsSP = async(client, opts) => {
|
|
499
529
|
if (!client.locals.initialized) await initDatabase(client, 'cdrs');
|
|
500
530
|
const response = {
|
|
@@ -741,6 +771,7 @@ module.exports = (logger, opts) => {
|
|
|
741
771
|
const callCountSPClient = new Influx.InfluxDB({database: 'sp_call_counts', schemas: schemas.sp_call_counts, ...opts});
|
|
742
772
|
// eslint-disable-next-line max-len
|
|
743
773
|
const callCountAppClient = new Influx.InfluxDB({database: 'app_call_counts', schemas: schemas.app_call_counts, ...opts});
|
|
774
|
+
const systemAlertClient = new Influx.InfluxDB({database: 'system_alerts', schemas: schemas.system_alerts, ...opts});
|
|
744
775
|
|
|
745
776
|
cdrClient.locals = {
|
|
746
777
|
db: 'cdrs',
|
|
@@ -782,6 +813,14 @@ module.exports = (logger, opts) => {
|
|
|
782
813
|
commitInterval: opts.commitInterval || 10,
|
|
783
814
|
data: []
|
|
784
815
|
};
|
|
816
|
+
systemAlertClient.locals = {
|
|
817
|
+
db: 'system_alerts',
|
|
818
|
+
initialized: false,
|
|
819
|
+
writing: false,
|
|
820
|
+
commitSize: opts.commitSize || 1,
|
|
821
|
+
commitInterval: opts.commitInterval || 10,
|
|
822
|
+
data: []
|
|
823
|
+
};
|
|
785
824
|
|
|
786
825
|
if (opts.commitSize > 1 && opts.commitInterval && opts.commitInterval > 2) {
|
|
787
826
|
setInterval(writeData.bind(null, callCountClient), opts.commitInterval * 1000);
|
|
@@ -804,6 +843,7 @@ module.exports = (logger, opts) => {
|
|
|
804
843
|
writeAlerts: writeAlerts.bind(null, alertClient),
|
|
805
844
|
queryAlerts: queryAlerts.bind(null, alertClient),
|
|
806
845
|
queryAlertsSP: queryAlertsSP.bind(null, alertClient),
|
|
846
|
+
writeSystemAlerts: writeSystemAlerts.bind(null, systemAlertClient),
|
|
807
847
|
AlertType: { ...AlertType }
|
|
808
848
|
};
|
|
809
849
|
};
|