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