Fully implement the logs and bars switch
This commit is contained in:
@@ -28,7 +28,7 @@ if (options.help) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const metricManager = new MetricManager();
|
||||
const metricManager = new MetricManager(options);
|
||||
|
||||
verifyDefaults(options, centerOptions);
|
||||
verifyExists(options.port, "Port can not be undefined or empty! (--port)", logger);
|
||||
@@ -122,7 +122,7 @@ const server = smpp.createServer(
|
||||
});
|
||||
session.on("submit_sm", async function (pdu) {
|
||||
if (!options.dr) {
|
||||
// sessionLogger.info("Replying to incoming submit_sm");
|
||||
sessionLogger.info("Replying to incoming submit_sm");
|
||||
rxMetrics.AddEvent();
|
||||
// setTimeout(() => {
|
||||
// session.send(pdu.response());
|
||||
@@ -168,7 +168,9 @@ const server = smpp.createServer(
|
||||
};
|
||||
sessionLogger.info(`Generated DR as ${drMessage}`);
|
||||
session.deliver_sm(DRPdu);
|
||||
if (txMetrics) {
|
||||
txMetrics.AddEvent();
|
||||
}
|
||||
});
|
||||
|
||||
session.on("close", function () {
|
||||
|
40
client.js
40
client.js
@@ -7,8 +7,8 @@ const { verifyDefaults, verifyExists } = require("./utils");
|
||||
const { clientOptions } = require("./cliOptions");
|
||||
const { MetricManager } = require("./metrics/metricManager");
|
||||
|
||||
const logger = createBaseLogger();
|
||||
const options = commandLineArgs(clientOptions);
|
||||
const logger = createBaseLogger(options);
|
||||
|
||||
if (options.help) {
|
||||
const usage = commandLineUsage([
|
||||
@@ -40,7 +40,7 @@ let failed = 0;
|
||||
const sendTimer = new NanoTimer();
|
||||
|
||||
function startInterval(session, sessionLogger, metrics) {
|
||||
if (!metrics.progress) {
|
||||
if (!metrics.progress && options.bars === true) {
|
||||
metrics.progress = metricManager.AddMetrics("Send progress", false);
|
||||
metrics.progress.bar.total = options.messagecount;
|
||||
metrics.window = metricManager.AddMetrics("Send window", false);
|
||||
@@ -49,12 +49,14 @@ function startInterval(session, sessionLogger, metrics) {
|
||||
sendTimer.setInterval(
|
||||
async () => {
|
||||
if (sent >= options.messagecount) {
|
||||
// sessionLogger.info(`Finished sending messages success:${success}, failed:${failed}, idling...`);
|
||||
sessionLogger.info(`Finished sending messages success:${success}, failed:${failed}, idling...`);
|
||||
sendTimer.clearInterval();
|
||||
} else if (inFlight < options.window) {
|
||||
// sessionLogger.info(`Sending message ${sent + 1}/${options.messagecount}`);
|
||||
sessionLogger.info(`Sending message ${sent + 1}/${options.messagecount}`);
|
||||
if (options.bars) {
|
||||
metrics.progress.bar.increment();
|
||||
metrics.window.bar.increment();
|
||||
}
|
||||
session.submit_sm(
|
||||
{
|
||||
source_addr: options.source,
|
||||
@@ -62,10 +64,12 @@ function startInterval(session, sessionLogger, metrics) {
|
||||
short_message: options.message,
|
||||
},
|
||||
function (pdu) {
|
||||
if (metrics.window?.bar) {
|
||||
metrics.window.bar.update(metrics.window.bar.value - 1);
|
||||
}
|
||||
inFlight--;
|
||||
if (pdu.command_status === 0) {
|
||||
// sessionLogger.info(`Received response with id ${pdu.message_id}`);
|
||||
sessionLogger.info(`Received response with id ${pdu.message_id}`);
|
||||
success++;
|
||||
} else {
|
||||
sessionLogger.warn(`Message failed with id ${pdu.message_id}`);
|
||||
@@ -73,13 +77,15 @@ function startInterval(session, sessionLogger, metrics) {
|
||||
}
|
||||
}
|
||||
);
|
||||
if (metrics.txMetrics) {
|
||||
metrics.txMetrics.AddEvent();
|
||||
}
|
||||
sent++;
|
||||
inFlight++;
|
||||
} else {
|
||||
// sessionLogger.warn(
|
||||
// `${inFlight}/${options.window} messages pending, waiting for a reply before sending more`
|
||||
// );
|
||||
sessionLogger.warn(
|
||||
`${inFlight}/${options.window} messages pending, waiting for a reply before sending more`
|
||||
);
|
||||
sendTimer.clearInterval();
|
||||
setTimeout(() => startInterval(session, sessionLogger, metrics), options.windowsleep);
|
||||
}
|
||||
@@ -89,10 +95,10 @@ function startInterval(session, sessionLogger, metrics) {
|
||||
);
|
||||
}
|
||||
|
||||
const metricManager = new MetricManager();
|
||||
const metricManager = new MetricManager(options);
|
||||
|
||||
for (let i = 0; i < options.sessions; i++) {
|
||||
const sessionLogger = createSessionLogger(i);
|
||||
const sessionLogger = createSessionLogger(options, i);
|
||||
sessionLogger.info(`Connecting to ${options.host}:${options.port}...`);
|
||||
const session = smpp.connect(
|
||||
{
|
||||
@@ -123,14 +129,18 @@ for (let i = 0; i < options.sessions; i++) {
|
||||
// TODO: Add error message for invalid systemid and password
|
||||
|
||||
session.on("deliver_sm", function (pdu) {
|
||||
if (rxMetrics) {
|
||||
rxMetrics.AddEvent();
|
||||
// sessionLogger.info("Got deliver_sm, replying...");
|
||||
setTimeout(() => {
|
||||
session.send(pdu.response());
|
||||
txMetrics.AddEvent();
|
||||
}, 200);
|
||||
}
|
||||
sessionLogger.info("Got deliver_sm, replying...");
|
||||
// setTimeout(() => {
|
||||
// session.send(pdu.response());
|
||||
// txMetrics.AddEvent();
|
||||
// }, 200);
|
||||
session.send(pdu.response());
|
||||
if (txMetrics) {
|
||||
txMetrics.AddEvent();
|
||||
}
|
||||
});
|
||||
session.on("enquire_link", function (pdu) {
|
||||
session.send(pdu.response());
|
||||
|
@@ -2,7 +2,9 @@ const cliProgress = require("cli-progress");
|
||||
const { Metric } = require("./metrics");
|
||||
|
||||
class MetricManager {
|
||||
constructor() {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
if (options.bars) {
|
||||
this.metricBufferSize = 1000;
|
||||
this.multibar = new cliProgress.MultiBar(
|
||||
{
|
||||
@@ -15,11 +17,14 @@ class MetricManager {
|
||||
);
|
||||
setInterval(() => this.multibar.update(), 100);
|
||||
}
|
||||
}
|
||||
|
||||
AddMetrics(name, refresh = true) {
|
||||
if (this.options.bars) {
|
||||
const metric = new Metric(name, this.multibar, this.metricBufferSize, refresh);
|
||||
return metric;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { MetricManager };
|
||||
|
Reference in New Issue
Block a user