NestJS OpenTelemtry - 无法使用 Telegraf 收集指标

问题描述 投票:0回答:1

我正在尝试使用 OpenTelemetry 使用 nestjs-otel 包自动检测我的 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-operator
注入 telegraf sidecar 来收集我的指标。我在我的
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 输入插件例外之间存在不匹配。我不确定应该使用哪个插件,以及是否需要进行任何配置更改才能使其正常工作。

您的帮助将不胜感激。

nestjs prometheus metrics open-telemetry telegraf-inputs-plugin
1个回答
0
投票

我发现问题是因为

http_server_duration
指标发送了两次。我必须删除
new HttpInstrumentation()
getNodeAutoInstrumentations()
才能使重复项消失。 然后问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.