Minor changes and fixes
This commit is contained in:
5
main.js
5
main.js
@@ -31,6 +31,7 @@ const MESSAGE_SEND_UPDATE_DELAY = process.env.MESSAGE_SEND_UPDATE_DELAY || 500;
|
||||
// }
|
||||
// });
|
||||
// TODO: Implement some sort of metrics on frontend by counting the pdus
|
||||
// TODO: Currently clients don't realize they've been disconnected by time out
|
||||
|
||||
[
|
||||
'debug',
|
||||
@@ -188,7 +189,7 @@ class ClientSession {
|
||||
refresh() {
|
||||
this.logger.log1(`Refreshing client with url ${this.url} and id ${this.id}`);
|
||||
let status = this.status;
|
||||
this.close().catch(err => this.logger.log1(err));
|
||||
this.close().catch(err => err);
|
||||
if (status === ClientSessionStatus.CONNECTED) {
|
||||
this.connect().catch(err => this.logger.log1(err));
|
||||
}
|
||||
@@ -1677,7 +1678,7 @@ centerSessionManager.startup();
|
||||
// let session = clientSessionManager.createSession('smpp://localhost:7001', 'test', 'test');
|
||||
// let server = centerSessionManager.createSession(7001, 'test', 'test');
|
||||
|
||||
let session = clientSessionManager.getSession(0);
|
||||
let session = clientSessionManager.getSession(1);
|
||||
let server = centerSessionManager.getSession(1);
|
||||
|
||||
session.connect()
|
||||
|
@@ -2,19 +2,58 @@ const WebSocket = require('ws');
|
||||
|
||||
const WS_SERVER_PORT = process.env.WS_SERVER_PORT || 8191;
|
||||
|
||||
class Metrics {
|
||||
static interestingMetrics = ['submit_sm', 'deliver_sm'];
|
||||
metrics = {};
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
processPdu(pdu) {
|
||||
if (Metrics.interestingMetrics.indexOf(pdu.command) !== -1) {
|
||||
let timestamp = Math.floor(new Date().getTime() / 1000);
|
||||
|
||||
if (!!!this.metrics[timestamp]) {
|
||||
this.metrics[timestamp] = {};
|
||||
}
|
||||
if (!!!this.metrics[timestamp][pdu.command]) {
|
||||
this.metrics[timestamp][pdu.command] = 0;
|
||||
}
|
||||
|
||||
this.metrics[timestamp][pdu.command] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let clientMetrics = new Metrics();
|
||||
let centerMetrics = new Metrics();
|
||||
|
||||
const ws = new WebSocket(`ws://localhost:${WS_SERVER_PORT}`);
|
||||
const ws2 = new WebSocket(`ws://localhost:${WS_SERVER_PORT}`);
|
||||
ws.on('open', () => {
|
||||
console.log('WebSocket connection established');
|
||||
ws.send("client:1");
|
||||
ws.send("client:0");
|
||||
});
|
||||
ws.on('message', (data) => {
|
||||
console.log(String(data));
|
||||
data = JSON.parse(data);
|
||||
if (data.type === 'pdu') {
|
||||
clientMetrics.processPdu(data.value);
|
||||
}
|
||||
});
|
||||
|
||||
const ws2 = new WebSocket(`ws://localhost:${WS_SERVER_PORT}`);
|
||||
ws2.on('open', () => {
|
||||
console.log('WebSocket connection established');
|
||||
ws.send("center:1");
|
||||
ws2.send("center:0");
|
||||
});
|
||||
ws2.on('message', (data) => {
|
||||
console.log(String(data));
|
||||
});
|
||||
data = JSON.parse(data);
|
||||
if (data.type === 'pdu') {
|
||||
centerMetrics.processPdu(data.value);
|
||||
}
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
console.log(clientMetrics.metrics);
|
||||
console.log(centerMetrics.metrics);
|
||||
console.log("");
|
||||
}, 500);
|
Reference in New Issue
Block a user