将服务器名称添加到 Datadog 的指标

Add server name to metrics for Datadog

我用dropwizard metrics with metrics-datadog.

像这样创建报告:

HttpTransport httpTransport = new HttpTransport.Builder().withApiKey(API_KEY).build();

DatadogReporter reporter;
reporter = DatadogReporter.forRegistry(metrics)
            .withTransport(httpTransport)
            .withPrefix(PREFIX)
            .withTags(tags)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build();

reporter.start(value, unit);

但是datadog中没有host(server name)参数。如何为指标添加主机(服务器名称)以在 datadog 控制面板中过滤它们?默认数据狗代理的指标具有服务器名称属性。

只需为 org.coursera.metrics.datadog.DatadogReporter.Builder 设置主机名:

.withHost(InetAddress.getLocalHost().getCanonicalHostName())