微服務監控調研

前言

微服務概念已經很是流行,這影響了如今架構的思想潮流。
現在,使用spring cloud體系搭建微服務架構的公司愈來愈多,成本低,出線上產品快,模塊全,開源等緣由將來可能更加流行。
通常,咱們須要一個監控系統來監控應用的數據,好比內存,磁盤,線程狀況,數據庫鏈接池,配置信息,jvm信息等等。html

方案

spring cloud admin

github地址:https://github.com/codecentric/spring-boot-adminjava

若是自己是java技術棧,搭建很是快,新建監控server項目,在spring boot搭建的client項目上配置如下便可,具體直接看文檔。git

InfluxDB 組合方案1

咱們能夠經過 Jolokia + Telegraf + InfluxDB + Grafana 方案
Jolokia: Spring Boot 承認使用Jolokia來經過HTTP導出export JMX數據。你只須要在工程類路徑中增長一些依賴項,一切都是開箱即用的。不須要任何額外的實現。
https://jolokia.org/reference/html/index.htmlgithub

Telegraf: Telegraf支持經過整合Jolokia來集成JMX數據的收集。它有一個預製的輸入插件,它是開箱即用的。不須要任何額外的實現。只須要作一些配置便可。web

InfluxDB: InfluxDB經過 輸出插件從Telegraf接收指標數據,它是開箱即用的,不須要任何額外的實現。spring

Grafana: Grafana經過鏈接InfluxDB做爲數據源來渲染圖標。它是開箱即用的,不須要額外的實現。數據庫

咱們也可使用InfluxDB官方的方案:
架構

1, Spring boot 配置:app

endpoints.jolokia.enabled=true
management.security.enabled=false
management.port=8088
management.context-path=/monitor

pom配置:jvm

<dependency>
   <groupId>org.jolokia</groupId>
   <artifactId>jolokia-core</artifactId>
</dependency>

2,telegraf --config telegraf.conf
配置telegraf.conf
3,./influxd
啓動influxdb
4,./chronograf
啓動chronograf

Prometheus

Prometheus 也是用go開發的方案。

啓動prometheus

./prometheus --config.file=prometheus.yml

prometheus.yml配置:

global:
  scrape_interval:     15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
#  - job_name: prometheus
#    static_configs:
#      - targets: ['localhost:9090']
  - job_name: spring-boot
    scrape_interval: 5s
    scrape_timeout: 5s
    metrics_path: /monitor/prometheus
    scheme: http
    static_configs:
      - targets:
        - 127.0.0.1:8088  #此處填寫 Spring Boot 應用的 IP + 端口號

應用啓動代碼:

@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplicationBuilder(Application.class).web(true).application();
        app.run(args);
    }
}

pom依賴:

<dependency>
   <groupId>io.prometheus</groupId>
   <artifactId>simpleclient_spring_boot</artifactId>
   <version>0.4.0</version>
</dependency>
相關文章
相關標籤/搜索