# healthcheck-prometheus — Agent usage Configure a coding agent for @nexload-sdk/healthcheck-prometheus. **Topic:** agents **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/agents/ ## Install matching skills Install the skills whose triggers match the task. ### healthcheck-monitoring-exporters [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/monitoring-exporters/SKILL.md) ```text Use when converting an existing HealthReport with @nexload-sdk/healthcheck-prometheus or @nexload-sdk/healthcheck-otel, including Prometheus/OpenMetrics text, OTel resource attributes and metric records, collector-only export boundaries, prefixes, metric names, HELP descriptions, label allowlists, dropped labels, deterministic output, and cardinality review. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-monitoring-exporters ``` ### healthcheck-diagnostics-security [Trigger](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/diagnostics-security/SKILL.md) ```text Use when deciding or reviewing public versus private health exposure, diagnostics details, metrics access, JSON redaction, error and stack suppression, bearer or Basic authentication, IPv4/CIDR allowlists, trusted proxy headers, no-store policy, or sensitive and high-cardinality health data. Compose with the route or exporter skill that owns implementation. ``` ```bash npx skills add gecut/nexload-sdk --skill healthcheck-diagnostics-security ``` ## Project AGENTS.md ```markdown For @nexload-sdk/healthcheck-prometheus, load healthcheck-monitoring-exporters when its trigger matches. Read the package bundle and check public exports against the installed version before editing. ``` ## Package context [Scoped Markdown bundle](/nexload-sdk/packages/healthcheck/prometheus/llms.txt). ## Prompts ```text Scrape health metrics as text. Use @nexload-sdk/healthcheck-prometheus and healthcheck-monitoring-exporters. Inspect the installed version and show a minimal typed example for my project. ``` ```text Review my @nexload-sdk/healthcheck-prometheus integration against the optimization page. Identify the relevant source for each finding and one test for the highest-risk behavior. ``` --- # API Reference & Compatibility Public API symbol reference and compatibility matrix for Healthcheck Prometheus. **Topic:** api **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/api/ The complete public API symbol inventory is generated automatically from package source exports: ## Functions ### `toOpenMetricsText` ```ts toOpenMetricsText(report: HealthReport, options?: OpenMetricsExportOptions) => string ``` **Exported from:** `@nexload-sdk/healthcheck-prometheus` Public function exported by @nexload-sdk/healthcheck-prometheus. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/src/index.ts#L262) ### `toPrometheusText` ```ts toPrometheusText(report: HealthReport, options?: PrometheusExportOptions) => string ``` **Exported from:** `@nexload-sdk/healthcheck-prometheus` Public function exported by @nexload-sdk/healthcheck-prometheus. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/src/index.ts#L236) ## Interfaces ### `PrometheusExportOptions` ```ts interface PrometheusExportOptions { prefix?: string defaultLabels?: Record includeDescriptions?: boolean } ``` **Exported from:** `@nexload-sdk/healthcheck-prometheus` Public interface exported by @nexload-sdk/healthcheck-prometheus. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/src/index.ts#L8) ## Types ### `OpenMetricsExportOptions` ```ts type OpenMetricsExportOptions = PrometheusExportOptions; ``` **Exported from:** `@nexload-sdk/healthcheck-prometheus` Public type exported by @nexload-sdk/healthcheck-prometheus. [Source](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/src/index.ts#L14) *** ## Runtime Compatibility Matrix | Runtime / Engine | Version Requirement | Verification Status | |---|---|---| | **Node.js** | `>=20.9.0` | Verified on Node 20 & 22 | | **Bun** | `>=1.0.0` | Verified on Bun 1.1+ | | **Module Format** | ESM only | Native ECMAScript Modules | | **Side Effects** | `false` | Fully tree-shakeable | --- # Production Guides & Recipes Configuring Prometheus endpoints, metric labels, Grafana alerts, and troubleshooting. **Topic:** guides **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/guides/ ## Exposing the `/metrics` Endpoint In Next.js, use `createNextMetricsRoute` from `@nexload-sdk/healthcheck-next`. In any other framework, serialize the report yourself: ```ts import { toPrometheusText } from "@nexload-sdk/healthcheck-prometheus"; import { health } from "@/lib/health"; export async function handleMetrics() { const report = await health.run("all", { profile: "monitoring" }); const body = toPrometheusText(report, { prefix: "shop_api", defaultLabels: { version: "1.2.0" }, includeDescriptions: true, }); return new Response(body, { status: 200, headers: { "Content-Type": "text/plain; version=0.0.4; charset=utf-8" }, }); } ``` For OpenMetrics, call `toOpenMetricsText` with the same options and answer with `Content-Type: application/openmetrics-text; version=1.0.0; charset=utf-8`. *** ## Options | Option | Type | Default | Description | |---|---|---|---| | `prefix` | `string` | `"nexload"` | Metric name prefix. | | `defaultLabels` | `Record` | `{}` | Labels added to every series. Labels outside the allowlist are dropped. | | `includeDescriptions` | `boolean` | `false` | Emits `# HELP` lines. | *** ## Emitted Series | Series | Labels | Value | |---|---|---| | `_health_status` | `scope`, `service`, `status` | `1` for the active status, `0` for the other two. | | `_health_check_status` | `check`, `component`, `scope`, `service`, `status` | Same encoding, per check. | | `_health_check_duration_milliseconds` | `check`, `component`, `scope`, `service` | Duration of each check. | | `_health_run_duration_milliseconds` | `scope`, `service` | Duration of the whole run. | | `_` | from the collector | Every metric in `report.metrics`. | *** ## Troubleshooting & Common Pitfalls ### 1. Prometheus Scraper Reports `text format parse error` Send the content type that matches the function you called: `text/plain; version=0.0.4` for `toPrometheusText`, `application/openmetrics-text; version=1.0.0` for `toOpenMetricsText`. ### 2. A Label Does Not Appear Only the allowlisted labels are emitted. Do not use user IDs or request IDs as labels; put static service data in `defaultLabels`. --- # Overview & Quick Start Serialize healthcheck reports into Prometheus text exposition and OpenMetrics format without heavy SDKs. **Topic:** overview **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/ **Package:** `@nexload-sdk/healthcheck-prometheus` **Workspace version:** `3.0.1` Prometheus and OpenMetrics text serializers for @nexload-sdk/healthcheck reports. [npm](https://www.npmjs.com/package/@nexload-sdk/healthcheck-prometheus) · [Source](https://github.com/gecut/nexload-sdk/tree/main/packages/healthcheck/prometheus) `@nexload-sdk/healthcheck-prometheus` serializes `@nexload-sdk/healthcheck` reports directly into Prometheus text exposition and OpenMetrics format without requiring bloated third-party metric client libraries. *** ## 10-Second Code Snippet ```ts import { createHealthManager, runtimeInfoCheck } from "@nexload-sdk/healthcheck"; import { toPrometheusText } from "@nexload-sdk/healthcheck-prometheus"; const health = createHealthManager({ service: { name: "api" }, checks: [runtimeInfoCheck()], }); const report = await health.run("all", { profile: "monitoring" }); const body = toPrometheusText(report, { prefix: "shop_api" }); // Content-Type: text/plain; version=0.0.4; charset=utf-8 ``` *** ## What You Get * **`toPrometheusText(report, options?)`**: Prometheus text format `0.0.4`, with no dependency on `prom-client`. * **`toOpenMetricsText(report, options?)`**: OpenMetrics `1.0.0` text, ending with `# EOF`. * **Status and duration series**: aggregate status, per-check status, per-check duration, run duration, and every collector metric in `report.metrics`. * **Label allowlist**: only bounded labels are emitted (`service`, `scope`, `check`, `component`, `dependency`, `runtime`, `status`, `error_code`, `collector`, `version`). Other labels are dropped. *** ## Installation & Requirements ```bash pnpm add @nexload-sdk/healthcheck-prometheus @nexload-sdk/healthcheck ``` Requires Node.js `>=20.9.0` or Bun `>=1.0.0`. *** ## Next Steps * Explore [Production Guides & Scraping Setup](./guides/) for metric names, label conventions, and scraping routes. * Check the [API Reference & Signatures](./api/) for `prefix`, `defaultLabels` and `includeDescriptions`. ## Next steps [Optimization](./optimization/) [Agent usage](./agents/) [Playground](./playground/) --- # healthcheck-prometheus — Optimization Production choices for @nexload-sdk/healthcheck-prometheus. **Topic:** optimization **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/optimization/ ## Use supported labels Use low-cardinality labels from the exporter allowlist. Unsupported labels are dropped. ## Export collector metrics Use a metric collector for custom series. Metrics attached to individual checks stay in the JSON report. ## Choose the exposition format Use `toPrometheusText` for Prometheus text or `toOpenMetricsText` for OpenMetrics text. Both serialize an existing report. ## Review dropped labels The allowlist also applies to `defaultLabels` and collector labels. Unsupported labels are silently dropped. ## Sources [Package guidance](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/README.md) · [Implementation](https://github.com/gecut/nexload-sdk/blob/main/packages/healthcheck/prometheus/src/index.ts). · [Matching skill](https://github.com/gecut/nexload-sdk/blob/main/skills/healthcheck/monitoring-exporters/SKILL.md). --- # healthcheck-prometheus — Playground Inspect a local readiness report. **Topic:** playground **Package:** `@nexload-sdk/healthcheck-prometheus` v3.0.1 **Canonical page:** https://gecut.github.io/nexload-sdk/packages/healthcheck/prometheus/playground/ ## Try it Type ok, degraded or unhealthy to change a critical inventory check. Switch between the report and three export formats. ## Read the result The local manager runs a readiness check. Prometheus renders metric text, OpenMetrics adds the EOF marker, and OTel returns metric records. No network service receives the output. Enter `ok`. The output includes the `nexload_health_status` series. [API reference](/nexload-sdk/packages/healthcheck/prometheus/api/).