- 4 services add collectDefaultMetrics for process metrics - docker-compose.yml images prefixed with docker.m.daocloud.io - Prometheus v0.51.0 (nonexistent) fixed to v2.51.0 - Grafana port remapped 3000 to 3030 to avoid teacher-portal conflict - ClickHouse edu_analytics database initialized - known-issues.md documents 7 new P6 scenario-to-rule mappings
29 lines
909 B
TypeScript
29 lines
909 B
TypeScript
import promClient from "prom-client";
|
||
|
||
const registry = new promClient.Registry();
|
||
// 修复:在本地 registry 上设置默认标签(原代码误用全局 register)
|
||
registry.setDefaultLabels({ service: "content" });
|
||
|
||
registry.registerMetric(
|
||
new promClient.Counter({
|
||
name: "content_requests_total",
|
||
help: "Total number of content requests",
|
||
labelNames: ["method", "endpoint", "status"],
|
||
}),
|
||
);
|
||
|
||
registry.registerMetric(
|
||
new promClient.Histogram({
|
||
name: "content_request_duration_seconds",
|
||
help: "Content request duration in seconds",
|
||
labelNames: ["method", "endpoint"],
|
||
buckets: [0.01, 0.05, 0.1, 0.3, 0.5, 1, 3, 5],
|
||
}),
|
||
);
|
||
|
||
// 自动收集 Node.js 进程级指标(CPU/内存/事件循环/GC等)
|
||
// 这些指标无需业务代码埋点,prom-client 自动采集
|
||
promClient.collectDefaultMetrics({ register: registry });
|
||
|
||
export { registry as metricsRegistry };
|