Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shoppinpal/metricia
https://github.com/shoppinpal/metricia
Last synced: about 10 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/shoppinpal/metricia
- Owner: ShoppinPal
- License: gpl-3.0
- Created: 2021-09-30T13:57:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-03T17:48:58.000Z (11 months ago)
- Last Synced: 2024-04-14T13:58:32.354Z (7 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 0
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Metricia
> To be used with Express server for metrics reporting
## Motivation
- To abstract away any sdk/service
- Provide a consistent API for metrics reporting
- TODO : update more## Initialization
- define PORT in enviornment variable to change it (default: 9000)
- Import the package in your application entrypoint file (app.js / index.js)
- ```
const { server: expressServerInstance } = metricsSdk.startCollectingMetrics(
, // user-management-service
, // fetch-users-worker
, // boolean - Should the basic nodejs metrics be sent
);
```## Functional Approach
### _Counter:_
- increment
```
metricsSdk.counter.inc(, , , );
```### _Gauge:_
- increment: increment gauge value
```
metricsSdk.gauge.inc(, , , );
```- decrement: decrement gauge value
```
metricsSdk.gauge.dec(, , , );
```- set value : set gauge value
```
metricsSdk.gauge.dec(, , , );
```- createWithCallback: get values when the metrics are scrapped
```
metricsSdk.gauge.createWithCallback('metrics_name', ['label1', 'label2], async (gauge) => {
const values = await getData();
gauge.labels({ label1: value, label2: value }).set(values.value1);
gauge.labels({ label1: value, label2: value }).set(values.value2);
});
```### _Histogram_
```
const histogram = metricsSdk.histogram.getOrCreate(
this.name,
this.labelNames,
this.description,
this.buckets,
prependProjectName,
);
histogram.labels(this.labels).observe(value)
```## Class based approach
### For Counter & Gauge:
```
const { CounterMetric, CalculateTimeMetric } = require('metricsSdk/classes');class YourCustomMetricName extends CounterMetric {
constructor(label1, label2) {
const labels = {
label1,
label2,
};
super('custom_metric_name', 'Metric Description', labels);
}
}new YourCustomMetricName(value1, value2).logMetric(1);
```
### For Histogram
```
class SomeTaskTimeTakenMetric extends CalculateTimeMetric {
constructor(label1, label2) {
const labels = {
label1,
label2,
};
super(
'some_task_time_taken_metric',
'Description',
[0.1, 0.25, 0.5, 0.75, 1, 1.5, 2, 5, 10, 20, 30, 60, 300, 600, 1200, 1800, 3600],
labels,
);
}
}
```#### Histogram logging
Method 1:
```
new SomeTaskTimeTakenMetric(CONFIG.BULL_QUEUE.ORDERS_QUEUE).logMetric(
startDate,
endDate,
);
```Method 2:
```
const someJobTimeMetric = new SomeTaskTimeTakenMetric(
value1,
value2,
);
someJobTimeMetric.startTask();
// Perform task
someJobTimeMetric.endTask();
```