You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi i have server like this:
`const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 3000;
var timeOfProcessing =0;
var time_of_processing_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_of_processing", {
description: "sum of all messages processing time",
//monotonic: true,
labelKeys: ["time_of_processing"],
});
time_of_processing_observable_gauge.addCallback(()=> timeOfProcessing)
var processed = 0;
var counterOfProcessed = meterProvider.getMeter('prometheus').createCounter("counter_of_processed", {
description: "all processed messages",
monotonic: true,
labelKeys: ["counter_of_processed"],
});
//counterOfProcessed_observable_gauge.addCallback(()=> processed)
var timeBetweenReceiveAndSend;
var time_between_receive_and_send_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_between_receive_and_send", {
description: "sum of all messages receive plus send time",
monotonic: true,
labelKeys: ["time_between_receive_and_send"],
});
time_between_receive_and_send_observable_gauge.addCallback(()=> timeBetweenReceiveAndSend);
let timeOfTransport;
var time_of_transport_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_of_transport", {
description: "sum of all messages transport (from client to server) time",
monotonic: true,
labelKeys: ["time_of_transport"],
});
time_of_transport_observable_gauge.addCallback(()=>timeOfTransport);
const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics' })
hostMetrics.start();
var currentTime = Date.now();
var splitted = msg.split("//");
var time = splitted[1];
var message = splitted[0];
var timeOfTransportLocal = currentTime - time;
counterOfProcessed.add(1);
//this.processed+=1;
timeOfTransport+=timeOfTransportLocal;
//method1();
var timeStart = Date.now();
io.emit('chat message', msg);//Object.keys(io.eio.clients));
var timeEnd = Date.now();
timeOfProcessing+=timeEnd-timeStart;
});
});
http.listen(port, () => {
console.log(Socket.IO server running at http://localhost:${port}/);
});
}
catch(e){
counter.add(1);
throw e;
}`
Inside socket.on I adding to counterOfProcess and it works - i see `# HELP counter_of_processed_total all processed messages
TYPE counter_of_processed_total counter
counter_of_processed_total 1` in prometheus
But if it comes to updating value timeOfProcessing+=timeEnd-timeStart it doesn't work. I see on debug that value is set (in callback also!) but in prometheus i see:
`# HELP time_of_processing sum of all messages processing time
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi i have server like this:
`const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 3000;
//instrumentation
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node');
//prometheus exporter
const opentelemetry = require('@opentelemetry/sdk-node');
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { Resource } = require('@opentelemetry/resources');
const { metrics } = require('@opentelemetry/api');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { HostMetrics } = require('@opentelemetry/host-metrics');
//const memoryData = process.memoryUsage();
//const cpuData = process.cpuUsage();
//const data = process.resourceUsage
const exporter = new PrometheusExporter(
{
startServer: true,
port : 56326
}, () => {
console.log('prometheus scrape endpoint: http://localhost:56326/metrics')
}
)
const meterProvider = new MeterProvider()
meterProvider.addMetricReader(exporter)
var counter = meterProvider.getMeter('prometheus').createCounter("failed_requests_metric", {
description: "Indicates failed requests",
monotonic: true,
labelKeys: ["failed_requests_metric"],
});
var timeOfProcessing =0;
var time_of_processing_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_of_processing", {
description: "sum of all messages processing time",
//monotonic: true,
labelKeys: ["time_of_processing"],
});
time_of_processing_observable_gauge.addCallback(()=> timeOfProcessing)
var processed = 0;
var counterOfProcessed = meterProvider.getMeter('prometheus').createCounter("counter_of_processed", {
description: "all processed messages",
monotonic: true,
labelKeys: ["counter_of_processed"],
});
//counterOfProcessed_observable_gauge.addCallback(()=> processed)
var timeBetweenReceiveAndSend;
var time_between_receive_and_send_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_between_receive_and_send", {
description: "sum of all messages receive plus send time",
monotonic: true,
labelKeys: ["time_between_receive_and_send"],
});
time_between_receive_and_send_observable_gauge.addCallback(()=> timeBetweenReceiveAndSend);
let timeOfTransport;
var time_of_transport_observable_gauge = meterProvider.getMeter('prometheus').createObservableGauge("time_of_transport", {
description: "sum of all messages transport (from client to server) time",
monotonic: true,
labelKeys: ["time_of_transport"],
});
time_of_transport_observable_gauge.addCallback(()=>timeOfTransport);
const hostMetrics = new HostMetrics({ meterProvider, name: 'example-host-metrics' })
hostMetrics.start();
function method1()
{
processed+=1;
}
try{
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
socket.on('chat message', msg => {
});
});
http.listen(port, () => {
console.log(
Socket.IO server running at http://localhost:${port}/
);});
}
catch(e){
counter.add(1);
throw e;
}`
Inside socket.on I adding to counterOfProcess and it works - i see `# HELP counter_of_processed_total all processed messages
TYPE counter_of_processed_total counter
counter_of_processed_total 1` in prometheus
But if it comes to updating value
timeOfProcessing+=timeEnd-timeStart
it doesn't work. I see on debug that value is set (in callback also!) but in prometheus i see:`# HELP time_of_processing sum of all messages processing time
TYPE time_of_processing gauge`
It's quie weird. Please for help
Beta Was this translation helpful? Give feedback.
All reactions