Gathering detailed insights and metrics for logzio-nodejs-metrics-sdk
Gathering detailed insights and metrics for logzio-nodejs-metrics-sdk
Gathering detailed insights and metrics for logzio-nodejs-metrics-sdk
Gathering detailed insights and metrics for logzio-nodejs-metrics-sdk
Records custom Prometheus format metrics in your Node js application and exports them to remote write compatible backends
npm install logzio-nodejs-metrics-sdk
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
84 Commits
3 Forks
4 Watchers
14 Branches
8 Contributors
Updated on Sep 17, 2024
Latest Version
0.5.0
Package Id
logzio-nodejs-metrics-sdk@0.5.0
Unpacked Size
57.78 kB
Size
13.22 kB
File Count
12
NPM Version
8.11.0
Node Version
17.9.1
Published on
Sep 17, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This topic includes instructions on how to send custom metrics to Logz.io from your Node.js application.
The included example uses the OpenTelemetry JS SDK and its based on OpenTelemetry exporter collector proto.
Before you begin, you'll need: Node 14 or higher
Note This project works best with logzio as metrics backend, but its compatible with all backends that support prometheuesrmotewrite
format
Install the package:
npm install logzio-nodejs-metrics-sdk@0.4.0
npm install @opentelemetry/sdk-metrics-base@0.27.0
Set the variables in the following code snippet:
Environment variable | Description |
---|---|
url | The Logz.io Listener URL for for your region, configured to use port 8052 for http traffic, or port 8053 for https traffic. For example - https://listener.logz.io:8053 |
token | Your Logz.io Prometheus Metrics account token. |
1const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics'); 2const sdk = require('logzio-nodejs-metrics-sdk'); 3 4const collectorOptions = { 5 url: '<<url>>', 6 headers: { 7 Authorization: 'Bearer <<token>>', 8 }, 9}; 10// Initialize the exporter 11const metricExporter = new sdk.RemoteWriteExporter(collectorOptions); 12 13// Initialize the meter provider 14const meter = new MeterProvider({ 15 readers: [ 16 new PeriodicExportingMetricReader( 17 { 18 exporter: metricExporter, 19 exportIntervalMillis: 1000 20 }) 21 ], 22}).getMeter('example-exporter'); 23 24// Create your first counter metric 25const requestCounter = meter.createCounter('Counter', { 26 description: 'Example of a Counter', 27}); 28// Define some labels for your metrics 29const labels = { environment: 'prod' }; 30// Record some value 31requestCounter.add(1, labels); 32// In logzio Metrics you will see the following metric: 33// Counter_total{environment: 'prod'} 1.0
For more information, see the OpenTelemetry documentation.
Name | Behavior |
---|---|
Counter | Metric value can only go up or be reset to 0, calculated per counter.Add(context,value,labels) request. |
UpDownCounter | Metric value can arbitrarily increment or decrement, calculated per updowncounter.Add(context,value,labels) request. |
Histogram | Metric values captured by the histogram.Record(context,value,labels) function, calculated per request. |
First Initialize the exporter and meter provider:
1const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics'); 2const sdk = require('logzio-nodejs-metrics-sdk'); 3 4const collectorOptions = { 5 url: '<<url>>', 6 headers: { 7 Authorization: 'Bearer <<token>>', 8 }, 9}; 10// Initialize the exporter 11const metricExporter = new sdk.RemoteWriteExporter(collectorOptions); 12 13// Initialize the meter provider 14const meter = new MeterProvider({ 15 readers: [ 16 new PeriodicExportingMetricReader( 17 { 18 exporter: metricExporter, 19 exportIntervalMillis: 1000 20 }) 21 ], 22}).getMeter('example-exporter');
Then create different types of metrics
1// Create UpDownCounter metric 2const upDownCounter = meter.createUpDownCounter('UpDownCounter', { 3 description: 'Example of a UpDownCounter', 4}); 5// Define some labels for your metrics 6const labels = { environment: 'prod' }; 7// Record some values 8upDownCounter.add(5, labels); 9upDownCounter.add(-1, labels); 10// In logzio you will see the following metric: 11// UpDownCounter{environment: 'prod'} 4.0
1// Create ValueRecorder metric 2const histogram = meter.createHistogram('test_histogram', { 3 description: 'Example of a histogram', 4}); 5// Define some labels for your metrics 6const labels = { environment: 'prod' }; 7// Record some values 8histogram.record(30, labels); 9histogram.record(20), labels; 10// In logzio you will see the following metrics: 11// test_histogram_sum{environment: 'prod'} 50.0 12// test_histogram_count{environment: 'prod'} 2.0 13// test_histogram_avg{environment: 'prod'} 25.0
0.5.0
Breaking changes:
1.26.0
12.*
0.4.0
Breaking changes:
8.*
10.*
Changelog:
axios
instead of requestretry
(@chapost1)0.3.0
0.2.0
0.1.0
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 4/8 approved changesets -- score normalized to 5
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More