Spring Boot2.x-14 使用Prometheus + Grafana 实现可视化的监控
文章目录
- 环境信息
- Prometheus 组件
- 下载 & 安装
- 通过指定配置文件prometheus.yml启动Prometheus
- 查看采集到的性能指标
- 查看prometheus规则
- 查看监控对象
- SpringBoot集成Prometheus
- pom.xml
- 配置文件
- 实例化MeterRegistryCustomizer
- 打包,上传到服务器上
- Prometheus 修改配置文件prometheus.yml 接入该工程
- Grafana 组件
- 下载 & 安装 & 启动Grafana
- Grafana 接入Prometheus 的数据
- Step1 添加Prometheus 数据源
- Step2 设置相关信息
- Step3 导入想要的dashboards
环境信息
OS: Centos7 (防火墙已经关闭)
IP: 192.168.31.34
APP: Spring Boot 2.1.3搭建的演示环境
Prometheus 组件
官网: https://prometheus.io/
下载地址: https://prometheus.io/download/
官方文档: https://prometheus.io/docs/prometheus/latest/getting_started/
Prometheus是一套开源的监控&报警&时间序列数据库的组合,基于应用的metrics来进行监控的开源工具 。
更多信息请参考官网介绍: https://prometheus.io/docs/introduction/overview/
下载 & 安装
官网下载速度太慢,我这里就没有使用最新版本,而是从 http://cactifans.hi-www.com 下载了 prometheus-2.1.0的版本
# 下载 prometheus-2.1.0.linux-amd64.tar.gz
[root@artisan ~]# wget http://cactifans.hi-www.com/prometheus/prometheus-2.1.0.linux-amd64.tar.gz
--2019-03-10 21:57:56-- http://cactifans.hi-www.com/prometheus/prometheus-2.1.0.linux-amd64.tar.gz
Resolving cactifans.hi-www.com (cactifans.hi-www.com)... 222.186.135.67
Connecting to cactifans.hi-www.com (cactifans.hi-www.com)|222.186.135.67|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25271154 (24M) [application/octet-stream]
Saving to: ‘prometheus-2.1.0.linux-amd64.tar.gz’100%[===========================================================================================================================================>] 25,271,154 6.34MB/s in 3.7s 2019-03-10 21:58:00 (6.55 MB/s) - ‘prometheus-2.1.0.linux-amd64.tar.gz’ saved [25271154/25271154]
# 解压prometheus-2.1.0.linux-amd64.tar.gz
[root@artisan ~]# tar -xvzf prometheus-2.1.0.linux-amd64.tar.gz
prometheus-2.1.0.linux-amd64/
prometheus-2.1.0.linux-amd64/consoles/
prometheus-2.1.0.linux-amd64/consoles/index.html.example
prometheus-2.1.0.linux-amd64/consoles/node-cpu.html
prometheus-2.1.0.linux-amd64/consoles/node-disk.html
prometheus-2.1.0.linux-amd64/consoles/node-overview.html
prometheus-2.1.0.linux-amd64/consoles/node.html
prometheus-2.1.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.1.0.linux-amd64/consoles/prometheus.html
prometheus-2.1.0.linux-amd64/console_libraries/
prometheus-2.1.0.linux-amd64/console_libraries/menu.lib
prometheus-2.1.0.linux-amd64/console_libraries/prom.lib
prometheus-2.1.0.linux-amd64/prometheus.yml
prometheus-2.1.0.linux-amd64/LICENSE
prometheus-2.1.0.linux-amd64/NOTICE
prometheus-2.1.0.linux-amd64/prometheus
prometheus-2.1.0.linux-amd64/promtool
# 为了方便使用,给解压后的目录 建个软连接
[root@artisan ~]# ln -s prometheus-2.1.0.linux-amd64 prometheus
通过指定配置文件prometheus.yml启动Prometheus
配置文件官方说明: https://prometheus.io/docs/prometheus/latest/configuration/configuration/
默认情况下,Prometheus会监控自己本身。
# 后台运行 &
[root@artisan prometheus]# ./prometheus --config.file=prometheus.yml &
[1] 9015
[root@artisan prometheus]# level=info ts=2019-03-10T15:06:43.257570596Z caller=main.go:225 msg="Starting Prometheus" version="(version=2.1.0, branch=HEAD, revision=85f23d82a045d103ea7f3c89a91fba4a93e6367a)"
level=info ts=2019-03-10T15:06:43.257669987Z caller=main.go:226 build_context="(go=go1.9.2, user=root@6e784304d3ff, date=20180119-12:01:23)"
level=info ts=2019-03-10T15:06:43.257704431Z caller=main.go:227 host_details="(Linux 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64 artisan (none))"
level=info ts=2019-03-10T15:06:43.257735315Z caller=main.go:228 fd_limits="(soft=1024, hard=4096)"
level=info ts=2019-03-10T15:06:43.263798112Z caller=main.go:499 msg="Starting TSDB ..."
level=info ts=2019-03-10T15:06:43.291174989Z caller=web.go:383 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-03-10T15:06:43.402481602Z caller=main.go:509 msg="TSDB started"
level=info ts=2019-03-10T15:06:43.402579292Z caller=main.go:585 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-03-10T15:06:43.404207598Z caller=main.go:486 msg="Server is ready to receive web requests."
level=info ts=2019-03-10T15:06:43.404378748Z caller=manager.go:59 component="scrape manager" msg="Starting scrape manager..."# 查看进程, 9015端口,刚才启动的时候也输出了这个端口
[root@artisan prometheus]# ps -ef|grep prometheus |grep -v grep
root 9015 7675 0 23:06 pts/0 00:00:00 ./prometheus --config.file=prometheus.yml
查看采集到的性能指标
访问 http://192.168.31.34:9090/metrics
太多了,真是没法看,还好有个弱弱的图形页面 (待会整合到Grafana 中就方便看了)
访问: http://192.168.31.34:9090/graph
选中某个指标,点击Execute . 超多指标可以查看 …
查看prometheus规则
查看监控对象
SpringBoot集成Prometheus
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.3.RELEASE</version><relativePath /> <!-- lookup parent from repository --></parent><groupId>com.artisan</groupId><artifactId>springbootPrometheusGrafana</artifactId><version>0.0.1-SNAPSHOT</version><name>springbootPrometheusGrafana</name><description>Artisan </description><properties><java.version>1.8</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional><scope>true</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
配置文件
spring: application:name: springbootPrometheusGrafanamanagement:endpoints:web:exposure:include: '*'metrics:tags:application: ${spring.application.name}
如果使用properties
spring.application.name=springbootPrometheusGrafana
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}
实例化MeterRegistryCustomizer
方便起见,我们就在启动类中实例化吧
package com.artisan;import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;import io.micrometer.core.instrument.MeterRegistry;@SpringBootApplication
public class SpringbootPrometheusGrafanaApplication {public static void main(String[] args) {SpringApplication.run(SpringbootPrometheusGrafanaApplication.class, args);}@BeanMeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {return (registry) -> registry.config().commonTags("application", applicationName);}}
打包,上传到服务器上
右键–Run As – Maven build ,输入 clean package
服务器上启动该jar即可
java -jar springbootPrometheusGrafana-0.0.1-SNAPSHOT.jar &
Prometheus 修改配置文件prometheus.yml 接入该工程
增加如下配置:
#SpringBoot应用配置- job_name: 'springbootPrometheusGrafana'scrape_interval: 5smetrics_path: '/actuator/prometheus'static_configs:- targets: ['192.168.31.34:8080']
重启Prometheus
[root@artisan prometheus]# ./prometheus --config.file=prometheus.yml &
访问 http://192.168.31.34:9090/targets
查看配置文件
服务自动发现
Grafana 组件
官网:https://grafana.com/
下载地址: https://grafana.com/grafana/download
入门:http://docs.grafana.org/guides/getting_started/
刚才也说了,Prometheus 的可视化功能比较弱,这里我们来接入Grafana 。
Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下六大特点:
展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;
通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;
过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。
下载 & 安装 & 启动Grafana
官网下载速度太慢,我这里就没有使用最新版本,而是从 http://cactifans.hi-www.com 下载了 grafana-5.4.2-1.x86_64.rpm的版本
# 下载
[root@artisan ~]# wget http://cactifans.hi-www.com/grafana/grafana-5.4.2-1.x86_64.rpm
--2019-03-10 23:44:28-- http://cactifans.hi-www.com/grafana/grafana-5.4.2-1.x86_64.rpm
Resolving cactifans.hi-www.com (cactifans.hi-www.com)... 222.186.135.67
Connecting to cactifans.hi-www.com (cactifans.hi-www.com)|222.186.135.67|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 54991977 (52M) [application/x-redhat-package-manager]
Saving to: ‘grafana-5.4.2-1.x86_64.rpm’100%[===========================================================================================================================================>] 54,991,977 5.20MB/s in 9.5s 2019-03-10 23:44:37 (5.51 MB/s) - ‘grafana-5.4.2-1.x86_64.rpm’ saved [54991977/54991977]# yum本地安装
[root@artisan ~]# yum localinstall grafana-5.4.2-1.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining grafana-5.4.2-1.x86_64.rpm: grafana-5.4.2-1.x86_64
Marking grafana-5.4.2-1.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package grafana.x86_64 0:5.4.2-1 will be installed
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
extras/7/x86_64/primary_db | 180 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 2.5 MB 00:00:00 Dependencies Resolved=====================================================================================================================================================================================Package Arch Version Repository Size
=====================================================================================================================================================================================
Installing:grafana x86_64 5.4.2-1 /grafana-5.4.2-1.x86_64 151 MTransaction Summary
=====================================================================================================================================================================================
Install 1 PackageTotal size: 151 M
Installed size: 151 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : grafana-5.4.2-1.x86_64 1/1
### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemdsudo /bin/systemctl daemon-reloadsudo /bin/systemctl enable grafana-server.service
### You can start grafana-server by executingsudo /bin/systemctl start grafana-server.service
POSTTRANS: Running scriptVerifying : grafana-5.4.2-1.x86_64 1/1 Installed:grafana.x86_64 0:5.4.2-1 Complete!# 启动
[root@artisan ~]# systemctl start grafana-server
# 设置为开机启动
[root@artisan ~]# systemctl enable grafana-server
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
# 查看进程
[root@artisan ~]# ps -ef|grep grafana-server |grep -v grep
grafana 9542 1 2 23:49 ? 00:00:00 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning
[root@artisan ~]#
配置文件 /etc/grafana/grafana.ini , 默认3000端口,按需修改
访问 http://192.168.31.34:3000/login
默认的用户名和密码为 admin/admin
Grafana 接入Prometheus 的数据
如何将 Prometheus 数据 添加到 Grafana 中,如下
Prometheus 官方指导 : https://prometheus.io/docs/visualization/grafana/
Step1 添加Prometheus 数据源
选择 Prometheus
Step2 设置相关信息
Step3 导入想要的dashboards
看板地址: https://grafana.com/dashboards
可筛选
https://grafana.com/dashboards/4701
导入
Spring Boot2.x-14 使用Prometheus + Grafana 实现可视化的监控相关推荐
- 使用Prometheus+grafana打造高逼格监控平台
前言: 笔者看来, 监控不应该只是监控,除了及时有效的报警,更应该"好看",因为视觉上的感受更能给我们直观的感受,更能从绚丽的走势中发现异常, 如果你觉得监控就应该像老牌监控nag ...
- 视频教程-Prometheus+Grafana搭建全方位的监控告警系统-Linux
Prometheus+Grafana搭建全方位的监控告警系统 高级运维工程师.资深DevOps工程师,精通kubernetes容器编排工具,熟练使用linux操作系统,多年线上线下教学经验 韩先超 ¥ ...
- (四) prometheus + grafana + alertmanager 配置Kafka监控
安装请看https://blog.51cto.com/liuqs/2027365 ,最好是对应的版本组件,否则可能会有差别. (一)prometheus + grafana + alertmanage ...
- 3.Prometheus + Grafana实现可视化、告警
3.Prometheus + Grafana实现可视化.告警 3.1.什么是Grafana 3.2.快速入门 3.3.Grafana的下载 3.4.启动grafana 3.5.配置数据源 3.6.配置 ...
- 搭建Prometheus+Grafana的云平台监控系统
1.1 Prometheus和Grafana概述 1.1.1 Prometheus概述 Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由Soun ...
- JMeter+InfluxDB+Grafana实现可视化实时监控
本文我们将介绍如何使用JMeter+InfluxDB+Grafana打造可视化实时监控. 目录 一.简介 概述 简单介绍实现原理 二.indluxdb安装和部署 1.indluxdb下载 2.修改in ...
- Prometheus+Grafana 搭建全方位的监控告警系统
一.Prometheus介绍 Prometheus是一个最初在SoundCloud上构建的监控系统.自2012年成为社区开源项目,拥有非常活跃的开发人员和用户社区.为强调开源及独立维护,Prometh ...
- SpringBoot + Prometheus + Grafana 打造可视化监控一条龙!
1.背景 SpringBoot的应用监控方案比较多,SpringBoot+Prometheus+Grafana是目前比较常用的方案之一.它们三者之间的关系大概如下图: 关系图 2.开发SpringBo ...
- Windows 搭建Prometheus + Grafana + Jmeter可视化监控平台
1.安装包下载 Prometheus 下载地址:Download | Prometheus windows_exporter下载:Releases · prometheus-community/win ...
最新文章
- 《关系营销2.0——社交网络时代的营销之道》一T表示Technology(技术)
- 暑期大作战 第五天(第四天待补)
- 【转】 Android - LayoutInflate用法
- Resource interpreted as Script but transferred with MIME type text/plain:
- 魔兽世界阿拉索人数最多服务器,魔兽世界8.3哪个区人多_wow8.3服务器人数统计介绍_3DM网游...
- NBU计算机专业期末考试记录
- 生产服务器怎么dmp堆栈信息,如何根据程序崩溃时的DMP文件使用WinDbg查找调用堆栈...
- 小甲鱼OD学习第15-16讲
- 野生前端的数据结构基础练习(6)——集合
- ax.spines——matplotlib坐标轴设置
- setuptools setup()
- JAVA中List与Array之间互换
- 利用计算机提出算法分析问题,应用计算机计算不可积类型的积分算法分析
- jsp实验管理系统开题报告_MR教育燧光与广东实验中学关于MR化学课程开题报告研讨会顺利完成...
- 用GIF图片来告诉大家程序猿的真实生活
- 幻想西游php源码,如何搭建幻想西游服务器
- java写的网络版斗地主_JAVA网络版斗地主游戏
- SMOTE算法(处理非平衡数据)
- Hive 取非 Group by 字段数据的方法
- uni-app学习心得和填坑,关于uni-app 打包h5 页面的坑
热门文章
- php中使用json做api,JSONAPI在PHP中的应用
- bigqury 认证
- python3数字全排列怎么搞_python3实现字符串的全排列的方法(无重复字符)
- 无源定位之时差估计的精确时差估计算法(ETDE)及MATLAB实现程序
- 27. Leetcode 92. 反转链表 II (链表-反转链表)
- 路径调度问题(CVRP)后续之如何在MATLAB中安装YALMIP及CPLEX包
- 主成分分析 PCA算法
- php ldap 创建用户,PHP LDAP获取作为组成员的成员的用户详细信息
- QT关于全局变量的申请以及使用,所有class可用同一个变量
- Python编程基础:第七节 字符串切片String Slicing