簡體   English   中英

Graphite中的Dropwizard指標

[英]Dropwizard metrics in Graphite

我們有使用Jersey創建的多個API端點,其中包含web.xml設置而不是資源配置設置。 我們希望捕獲並顯示每個端點的所有請求的度量標准,包括所有不同的響應代碼。 到目前為止,我已經創建了一個擴展了InstrumentedFilterContextListener的類,並在其中包含了Graphite報告器。

在web.xml中,我添加了以下塊以使報告正常工作:

<listener>
    <listener-class>metrics.MyInstrumentedFilterContextListener</listener-class>
</listener>


<filter>
    <filter-name>testFilter</filter-name>
    <filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
    <init-param>
        <param-name>name-prefix</param-name>
        <param-value>testEndpoint</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>testFilter</filter-name>
    <url-pattern>/api/testEP1/*</url-pattern>
</filter-mapping>
enter code here

<filter>
    <filter-name>testFilter2</filter-name>
    <filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
    <init-param>
        <param-name>name-prefix</param-name>
        <param-value>testEndpoint2</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>testFilter2</filter-name>
    <url-pattern>/api/testEP2/*</url-pattern>
</filter-mapping>

所以使用上面的配置和下面的類我在Graphite Dashboard中獲得了一些信息:

public class MyInstrumentedFilterContextListener extends InstrumentedFilterContextListener {
public static MetricRegistry METRIC_REGISTRY = new MetricRegistry();

static {

    final Graphite graphite = new Graphite(new InetSocketAddress("localhost", 8080));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(METRIC_REGISTRY)
            .prefixedWith("API.Metrics")
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)

            .build(graphite);
    reporter.start(10, TimeUnit.SECONDS);
}

@Override
protected MetricRegistry getMetricRegistry() {
    return METRIC_REGISTRY;
}
}

我現在的問題是,我可以告訴它主要是與機器相關的指標,cpu,內存等正在被捕獲,而不是像我已映射的端點的ok,錯誤或未找到的請求數。 我已經通過添加ConsoleReporter來測試我的偵聽器類正在捕獲請求,以便我可以看到不同請求的所有計數都在增加。 最后,我的問題是如何在Graphite中看到所有相同的Meter和Timer數據? 是否有一些額外的設置我必須設置或獲取此數據的東西,或者在Graphite中被稱為完全不同的數據?

問題是這行中指定的套接字是不正確的,但找到套接字的唯一方法是使用netstat,在我的情況下最終為22033:

final Graphite graphite = new Graphite(new InetSocketAddress("localhost", 8080));

這可能已在石墨中的某個文件中指定,但我沒有在任何文檔中找到它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM