微服务概念已经很是流行,这影响了如今架构的思想潮流。
现在,使用spring cloud体系搭建微服务架构的公司愈来愈多,成本低,出线上产品快,模块全,开源等缘由将来可能更加流行。
通常,咱们须要一个监控系统来监控应用的数据,好比内存,磁盘,线程状况,数据库链接池,配置信息,jvm信息等等。html
github地址:https://github.com/codecentric/spring-boot-adminjava
若是自己是java技术栈,搭建很是快,新建监控server项目,在spring boot搭建的client项目上配置如下便可,具体直接看文档。git
咱们能够经过 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 也是用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>