随着服务的复杂度上升,对服务的监控和管理的需求显著增长,开发人员能够使用Jconsole、jvisualvm、jinfo、jstat等工具分析服务的运行情况,可是对于运维人员以及其余非开发人员就不具备可行性;故须要搭建一套图形化的监控平台。java
actuator是spring boot提供的对应用系统的自省和监控的集成功能,能够对应用系统进行配置查看、相关功能统计等。Actuator使用方法linux
Spring Boot Actuator对外暴露应用的监控信息,Jolokia提供使用HTTP接口获取JSON格式 的数据。Jolokia使用方法web
收集系统和服务的统计数据,并支持写入到 InfluxDB 数据库。官方地址redis
InfluxDB 是一个开源分布式时序、事件和指标数据库。它具有以下主要特性;官方地址spring
Grafana 是一个开箱即用的可视化工具,具备功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,能够混合多种风格,支持多个数据源特色。官方地址sql
使用Centos,安装方法以下,其余系统安装参考数据库
wget https://dl.influxdata.com/telegraf/releases/telegraf-1.3.5-1.x86_64.rpm sudo yum localinstall telegraf-1.3.5-1.x86_64.rpm
使用Centos,安装方法以下,vim
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.3.5.x86_64.rpm sudo yum localinstall influxdb-1.3.5.x86_64.rpm
使用Centos安装方法以下,其余系统安装参考:segmentfault
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.3-1.x86_64.rpm sudo yum localinstall grafana-4.4.3-1.x86_64.rpm
打开配置文件springboot
vim /etc/telegraf/telegraf.conf
配置输入源
Jolokia作为输入源,在Vim中定位到该配置块,在非编辑模式下输入以下命令:
/inputs.telegraf
代码以下:
[[inputs.jolokia]] #配置jolokia接口的路径,可根据本身的实际状况修改 context = "/jolokia/" //须要收集信息的服务地址,多个可增长[[inputs.jolokia.servers]]节点 [[inputs.jolokia.servers]] name = "as-server-01" host = "127.0.0.1" port = "9000" # # username = "myuser" # # password = "mypassword" #须要收集信息的节点,此处可参看后续的配置方法 #收集内存的使用状况 #[[inputs.jolokia.metrics]] # name = "heap_memory_usage" #mbean = "java.lang:type=Memory" #attribute = "HeapMemoryUsage" #收集springboot中actuator的监控信息 [[inputs.jolokia.metrics]] name = "metrics" mbean ="org.springframework.boot:name=metricsEndpoint,type=Endpoint" attribute = "Data"
还支持其余如MQTT、redis等服务,使用方法可参考官方文档。
配置 输出源
使用InfluxDb做为输出源,定位到该模块
/outputs.influxdb
代码以下:
[[outputs.influxdb]] ## The HTTP or UDP URL for your InfluxDB instance. Each item should be ## of the form: ## scheme "://" host [ ":" port] ## ## Multiple urls can be specified as part of the same cluster, ## this means that only ONE of the urls will be written to each interval. # urls = ["udp://localhost:8089"] # UDP endpoint example #influx的http地址,可根据实际状况修改 urls = ["http://localhost:8086"] # required ## The target database for metrics (telegraf will create it if not exists). #数据库名称 database = "telegraf" # required
保存配置文件
启动服务
systemctl start telegraf
打开配置文件
vi /etc/influxdb/influxdb.conf
若不须要修改端口或其余,可以使用默认配置
启动服务
systemctl start influxdb
使用默认配置,使用sqlite3数据库保存配置信息,若须要更换数据库,可打开/etc/grafana/grafana.ini配置
启动
grafana-server
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency>
@RestController public class MyController { //简单技术指标监控 @Autowired CounterService counterService; /** * 声明日志 */ private Logger LOGGER = LoggerFactory.getLogger(this.getClass()); @RequestMapping("/hello") public SimpleResult ver() throws Exception{ counterService.increment("acess.max"); return null; } }
QQ截图20170831154347
3.添加Dashboard,此处监控堆内存的使用状况和刚才添加的自定义指标,
Influxdb的使用方法和相关函数含义可自定查询;
堆内存数据查询
配置堆内存最大堆大小及已使用堆大小监控
自定义指标数据查询
配置接口/hello访问次数监控.jpg
[[inputs.jolokia.metrics]] name = "metrics" mbean ="org.springframework.boot:name=metricsEndpoint,type=Endpoint" attribute = "Data"
[[inputs.jolokia.metrics]] name = "heap_memory_usage" mbean = "java.lang:type=Memory" attribute = "HeapMemoryUsage"
https://blog.csdn.net/li_xue_zhao/article/details/79800140