简体   繁体   中英

How can I expose metrics of my NodeJS service using opencensus / prometheus library?

My service is written using NodeJS and I want to create a separate endpoint \\metrics that will return the following metrics:

Average request latency
99th percentile request latencies

Is there a hello world example for either opencensus / prometheus libraries? I didn't manage to find any examples of using it in NodeJS.

For example, when I add the following code from this tutorial , my output is empty even after I execute a couple of requests.

The example you referenced is a good starting point.

For convenience, the example reads text from a file ./test.txt and measure the latency in processLine using:

measure: mLatencyMs,
value: (new Date()) - startTime.getTime()

You want to do much the same except replace the file text processing with your requests and measuring your request latencies.

There are many examples that demonstrate measuring eg HTTP request latencies using Express (here's one ).

So, you should combine the OpenCensus sample with code that measures and records your request latencies and, as long as you configure the Prometheus Exporter (as shown), you should be able to grab these metrics from a /metrics endpoint.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM