【问题标题】:No Token Found error in PrometheusPrometheus 中未找到令牌错误
【发布时间】:2018-10-31 20:41:21
【问题描述】:

我想用 Prometheus 监控我的 .Net Core 应用程序。 为了做到这一点,我使用了一个 .Net Prometheus Library (AppMetrics)。 当我转到链接 http://localhost:57057/metrics 时,它会返回一个带有数据的 JSON。

但是当我去普罗米修斯并将这个链接添加为目标时,它会抛出这个错误No Token Found

level=warn ts=2018-05-22T06:52:17.5781093Z caller=scrape.go:697 component="scrape manager" scrape_pool=actibook target=http://localhost:57057/metrics msg="append failed" err="no token找到”

这是我可以处理的方法吗?

任何对此有问题的人都可以在这里解决。

Startup.cs

//ConfigureServices
var metrics = new MetricsBuilder()
                            .OutputMetrics.AsPrometheusPlainText()
                            .OutputMetrics.AsPrometheusProtobuf().Build();
            services.AddMetrics(metrics);
            services.AddMetricsEndpoints(options =>
            {
                options.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
                options.MetricsEndpointOutputFormatter = new MetricsPrometheusProtobufOutputFormatter();
            });
            services.AddMvc().AddMetrics();

//Configure
            app.UseMetricsAllMiddleware();
            app.UseMetricsAllEndpoints();

程序.cs

Metrics = AppMetrics.CreateDefaultBuilder()
                        .OutputMetrics.AsPrometheusPlainText()
                        .OutputMetrics.AsPrometheusProtobuf()
                        .Build();

            return WebHost.CreateDefaultBuilder(args)
                .ConfigureMetrics(Metrics)
                .UseMetrics()
                .UseStartup<Startup>()
                .Build();

appsettings.json

"MetricsOptions": {
    "DefaultContextLabel": "MyMvcApplication",
    "Enabled": true
  },
  "MetricsWebTrackingOptions": {
    "ApdexTrackingEnabled": true,
    "ApdexTSeconds": 0.1,
    "IgnoredHttpStatusCodes": [ 404 ],
    "IgnoredRoutesRegexPatterns": [],
    "OAuth2TrackingEnabled": true
  },
  "MetricEndpointsOptions": {
    "MetricsEndpointEnabled": true,
    "MetricsTextEndpointEnabled": true,
    "EnvironmentInfoEndpointEnabled": true
  }

您可以通过/metrics-text 路径访问它。 同样在你的prometheus.yml 文件中应该添加这个:

- job_name: 'nameOfJob'
    metrics_path: '/metrics-text'
    static_configs:
      - targets: ['localhost:57057']

【问题讨论】:

    标签: asp.net-core monitoring monitor prometheus


    【解决方案1】:

    这通常意味着输出不是有效的 Prometheus 文本格式。查找指标或标签名称中的连字符,或其中任何一个以数字开头的连字符 - 这些是最常见的错误。

    【讨论】:

    • 是的,我已经写了解决方案。在我发现问题所在之后。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多