提问人:Yonatan 提问时间:11/16/2023 更新时间:11/16/2023 访问量:21
NestJS OpenTelemtry - 无法使用 Telegraf 收集指标
NestJS OpenTelemtry - Failure to collect metrics using Telegraf
问:
我正在尝试使用 nestjs-otel 包使用 OpenTelemetry 自动检测我的 NestJS 项目。我按照说明进行了操作,并按照其中一个未解决的问题进行了更正。
这是我对otelSdk的主要配置:
export const otelSDK = new NodeSDK({
metricReader: new PrometheusExporter({
port: 8125,
}),
contextManager: new AsyncLocalStorageContextManager(),
instrumentations: [
new PinoInstrumentation(),
new HttpInstrumentation(),
new NestInstrumentation(),
getNodeAutoInstrumentations(),
]
});
在本地运行服务时,我已经设法启动并运行了指标,因此在访问时,我看到指标进来了:http://localhost:8125/metrics
...
# HELP http_server_duration Measures the duration of inbound HTTP requests.
# UNIT http_server_duration ms
# TYPE http_server_duration histogram
http_server_duration_count{http_scheme="http",http_method="GET",net_host_name="localhost",http_flavor="1.1",http_status_code="200",net_host_port="8125"} 3
http_server_duration_sum{http_scheme="http",http_method="GET",net_host_name="localhost",http_flavor="1.1",http_status_code="200",net_host_port="8125"} 933.854501
http_server_duration_bucket{http_scheme="http",http_method="GET",net_host_name="localhost",http_flavor="1.1",http_status_code="200",net_host_port="8125",le="0"} 0
http_server_duration_bucket{http_scheme="http",http_method="GET",net_host_name="localhost",http_flavor="1.1",http_status_code="200",net_host_port="8125",le="5"} 0
http_server_duration_bucket{http_scheme="http",http_method="GET",net_host_name="localhost",http_flavor="1.1",http_status_code="200",net_host_port="8125",le="10"} 0
...
我正在使用 Kubernetes 部署我的服务,并使用注入 telegraf sidecar 来收集我的指标。我在我的资源上提供了以下注释:telegraf-operator
deployment
telegraf.influxdata.com/class: influxdb
telegraf.influxdata.com/inputs: |+
[[inputs.prometheus]]
urls = ["http://localhost:{{ .Values.deployment.metrics.port }}{{ .Values.deployment.metrics.route }}"]
metric_version = 1
但是,在 Kubernetes 上运行服务时,出现以下错误:
[inputs.prometheus] Error in plugin: error reading metrics for http://localhost:8125/metrics: reading text format failed: text format parsing error in line X: second HELP line for metric name "http_server_duration"
据我了解,指标格式和 telegraf 输入插件异常之间存在不匹配。我不确定我应该使用哪个插件,以及我是否需要进行任何配置更改才能正常工作。
您的帮助将不胜感激。
答:
0赞
Yonatan
11/16/2023
#1
我发现问题出是因为指标被发送了两次。我必须删除 和 才能让副本消失。
然后,问题就解决了。http_server_duration
new HttpInstrumentation()
getNodeAutoInstrumentations()
评论