metrics+spring+influxdb整合

1.在maven項目的pom.xml引入metrics-spring和metrics-influxdb兩個jar包html

    <dependency>
            <groupId>com.ryantenney.metrics</groupId>
            <artifactId>metrics-spring</artifactId>
            <version>3.1.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.davidb</groupId>
            <artifactId>metrics-influxdb</artifactId>
            <version>0.9.3</version>
        </dependency>

2.配置InfluxdbReporterjava

import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Configuration;

import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.ryantenney.metrics.spring.config.annotation.EnableMetrics;
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;

import metrics_influxdb.HttpInfluxdbProtocol;
import metrics_influxdb.InfluxdbReporter;

@Configuration
@EnableMetrics
public class SpringConfiguringClass extends MetricsConfigurerAdapter {

    @Override
    public void configureReporters(MetricRegistry metricRegistry) {
        // registerReporter allows the MetricsConfigurerAdapter to
        // shut down the reporter when the Spring context is closed
        //輸出度量數據至控制檯
        registerReporter(ConsoleReporter.forRegistry(metricRegistry).build()).start(5, TimeUnit.SECONDS);
        //輸出度數數據到influxdb
        InfluxdbReporter.forRegistry(metricRegistry)
                .protocol(new HttpInfluxdbProtocol("your influxdb server IP address", 8086, "test", "test"))
                .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL)
                .skipIdleMetrics(false).tag("server", "127.0.0.1").build().start(1, TimeUnit.SECONDS);
    }

}

3.在須要監控的代碼方法體上引入相關注解git

 note:方法必須爲public方法github

 

4.參考文檔spring

  Metrics官網 https://metrics.dropwizard.io/4.0.0/getting-started.htmlmaven

  metrics-spring官網 https://github.com/ryantenney/metrics-springide

  metrics-influxdb官網 https://github.com/davidB/metrics-influxdbui

  grafana官網文檔 http://docs.grafana.org/features/panels/graph/spa

5.整合influxdb+grafana+metrics,可參考.net

  https://blog.csdn.net/qq_35981283/article/details/76887173

相關文章
相關標籤/搜索