SpringBoot使用Actuator+Jolokia+Telegraf+Influxdb+Grafana搭建图形化服务监控平台

随着服务的复杂度上升,对服务的监控和管理的需求显著增加,开发人员可以使用Jconsole、jvisualvm、jinfo、jstat等工具分析服务的运行状况,但是对于运维人员以及其他非开发人员就不具有可行性;故需要搭建一套图形化的监控平台。

简介

Actuator

actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。Actuator使用方法

Jolokia

Spring Boot Actuator对外暴露应用的监控信息,Jolokia提供使用HTTP接口获取JSON格式 的数据。Jolokia使用方法

Telegraf

收集系统和服务的统计数据,并支持写入到 InfluxDB 数据库。官方地址

Influxdb

InfluxDB 是一个开源分布式时序、事件和指标数据库。它具备如下主要特性;官方地址

  • Time Series (时间序列):你以使用与时间有关的相关函数(如最大,最小,求和等)
  • Metrics(度量):你可以实时对大量数据进行计算
  • Eevents(事件):它支持任意的事件数据

Grafana

Grafana 是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点。官方地址

安装

Telegraf

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

Influxdb

使用Centos,安装方法如下,

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.3.5.x86_64.rpm
sudo yum localinstall influxdb-1.3.5.x86_64.rpm

Grafana

使用Centos安装方法如下,其他系统安装参考

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 

配置

Telegraf

  • 打开配置文件

    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
    

Influxdb

  • 打开配置文件

    vi /etc/influxdb/influxdb.conf      
    
  • 若不需要修改端口或其他,可使用默认配置

  • 启动服务

    systemctl start influxdb
    

Grafana

  • 使用默认配置,使用sqlite3数据库保存配置信息,若需要更换数据库,可打开/etc/grafana/grafana.ini配置

  • 启动

    grafana-server
    

使用

  • 新建Springboot应用,添加如下依赖:
<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

  1. 结果如下

 

其他

  • Telegraf中Jolokia监控源配置方法,可先打开Jconsole工具,找到需监控的应用,打开Mbean选项:

 

  • 找到springboot中的Endpoint的metricsEndpoint
    上文中Telegraf配置
[[inputs.jolokia.metrics]]
name = "metrics"
mbean  ="org.springframework.boot:name=metricsEndpoint,type=Endpoint"
attribute = "Data"     
  1. name可自定义
  2. mbean 对应我们选择的需监控对象的ObjectName的值org.springframework.boot:type=Endpoint,name=metricsEndpoint

 

  1. attribute 对应节点的属性中的Data
  2. 其他需要监控的节点信息,可按该方法找到对应的信息,如内存信息监控信息
[[inputs.jolokia.metrics]]
  name = "heap_memory_usage"
 mbean  = "java.lang:type=Memory"
 attribute = "HeapMemoryUsage"

 

grafana + influxdb + telegraf , 构建linux性能监控平台

https://blog.csdn.net/li_xue_zhao/article/details/79800140

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章