@nexload-sdk/healthcheck-prometheus 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -2
- package/dist/index.cjs +61 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +61 -1
- package/dist/index.mjs.map +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,9 +1,134 @@
|
|
|
1
1
|
# @nexload-sdk/healthcheck-prometheus
|
|
2
2
|
|
|
3
|
-
Prometheus
|
|
3
|
+
**Zero-dependency Prometheus and OpenMetrics text serializers for `@nexload-sdk/healthcheck` reports.**
|
|
4
|
+
|
|
5
|
+
[Documentation](https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/) · [API reference](https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/api/)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@nexload-sdk/healthcheck-prometheus)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
> [!IMPORTANT]
|
|
13
|
+
> A new major release is pending across the healthcheck family in `.changeset/healthcheck-major.md` (import ordering updates, no runtime behavior changes).
|
|
14
|
+
|
|
15
|
+
## Table of contents
|
|
16
|
+
|
|
17
|
+
- [Overview](#overview)
|
|
18
|
+
- [Philosophy](#philosophy)
|
|
19
|
+
- [Install](#install)
|
|
20
|
+
- [Quick start](#quick-start)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [API](#api)
|
|
23
|
+
- [Configuration](#configuration)
|
|
24
|
+
- [Runtime and compatibility](#runtime-and-compatibility)
|
|
25
|
+
- [Caveats](#caveats)
|
|
26
|
+
- [Related packages](#related-packages)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
`@nexload-sdk/healthcheck-prometheus` serializes a `HealthReport` into Prometheus exposition text (`toPrometheusText`) or OpenMetrics text (`toOpenMetricsText`). It solves exposing `/metrics` endpoints for Prometheus scrapers without requiring `prom-client` or global metric registries. It is for services running `@nexload-sdk/healthcheck` in Node.js, Bun, Next.js, or Edge runtimes.
|
|
32
|
+
|
|
33
|
+
What it is not:
|
|
34
|
+
|
|
35
|
+
- Not a `prom-client` wrapper or stateful metric registry.
|
|
36
|
+
- Not an HTTP server (pair with `@nexload-sdk/healthcheck-next` `createNextMetricsRoute` or your own framework route).
|
|
37
|
+
|
|
38
|
+
## Philosophy
|
|
39
|
+
|
|
40
|
+
- **Zero external dependencies:** Pure string serialization with no `prom-client` dependency.
|
|
41
|
+
- **Low-cardinality label allowlist:** Only safe, bounded labels (`service`, `scope`, `check`, `component`, `dependency`, `runtime`, `status`, `error_code`, `collector`, `version`) are emitted; unknown labels are dropped.
|
|
42
|
+
- **Collectors over check-local metrics:** Monitoring series come from `report.metrics` (collectors) plus aggregate/per-check status and duration, keeping check-local diagnostic payloads out of time-series storage.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-prometheus
|
|
48
|
+
# or
|
|
49
|
+
npm install @nexload-sdk/healthcheck @nexload-sdk/healthcheck-prometheus
|
|
50
|
+
# or
|
|
51
|
+
yarn add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-prometheus
|
|
52
|
+
# or
|
|
53
|
+
bun add @nexload-sdk/healthcheck @nexload-sdk/healthcheck-prometheus
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| Package | Range | Required / Optional |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| *(none)* | — | No peer dependencies (`@nexload-sdk/healthcheck` is a direct dependency) |
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
4
61
|
|
|
5
62
|
```ts
|
|
6
63
|
import { toPrometheusText } from "@nexload-sdk/healthcheck-prometheus";
|
|
7
64
|
|
|
8
|
-
const text = toPrometheusText(report, {
|
|
65
|
+
const text = toPrometheusText(report, {
|
|
66
|
+
prefix: "nexload",
|
|
67
|
+
includeDescriptions: true,
|
|
68
|
+
});
|
|
9
69
|
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### OpenMetrics format
|
|
74
|
+
|
|
75
|
+
`toOpenMetricsText` appends the required `# EOF\n` terminator for `application/openmetrics-text; version=1.0.0; charset=utf-8` responses:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { toOpenMetricsText } from "@nexload-sdk/healthcheck-prometheus";
|
|
79
|
+
|
|
80
|
+
const body = toOpenMetricsText(report, {
|
|
81
|
+
prefix: "shop_api",
|
|
82
|
+
defaultLabels: { version: "1.2.0" },
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Emitted series
|
|
87
|
+
|
|
88
|
+
- `<prefix>_health_status{scope,service,status}` (`1` for active status, `0` otherwise across `ok`, `degraded`, `unhealthy`)
|
|
89
|
+
- `<prefix>_health_check_status{check,component,scope,service,status}`
|
|
90
|
+
- `<prefix>_health_check_duration_milliseconds{check,component,scope,service}`
|
|
91
|
+
- `<prefix>_health_run_duration_milliseconds{scope,service}`
|
|
92
|
+
- `<prefix>_<collector_metric_name>{...}` for every metric in `report.metrics`
|
|
93
|
+
|
|
94
|
+
## API
|
|
95
|
+
|
|
96
|
+
### Root entry (`@nexload-sdk/healthcheck-prometheus`)
|
|
97
|
+
|
|
98
|
+
| Export | Kind | Summary |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `toPrometheusText` | `function` | Serializes `HealthReport` to Prometheus text format (`0.0.4`) |
|
|
101
|
+
| `toOpenMetricsText` | `function` | Serializes `HealthReport` to OpenMetrics text format (`1.0.0`, ending with `# EOF`) |
|
|
102
|
+
| `PrometheusExportOptions` | `interface` | `{ prefix?, defaultLabels?, includeDescriptions? }` |
|
|
103
|
+
| `OpenMetricsExportOptions` | `type` | Alias of `PrometheusExportOptions` |
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
| Option | Type | Default | Description |
|
|
108
|
+
| --- | --- | --- | --- |
|
|
109
|
+
| `prefix` | `string` | `"nexload"` | Metric name prefix |
|
|
110
|
+
| `defaultLabels` | `Record<string, string>` | `{}` | Default labels merged into emitted series (filtered by allowlist) |
|
|
111
|
+
| `includeDescriptions` | `boolean` | `false` | Emits `# HELP` lines for built-in and collector metrics |
|
|
112
|
+
|
|
113
|
+
## Runtime and compatibility
|
|
114
|
+
|
|
115
|
+
- **Module format:** Dual ESM (`import`) and CJS (`require`).
|
|
116
|
+
- **Runtimes:** Pure TypeScript; runs in Node.js, Bun, Edge, and browsers.
|
|
117
|
+
|
|
118
|
+
## Caveats
|
|
119
|
+
|
|
120
|
+
> [!WARNING]
|
|
121
|
+
> Unsupported or high-cardinality labels (including in `defaultLabels` or collector `metric.labels`) are silently dropped by the allowlist (`service`, `scope`, `check`, `component`, `dependency`, `runtime`, `status`, `error_code`, `collector`, `version`).
|
|
122
|
+
|
|
123
|
+
> [!NOTE]
|
|
124
|
+
> Metrics embedded inside individual `check.metrics` objects are not exported as Prometheus series; use a `MetricCollectorDefinition` (`report.metrics`) for Prometheus metrics.
|
|
125
|
+
|
|
126
|
+
## Related packages
|
|
127
|
+
|
|
128
|
+
- [healthcheck](../core/README.md) — Core `HealthManager` and `MetricCollectorDefinition`
|
|
129
|
+
- [healthcheck-next](../next/README.md) — Next.js App Router `createNextMetricsRoute`
|
|
130
|
+
- [healthcheck-otel](../otel/README.md) — OpenTelemetry metric record transforms
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @nexload-sdk/healthcheck-prometheus
|
|
1
|
+
// @nexload-sdk/healthcheck-prometheus v3.0.0 (build 2026-11-25T11:31:39.607Z)
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -86,6 +86,59 @@ function appendMetric(lines, name, labelsInput, value) {
|
|
|
86
86
|
if (numeric === null) return;
|
|
87
87
|
lines.push(`${name}${labels(labelsInput)} ${numeric}`);
|
|
88
88
|
}
|
|
89
|
+
function appendDescriptions(lines, report, prefix) {
|
|
90
|
+
const descriptions = /* @__PURE__ */ new Map([
|
|
91
|
+
[
|
|
92
|
+
metricName(
|
|
93
|
+
"health.status",
|
|
94
|
+
prefix
|
|
95
|
+
),
|
|
96
|
+
"Current aggregate health status."
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
metricName(
|
|
100
|
+
"health.check.status",
|
|
101
|
+
prefix
|
|
102
|
+
),
|
|
103
|
+
"Current status of a registered health check."
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
metricName(
|
|
107
|
+
"health.check.duration_milliseconds",
|
|
108
|
+
prefix
|
|
109
|
+
),
|
|
110
|
+
"Duration of a registered health check in milliseconds."
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
metricName(
|
|
114
|
+
"health.run.duration_milliseconds",
|
|
115
|
+
prefix
|
|
116
|
+
),
|
|
117
|
+
"Duration of the health report run in milliseconds."
|
|
118
|
+
]
|
|
119
|
+
]);
|
|
120
|
+
for (const metric of report.metrics) {
|
|
121
|
+
if (metric.description) {
|
|
122
|
+
descriptions.set(
|
|
123
|
+
metricName(
|
|
124
|
+
metric.name,
|
|
125
|
+
prefix
|
|
126
|
+
),
|
|
127
|
+
metric.description
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const [
|
|
132
|
+
name,
|
|
133
|
+
description
|
|
134
|
+
] of descriptions) {
|
|
135
|
+
const sanitizedDescription = description.replace(
|
|
136
|
+
/\s+/g,
|
|
137
|
+
" "
|
|
138
|
+
).trim();
|
|
139
|
+
lines.push(`# HELP ${name} ${sanitizedDescription}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
89
142
|
function appendHealthStatus(lines, report, prefix, defaults) {
|
|
90
143
|
const name = metricName(
|
|
91
144
|
"health.status",
|
|
@@ -189,6 +242,13 @@ function toPrometheusText(report, options = {}) {
|
|
|
189
242
|
const prefix = options.prefix ?? "nexload";
|
|
190
243
|
const defaults = options.defaultLabels ?? {};
|
|
191
244
|
const lines = [];
|
|
245
|
+
if (options.includeDescriptions) {
|
|
246
|
+
appendDescriptions(
|
|
247
|
+
lines,
|
|
248
|
+
report,
|
|
249
|
+
prefix
|
|
250
|
+
);
|
|
251
|
+
}
|
|
192
252
|
appendHealthStatus(
|
|
193
253
|
lines,
|
|
194
254
|
report,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HealthMetric,\n HealthMetricValue,\n HealthReport,\n HealthStatus\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface PrometheusExportOptions {\n prefix?: string\n defaultLabels?: Record<string, string>\n includeDescriptions?: boolean\n}\n\nexport type OpenMetricsExportOptions = PrometheusExportOptions;\n\nconst STATUSES: readonly HealthStatus[] = [\n \"ok\",\n \"degraded\",\n \"unhealthy\"\n];\nconst ALLOWED_LABELS = new Set([\n \"service\",\n \"scope\",\n \"check\",\n \"component\",\n \"dependency\",\n \"runtime\",\n \"status\",\n \"error_code\",\n \"collector\",\n \"version\"\n]);\n\nfunction metricName (\n name: string, prefix: string\n): string {\n const normalized = name.replace(\n /[^a-zA-Z0-9_:]/g, \"_\"\n ).replace(\n /_+/g, \"_\"\n )\n .replace(\n /^_+|_+$/g, \"\"\n )\n .toLowerCase();\n return `${prefix}_${normalized}`;\n}\n\nfunction metricValue (value: HealthMetricValue): number | null {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"boolean\") return value ? 1 : 0;\n if (typeof value === \"string\") return 1;\n return null;\n}\n\nfunction escapeLabel (value: string): string {\n return value.replace(\n /\\\\/g, \"\\\\\\\\\"\n ).replace(\n /\\n/g, \"\\\\n\"\n )\n .replace(\n /\"/g, \"\\\\\\\"\"\n );\n}\n\nfunction labels (input: Record<string, string | undefined>): string {\n const entries = Object.entries(input)\n .filter((entry): entry is [string, string] => Boolean(entry[1]) && ALLOWED_LABELS.has(entry[0]))\n .sort((\n [a], [b]\n ) => a.localeCompare(b));\n\n if (entries.length === 0) return \"\";\n\n return `{${entries.map(([\n key,\n value\n ]) => `${key}=\"${escapeLabel(value)}\"`).join(\",\")}}`;\n}\n\nfunction appendMetric (\n lines: string[], name: string, labelsInput: Record<string, string | undefined>, value: HealthMetricValue\n): void {\n const numeric = metricValue(value);\n if (numeric === null) return;\n\n lines.push(`${name}${labels(labelsInput)} ${numeric}`);\n}\n\nfunction appendHealthStatus (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const name = metricName(\n \"health.status\", prefix\n );\n\n for (const status of STATUSES) {\n appendMetric(\n lines, name, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n status,\n }, report.status === status ? 1 : 0\n );\n }\n}\n\nfunction appendCheckMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const statusName = metricName(\n \"health.check.status\", prefix\n );\n const durationName = metricName(\n \"health.check.duration_milliseconds\", prefix\n );\n\n for (const check of report.checks) {\n for (const status of STATUSES) {\n appendMetric(\n lines, statusName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n status,\n }, check.status === status ? 1 : 0\n );\n }\n\n appendMetric(\n lines, durationName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n }, check.durationMs\n );\n }\n}\n\nfunction appendReportMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const runDurationName = metricName(\n \"health.run.duration_milliseconds\", prefix\n );\n appendMetric(\n lines, runDurationName, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n }, report.durationMs\n );\n\n for (const metric of report.metrics) {\n appendHealthMetric(\n lines, metric, report, prefix, defaults\n );\n }\n}\n\nfunction appendHealthMetric (\n lines: string[], metric: HealthMetric, report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n appendMetric(\n lines, metricName(\n metric.name, prefix\n ), {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n ...metric.labels,\n }, metric.value\n );\n}\n\nexport function toPrometheusText (\n report: HealthReport, options: PrometheusExportOptions = {}\n): string {\n const prefix = options.prefix ?? \"nexload\";\n const defaults = options.defaultLabels ?? {};\n const lines: string[] = [];\n\n appendHealthStatus(\n lines, report, prefix, defaults\n );\n appendCheckMetrics(\n lines, report, prefix, defaults\n );\n appendReportMetrics(\n lines, report, prefix, defaults\n );\n\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nexport function toOpenMetricsText (\n report: HealthReport, options: OpenMetricsExportOptions = {}\n): string {\n return `${toPrometheusText(\n report, options\n )}# EOF\\n`;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,WAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,WACP,MAAc,QACN;AACR,QAAM,aAAa,KAAK;AAAA,IACtB;AAAA,IAAmB;AAAA,EACrB,EAAE;AAAA,IACA;AAAA,IAAO;AAAA,EACT,EACG;AAAA,IACC;AAAA,IAAY;AAAA,EACd,EACC,YAAY;
|
|
4
|
+
"sourcesContent": ["import type {\n HealthMetric,\n HealthMetricValue,\n HealthReport,\n HealthStatus\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface PrometheusExportOptions {\n prefix?: string\n defaultLabels?: Record<string, string>\n includeDescriptions?: boolean\n}\n\nexport type OpenMetricsExportOptions = PrometheusExportOptions;\n\nconst STATUSES: readonly HealthStatus[] = [\n \"ok\",\n \"degraded\",\n \"unhealthy\"\n];\nconst ALLOWED_LABELS = new Set([\n \"service\",\n \"scope\",\n \"check\",\n \"component\",\n \"dependency\",\n \"runtime\",\n \"status\",\n \"error_code\",\n \"collector\",\n \"version\"\n]);\n\nfunction metricName (\n name: string, prefix: string\n): string {\n const normalized = name.replace(\n /[^a-zA-Z0-9_:]/g, \"_\"\n ).replace(\n /_+/g, \"_\"\n )\n .replace(\n /^_+|_+$/g, \"\"\n )\n .toLowerCase();\n\n return `${prefix}_${normalized}`;\n}\n\nfunction metricValue (value: HealthMetricValue): number | null {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"boolean\") return value ? 1 : 0;\n if (typeof value === \"string\") return 1;\n\n return null;\n}\n\nfunction escapeLabel (value: string): string {\n return value.replace(\n /\\\\/g, \"\\\\\\\\\"\n ).replace(\n /\\n/g, \"\\\\n\"\n )\n .replace(\n /\"/g, \"\\\\\\\"\"\n );\n}\n\nfunction labels (input: Record<string, string | undefined>): string {\n const entries = Object.entries(input)\n .filter((entry): entry is [string, string] => Boolean(entry[1]) && ALLOWED_LABELS.has(entry[0]))\n .sort((\n [a], [b]\n ) => a.localeCompare(b));\n\n if (entries.length === 0) return \"\";\n\n return `{${entries.map(([\n key,\n value\n ]) => `${key}=\"${escapeLabel(value)}\"`).join(\",\")}}`;\n}\n\nfunction appendMetric (\n lines: string[], name: string, labelsInput: Record<string, string | undefined>, value: HealthMetricValue\n): void {\n const numeric = metricValue(value);\n\n if (numeric === null) return;\n\n lines.push(`${name}${labels(labelsInput)} ${numeric}`);\n}\n\nfunction appendDescriptions (\n lines: string[], report: HealthReport, prefix: string\n): void {\n const descriptions = new Map<string, string>([\n [\n metricName(\n \"health.status\", prefix\n ),\n \"Current aggregate health status.\"\n ],\n [\n metricName(\n \"health.check.status\", prefix\n ),\n \"Current status of a registered health check.\"\n ],\n [\n metricName(\n \"health.check.duration_milliseconds\", prefix\n ),\n \"Duration of a registered health check in milliseconds.\"\n ],\n [\n metricName(\n \"health.run.duration_milliseconds\", prefix\n ),\n \"Duration of the health report run in milliseconds.\"\n ]\n ]);\n\n for (const metric of report.metrics) {\n if (metric.description) {\n descriptions.set(\n metricName(\n metric.name, prefix\n ), metric.description\n );\n }\n }\n\n for (const [\n name,\n description\n ] of descriptions) {\n const sanitizedDescription = description.replace(\n /\\s+/g, \" \"\n ).trim();\n lines.push(`# HELP ${name} ${sanitizedDescription}`);\n }\n}\n\nfunction appendHealthStatus (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const name = metricName(\n \"health.status\", prefix\n );\n\n for (const status of STATUSES) {\n appendMetric(\n lines, name, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n status,\n }, report.status === status ? 1 : 0\n );\n }\n}\n\nfunction appendCheckMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const statusName = metricName(\n \"health.check.status\", prefix\n );\n const durationName = metricName(\n \"health.check.duration_milliseconds\", prefix\n );\n\n for (const check of report.checks) {\n for (const status of STATUSES) {\n appendMetric(\n lines, statusName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n status,\n }, check.status === status ? 1 : 0\n );\n }\n\n appendMetric(\n lines, durationName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n }, check.durationMs\n );\n }\n}\n\nfunction appendReportMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const runDurationName = metricName(\n \"health.run.duration_milliseconds\", prefix\n );\n appendMetric(\n lines, runDurationName, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n }, report.durationMs\n );\n\n for (const metric of report.metrics) {\n appendHealthMetric(\n lines, metric, report, prefix, defaults\n );\n }\n}\n\nfunction appendHealthMetric (\n lines: string[], metric: HealthMetric, report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n appendMetric(\n lines, metricName(\n metric.name, prefix\n ), {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n ...metric.labels,\n }, metric.value\n );\n}\n\nexport function toPrometheusText (\n report: HealthReport, options: PrometheusExportOptions = {}\n): string {\n const prefix = options.prefix ?? \"nexload\";\n const defaults = options.defaultLabels ?? {};\n const lines: string[] = [];\n\n if (options.includeDescriptions) {\n appendDescriptions(\n lines, report, prefix\n );\n }\n\n appendHealthStatus(\n lines, report, prefix, defaults\n );\n appendCheckMetrics(\n lines, report, prefix, defaults\n );\n appendReportMetrics(\n lines, report, prefix, defaults\n );\n\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nexport function toOpenMetricsText (\n report: HealthReport, options: OpenMetricsExportOptions = {}\n): string {\n return `${toPrometheusText(\n report, options\n )}# EOF\\n`;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,WAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,WACP,MAAc,QACN;AACR,QAAM,aAAa,KAAK;AAAA,IACtB;AAAA,IAAmB;AAAA,EACrB,EAAE;AAAA,IACA;AAAA,IAAO;AAAA,EACT,EACG;AAAA,IACC;AAAA,IAAY;AAAA,EACd,EACC,YAAY;AAEf,SAAO,GAAG,MAAM,IAAI,UAAU;AAChC;AAEA,SAAS,YAAa,OAAyC;AAC7D,MAAI,OAAO,UAAU,SAAU,QAA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IAAQ;AAAA,EACzB;AACA;AAAA,IACE;AAAA,IAAO;AAAA,IAAQ;AAAA,IAAQ;AAAA,EACzB;AAEA,SAAO,GAAG,MAAM,KAAK,IAAI,CAAC;AAAA;AAC5B;AAEO,SAAS,kBACd,QAAsB,UAAoC,CAAC,GACnD;AACR,SAAO,GAAG;AAAA,IACR;AAAA,IAAQ;AAAA,EACV,CAAC;AAAA;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EAEb,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EAEb,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AA8N/D,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,uBAA4B,GAC1D,MAAM,CAsBR;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,wBAA6B,GAC3D,MAAM,CAIR"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @nexload-sdk/healthcheck-prometheus
|
|
1
|
+
// @nexload-sdk/healthcheck-prometheus v3.0.0 (build 2026-11-25T11:31:38.690Z)
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
var STATUSES = [
|
|
@@ -62,6 +62,59 @@ function appendMetric(lines, name, labelsInput, value) {
|
|
|
62
62
|
if (numeric === null) return;
|
|
63
63
|
lines.push(`${name}${labels(labelsInput)} ${numeric}`);
|
|
64
64
|
}
|
|
65
|
+
function appendDescriptions(lines, report, prefix) {
|
|
66
|
+
const descriptions = /* @__PURE__ */ new Map([
|
|
67
|
+
[
|
|
68
|
+
metricName(
|
|
69
|
+
"health.status",
|
|
70
|
+
prefix
|
|
71
|
+
),
|
|
72
|
+
"Current aggregate health status."
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
metricName(
|
|
76
|
+
"health.check.status",
|
|
77
|
+
prefix
|
|
78
|
+
),
|
|
79
|
+
"Current status of a registered health check."
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
metricName(
|
|
83
|
+
"health.check.duration_milliseconds",
|
|
84
|
+
prefix
|
|
85
|
+
),
|
|
86
|
+
"Duration of a registered health check in milliseconds."
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
metricName(
|
|
90
|
+
"health.run.duration_milliseconds",
|
|
91
|
+
prefix
|
|
92
|
+
),
|
|
93
|
+
"Duration of the health report run in milliseconds."
|
|
94
|
+
]
|
|
95
|
+
]);
|
|
96
|
+
for (const metric of report.metrics) {
|
|
97
|
+
if (metric.description) {
|
|
98
|
+
descriptions.set(
|
|
99
|
+
metricName(
|
|
100
|
+
metric.name,
|
|
101
|
+
prefix
|
|
102
|
+
),
|
|
103
|
+
metric.description
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const [
|
|
108
|
+
name,
|
|
109
|
+
description
|
|
110
|
+
] of descriptions) {
|
|
111
|
+
const sanitizedDescription = description.replace(
|
|
112
|
+
/\s+/g,
|
|
113
|
+
" "
|
|
114
|
+
).trim();
|
|
115
|
+
lines.push(`# HELP ${name} ${sanitizedDescription}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
65
118
|
function appendHealthStatus(lines, report, prefix, defaults) {
|
|
66
119
|
const name = metricName(
|
|
67
120
|
"health.status",
|
|
@@ -165,6 +218,13 @@ function toPrometheusText(report, options = {}) {
|
|
|
165
218
|
const prefix = options.prefix ?? "nexload";
|
|
166
219
|
const defaults = options.defaultLabels ?? {};
|
|
167
220
|
const lines = [];
|
|
221
|
+
if (options.includeDescriptions) {
|
|
222
|
+
appendDescriptions(
|
|
223
|
+
lines,
|
|
224
|
+
report,
|
|
225
|
+
prefix
|
|
226
|
+
);
|
|
227
|
+
}
|
|
168
228
|
appendHealthStatus(
|
|
169
229
|
lines,
|
|
170
230
|
report,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HealthMetric,\n HealthMetricValue,\n HealthReport,\n HealthStatus\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface PrometheusExportOptions {\n prefix?: string\n defaultLabels?: Record<string, string>\n includeDescriptions?: boolean\n}\n\nexport type OpenMetricsExportOptions = PrometheusExportOptions;\n\nconst STATUSES: readonly HealthStatus[] = [\n \"ok\",\n \"degraded\",\n \"unhealthy\"\n];\nconst ALLOWED_LABELS = new Set([\n \"service\",\n \"scope\",\n \"check\",\n \"component\",\n \"dependency\",\n \"runtime\",\n \"status\",\n \"error_code\",\n \"collector\",\n \"version\"\n]);\n\nfunction metricName (\n name: string, prefix: string\n): string {\n const normalized = name.replace(\n /[^a-zA-Z0-9_:]/g, \"_\"\n ).replace(\n /_+/g, \"_\"\n )\n .replace(\n /^_+|_+$/g, \"\"\n )\n .toLowerCase();\n return `${prefix}_${normalized}`;\n}\n\nfunction metricValue (value: HealthMetricValue): number | null {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"boolean\") return value ? 1 : 0;\n if (typeof value === \"string\") return 1;\n return null;\n}\n\nfunction escapeLabel (value: string): string {\n return value.replace(\n /\\\\/g, \"\\\\\\\\\"\n ).replace(\n /\\n/g, \"\\\\n\"\n )\n .replace(\n /\"/g, \"\\\\\\\"\"\n );\n}\n\nfunction labels (input: Record<string, string | undefined>): string {\n const entries = Object.entries(input)\n .filter((entry): entry is [string, string] => Boolean(entry[1]) && ALLOWED_LABELS.has(entry[0]))\n .sort((\n [a], [b]\n ) => a.localeCompare(b));\n\n if (entries.length === 0) return \"\";\n\n return `{${entries.map(([\n key,\n value\n ]) => `${key}=\"${escapeLabel(value)}\"`).join(\",\")}}`;\n}\n\nfunction appendMetric (\n lines: string[], name: string, labelsInput: Record<string, string | undefined>, value: HealthMetricValue\n): void {\n const numeric = metricValue(value);\n if (numeric === null) return;\n\n lines.push(`${name}${labels(labelsInput)} ${numeric}`);\n}\n\nfunction appendHealthStatus (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const name = metricName(\n \"health.status\", prefix\n );\n\n for (const status of STATUSES) {\n appendMetric(\n lines, name, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n status,\n }, report.status === status ? 1 : 0\n );\n }\n}\n\nfunction appendCheckMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const statusName = metricName(\n \"health.check.status\", prefix\n );\n const durationName = metricName(\n \"health.check.duration_milliseconds\", prefix\n );\n\n for (const check of report.checks) {\n for (const status of STATUSES) {\n appendMetric(\n lines, statusName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n status,\n }, check.status === status ? 1 : 0\n );\n }\n\n appendMetric(\n lines, durationName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n }, check.durationMs\n );\n }\n}\n\nfunction appendReportMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const runDurationName = metricName(\n \"health.run.duration_milliseconds\", prefix\n );\n appendMetric(\n lines, runDurationName, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n }, report.durationMs\n );\n\n for (const metric of report.metrics) {\n appendHealthMetric(\n lines, metric, report, prefix, defaults\n );\n }\n}\n\nfunction appendHealthMetric (\n lines: string[], metric: HealthMetric, report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n appendMetric(\n lines, metricName(\n metric.name, prefix\n ), {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n ...metric.labels,\n }, metric.value\n );\n}\n\nexport function toPrometheusText (\n report: HealthReport, options: PrometheusExportOptions = {}\n): string {\n const prefix = options.prefix ?? \"nexload\";\n const defaults = options.defaultLabels ?? {};\n const lines: string[] = [];\n\n appendHealthStatus(\n lines, report, prefix, defaults\n );\n appendCheckMetrics(\n lines, report, prefix, defaults\n );\n appendReportMetrics(\n lines, report, prefix, defaults\n );\n\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nexport function toOpenMetricsText (\n report: HealthReport, options: OpenMetricsExportOptions = {}\n): string {\n return `${toPrometheusText(\n report, options\n )}# EOF\\n`;\n}\n"],
|
|
5
|
-
"mappings": ";;;AAeA,IAAM,WAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,WACP,MAAc,QACN;AACR,QAAM,aAAa,KAAK;AAAA,IACtB;AAAA,IAAmB;AAAA,EACrB,EAAE;AAAA,IACA;AAAA,IAAO;AAAA,EACT,EACG;AAAA,IACC;AAAA,IAAY;AAAA,EACd,EACC,YAAY;
|
|
4
|
+
"sourcesContent": ["import type {\n HealthMetric,\n HealthMetricValue,\n HealthReport,\n HealthStatus\n} from \"@nexload-sdk/healthcheck\";\n\nexport interface PrometheusExportOptions {\n prefix?: string\n defaultLabels?: Record<string, string>\n includeDescriptions?: boolean\n}\n\nexport type OpenMetricsExportOptions = PrometheusExportOptions;\n\nconst STATUSES: readonly HealthStatus[] = [\n \"ok\",\n \"degraded\",\n \"unhealthy\"\n];\nconst ALLOWED_LABELS = new Set([\n \"service\",\n \"scope\",\n \"check\",\n \"component\",\n \"dependency\",\n \"runtime\",\n \"status\",\n \"error_code\",\n \"collector\",\n \"version\"\n]);\n\nfunction metricName (\n name: string, prefix: string\n): string {\n const normalized = name.replace(\n /[^a-zA-Z0-9_:]/g, \"_\"\n ).replace(\n /_+/g, \"_\"\n )\n .replace(\n /^_+|_+$/g, \"\"\n )\n .toLowerCase();\n\n return `${prefix}_${normalized}`;\n}\n\nfunction metricValue (value: HealthMetricValue): number | null {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"boolean\") return value ? 1 : 0;\n if (typeof value === \"string\") return 1;\n\n return null;\n}\n\nfunction escapeLabel (value: string): string {\n return value.replace(\n /\\\\/g, \"\\\\\\\\\"\n ).replace(\n /\\n/g, \"\\\\n\"\n )\n .replace(\n /\"/g, \"\\\\\\\"\"\n );\n}\n\nfunction labels (input: Record<string, string | undefined>): string {\n const entries = Object.entries(input)\n .filter((entry): entry is [string, string] => Boolean(entry[1]) && ALLOWED_LABELS.has(entry[0]))\n .sort((\n [a], [b]\n ) => a.localeCompare(b));\n\n if (entries.length === 0) return \"\";\n\n return `{${entries.map(([\n key,\n value\n ]) => `${key}=\"${escapeLabel(value)}\"`).join(\",\")}}`;\n}\n\nfunction appendMetric (\n lines: string[], name: string, labelsInput: Record<string, string | undefined>, value: HealthMetricValue\n): void {\n const numeric = metricValue(value);\n\n if (numeric === null) return;\n\n lines.push(`${name}${labels(labelsInput)} ${numeric}`);\n}\n\nfunction appendDescriptions (\n lines: string[], report: HealthReport, prefix: string\n): void {\n const descriptions = new Map<string, string>([\n [\n metricName(\n \"health.status\", prefix\n ),\n \"Current aggregate health status.\"\n ],\n [\n metricName(\n \"health.check.status\", prefix\n ),\n \"Current status of a registered health check.\"\n ],\n [\n metricName(\n \"health.check.duration_milliseconds\", prefix\n ),\n \"Duration of a registered health check in milliseconds.\"\n ],\n [\n metricName(\n \"health.run.duration_milliseconds\", prefix\n ),\n \"Duration of the health report run in milliseconds.\"\n ]\n ]);\n\n for (const metric of report.metrics) {\n if (metric.description) {\n descriptions.set(\n metricName(\n metric.name, prefix\n ), metric.description\n );\n }\n }\n\n for (const [\n name,\n description\n ] of descriptions) {\n const sanitizedDescription = description.replace(\n /\\s+/g, \" \"\n ).trim();\n lines.push(`# HELP ${name} ${sanitizedDescription}`);\n }\n}\n\nfunction appendHealthStatus (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const name = metricName(\n \"health.status\", prefix\n );\n\n for (const status of STATUSES) {\n appendMetric(\n lines, name, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n status,\n }, report.status === status ? 1 : 0\n );\n }\n}\n\nfunction appendCheckMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const statusName = metricName(\n \"health.check.status\", prefix\n );\n const durationName = metricName(\n \"health.check.duration_milliseconds\", prefix\n );\n\n for (const check of report.checks) {\n for (const status of STATUSES) {\n appendMetric(\n lines, statusName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n status,\n }, check.status === status ? 1 : 0\n );\n }\n\n appendMetric(\n lines, durationName, {\n ...defaults,\n service: report.service.name,\n scope: String(check.scope),\n check: check.name,\n component: check.component,\n }, check.durationMs\n );\n }\n}\n\nfunction appendReportMetrics (\n lines: string[], report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n const runDurationName = metricName(\n \"health.run.duration_milliseconds\", prefix\n );\n appendMetric(\n lines, runDurationName, {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n }, report.durationMs\n );\n\n for (const metric of report.metrics) {\n appendHealthMetric(\n lines, metric, report, prefix, defaults\n );\n }\n}\n\nfunction appendHealthMetric (\n lines: string[], metric: HealthMetric, report: HealthReport, prefix: string, defaults: Record<string, string>\n): void {\n appendMetric(\n lines, metricName(\n metric.name, prefix\n ), {\n ...defaults,\n service: report.service.name,\n scope: report.scope,\n ...metric.labels,\n }, metric.value\n );\n}\n\nexport function toPrometheusText (\n report: HealthReport, options: PrometheusExportOptions = {}\n): string {\n const prefix = options.prefix ?? \"nexload\";\n const defaults = options.defaultLabels ?? {};\n const lines: string[] = [];\n\n if (options.includeDescriptions) {\n appendDescriptions(\n lines, report, prefix\n );\n }\n\n appendHealthStatus(\n lines, report, prefix, defaults\n );\n appendCheckMetrics(\n lines, report, prefix, defaults\n );\n appendReportMetrics(\n lines, report, prefix, defaults\n );\n\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nexport function toOpenMetricsText (\n report: HealthReport, options: OpenMetricsExportOptions = {}\n): string {\n return `${toPrometheusText(\n report, options\n )}# EOF\\n`;\n}\n"],
|
|
5
|
+
"mappings": ";;;AAeA,IAAM,WAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,WACP,MAAc,QACN;AACR,QAAM,aAAa,KAAK;AAAA,IACtB;AAAA,IAAmB;AAAA,EACrB,EAAE;AAAA,IACA;AAAA,IAAO;AAAA,EACT,EACG;AAAA,IACC;AAAA,IAAY;AAAA,EACd,EACC,YAAY;AAEf,SAAO,GAAG,MAAM,IAAI,UAAU;AAChC;AAEA,SAAS,YAAa,OAAyC;AAC7D,MAAI,OAAO,U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,IAAQ;AAAA,IAAQ;AAAA,EACzB;AACA;AAAA,IACE;AAAA,IAAO;AAAA,IAAQ;AAAA,IAAQ;AAAA,EACzB;AAEA,SAAO,GAAG,MAAM,KAAK,IAAI,CAAC;AAAA;AAC5B;AAEO,SAAS,kBACd,QAAsB,UAAoC,CAAC,GACnD;AACR,SAAO,GAAG;AAAA,IACR;AAAA,IAAQ;AAAA,EACV,CAAC;AAAA;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexload-sdk/healthcheck-prometheus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Prometheus and OpenMetrics text serializers for @nexload-sdk/healthcheck reports.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"healthcheck",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nexload-sdk/healthcheck": "
|
|
35
|
+
"@nexload-sdk/healthcheck": "5.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^25.0.3",
|
|
39
39
|
"eslint": "^9.39.2",
|
|
40
40
|
"typescript": "5.9.3",
|
|
41
41
|
"@nexload-sdk/bundler": "4.0.1",
|
|
42
|
-
"@nexload-sdk/typescript-config": "
|
|
43
|
-
"@nexload-sdk/eslint-config": "
|
|
42
|
+
"@nexload-sdk/typescript-config": "5.9.3",
|
|
43
|
+
"@nexload-sdk/eslint-config": "9.39.2"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "node esbuild.config.mjs",
|