微服务监控调研

前言

微服务概念已经非常流行,这影响了现在架构的思想潮流。
如今,使用spring cloud体系搭建微服务架构的公司越来越多,成本低,出线上产品快,模块全,开源等原因未来可能更加流行。
一般,我们需要一个监控系统来监控应用的数据,比如内存,磁盘,线程情况,数据库连接池,配置信息,jvm信息等等。

方案

spring cloud admin

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

如果本身是java技术栈,搭建非常快,新建监控server项目,在spring boot搭建的client项目上配置以下即可,具体直接看文档。

InfluxDB 组合方案1

我们可以通过 Jolokia + Telegraf + InfluxDB + Grafana 方案
Jolokia: Spring Boot 认可使用Jolokia来通过HTTP导出export JMX数据。你只需要在工程类路径中增加一些依赖项,一切都是开箱即用的。不需要任何额外的实现。
https://jolokia.org/reference/html/index.html

Telegraf: Telegraf支持通过整合Jolokia来集成JMX数据的收集。它有一个预制的输入插件,它是开箱即用的。不需要任何额外的实现。只需要做一些配置即可。

InfluxDB: InfluxDB通过 输出插件从Telegraf接收指标数据,它是开箱即用的,不需要任何额外的实现。

Grafana: Grafana通过连接InfluxDB作为数据源来渲染图标。它是开箱即用的,不需要额外的实现。

我们也可以使用InfluxDB官方的方案:

1, Spring boot 配置:

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

pom配置:

<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>

posted on 2018-07-08 19:57  每当变幻时  阅读(1077)  评论(0编辑  收藏  举报

导航