Skip to content

Production Guides & Recipes

In Next.js, use createNextMetricsRoute from @nexload-sdk/healthcheck-next. In any other framework, serialize the report yourself:

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.


OptionTypeDefaultDescription
prefixstring"nexload"Metric name prefix.
defaultLabelsRecord<string, string>{}Labels added to every series. Labels outside the allowlist are dropped.
includeDescriptionsbooleanfalseEmits # HELP lines.

SeriesLabelsValue
<prefix>_health_statusscope, service, status1 for the active status, 0 for the other two.
<prefix>_health_check_statuscheck, component, scope, service, statusSame encoding, per check.
<prefix>_health_check_duration_millisecondscheck, component, scope, serviceDuration of each check.
<prefix>_health_run_duration_millisecondsscope, serviceDuration of the whole run.
<prefix>_<collector_metric_name>from the collectorEvery metric in report.metrics.

1. Prometheus Scraper Reports text format parse error

Section titled “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.

Only the allowlisted labels are emitted. Do not use user IDs or request IDs as labels; put static service data in defaultLabels.