# @pager/metrics-client

> Hapi Prometheus Plugin and optional endpoint

Latest version **6.0.0** (published 2023-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pager/metrics-client
pnpm add @pager/metrics-client
yarn add @pager/metrics-client
bun add @pager/metrics-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2023-01-03 |
| First published | 2018-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 3 |
| Unpacked size | 19.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | engineering@pager.com |
| Maintainers | melinamejia95, kyleherrmann, jonmiller035, durenh, juanpahdz, luciabrumnich.pager, chrisft25, juandara22, m4shu, juancabuhe, joan.semander, mariano-ramonda, fauricio-pager, divyasehgal, fredgonzalez, pinkphi, mark.ferris, dmsq22, exequiel-sanoner, juan.lacoste.pager, hsoberon, jiggyjigsj, dawinvalenz, ijuani, matthewhudson, luis.garcia.pager, jsanmi, fabian.celdeiro, aftab-alam-khan, markguyver-at-pager, peter-vizi-pager, ramanvas, epsanchezma, jonathanhuertas, jenkins-pager, circle-pager, sa-pagerinc-automation, lgenzelis, fcue, roybay04, shankyjs, ryshah1207, gh0stl1m-p, ilmancino, blaine-pager, jmelero.pager |

## Links

- npm: https://www.npmjs.com/package/@pager/metrics-client
- Repository: https://github.com/pagerinc/metrics-client
- Homepage: https://github.com/pagerinc/metrics-client#readme
- Issues: https://github.com/pagerinc/metrics-client/issues
- npm.io page: https://npm.io/package/@pager/metrics-client

## Dependencies (3)

- [joi](https://npm.io/package/joi.md) ^17.3.0
- [@hapi/hoek](https://npm.io/package/@hapi/hoek.md) ^9.1.0
- [prom-client](https://npm.io/package/prom-client.md) 12.x

## Recent versions

- 6.0.0 (latest) — 2023-01-03
- 5.0.1 — 2020-11-06
- 5.0.0 — 2020-08-19
- 4.3.1 — 2020-02-12
- 4.3.0 — 2019-07-31
- 4.2.1 — 2019-06-05
- 4.2.0 — 2019-06-05
- 4.1.0 — 2019-05-13
- 4.0.0 — 2019-03-28
- 3.0.0 — 2018-11-13
- 2.0.0 — 2018-08-16
- 1.1.2 — 2018-07-19
- 1.1.1 — 2018-07-19
- 1.1.0 — 2018-07-19
- 1.0.2 — 2018-03-21
- … 1 more at https://npm.io/package/@pager/metrics-client/versions

## README

# metrics-client
Hapi-centric Prometheus Plugin and optional endpoint

Use this plugin to:
- Add an endpoint for metrics (defaults to `/metrics`)
- Add custom metrics in routes (server binds `.metrics` in request contexts)
- Run a server for worker that reports metrics from an endpoint (defaults to `/metrics` on port `3000`)

## Integration 

### Modules

Once metric-client is a Hapi-centric Prometheus Plugin. Hapi and metrics-client modules need to be installed.

```bash
npm install -S @hapi/hapi
npm install -S @pager/metrics-client
```
### Usage 

Sample usage for metrics-client server 

```js
'use strict';

const Hapi = require('@hapi/hapi');
const Metrics = require('@pager/metrics-client');

const startServer = async () => {

    const server = await new Hapi.Server({
        port: 3000
    });
    await server.register([
        {
            plugin: Metrics
        }
    ]);
    await server.start();
    console.log( `Server started at ${ server.info.uri }`);
    return server;
};

module.exports = startServer();
```

### Annotations

```yaml
annotations:
  prometheus.io/scrape: "true"
  prometheus.io/port: {{ .Values.service.internalPort | quote }}
```

### Readiness and Liveness

Readiness probes are designed to let Kubernetes know when your app is ready to serve traffic. Similarly, liveness probes let Kubernetes know if your app is alive or dead. Metric-client plugin is also support health check and needs to be added to the deployment file under container details. 

```yaml
livenessProbe:
  httpGet:
    path: /health
    port: {{ .Values.service.internalPort }} 
  initialDelaySeconds: 15
  timeoutSeconds: 1
readinessProbe:
  httpGet:
    path: /health
    port: {{ .Values.service.internalPort }}
  initialDelaySeconds: 15
  timeoutSeconds: 1
```

### Internal Ports 

Prometheus server Kubernetes service discovery configuration is going to search running server on kubernetes cluster. It will use  default server port `3000`. Thus, metrics-client must start at default port `3000`. If the server is not already running on port `3000`, it should be added on containers details.  

```yaml
env:
  - name: PORT
  value: "3000"
```

## References

### Health vs Metrics endpoint

Health endpoint is designed to provide information about a readiness and liveness of the server. On the other hand, metrics endpoint provides information about the performance of the server such as load time, response time, memory usage, CPU usage etc. 


| Metrics List|
|---|
|cpu_user_time|
|cpu_user_utilization|
|cpu_system_time|
|cpu_system_utilization|
|event_loop_usage|
|event_loop_wait|
|memory_physical|
|memory_heap_used|
|memory_heap_free|
|memory_heap_max|
|memory_nonheap_used|
|http_request_duration_milliseconds|
|http_request_buckets_milliseconds|
|gc_pause_time_min|
|gc_pause_time_max|
|gc_pause_time_total|
|gc_scavenge_min|
|gc_scavenge_max|
|gc_scavenge_total|
|gc_marksweepcompact_min|
|gc_marksweepcompact_max|
|gc_marksweepcompact_total|
|gc_incrementalmarking_min|
|gc_incrementalmarking_max|
|gc_incrementalmarking_total|

---
_Source: https://npm.io/package/@pager/metrics-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
