
流逸穿风
V1
2022/05/17阅读:49主题:橙心
监控平台部署说明
监控平台安装
安装docker
-
安装docker依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2
-
设置镜像仓库
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
-
安装docker社区版
yum install docker-ce docker-ce-cli containerd.io
安装grafana相关软件
相关软件安装成功后,可访问对应地址确认是否安装成功
-
拉取docker镜像
docker pull grafana/grafana
docker pull prom/prometheus
docker pull prom/mysqld-exporter
-
启动grafana
docker run -d --name grafana1 \
--restart=always \
-p 3000:3000 grafana/grafana
-
启动prometheus
docker run -p 9090:9090 --name prometheus \
--restart=always \
-v /home/docker/grafana/prometheus.yml:/etc/prometheus/prometheus.yml \
-d prom/prometheus
-
启动mysqld-exporter
docker run -itd --name mysql-exporter -p 9104:9104 \
--restart=always \
-e DATA_SOURCE_NAME="mysql用户名:mysql密码@(mysql的ip地址:8336)/" \
prom/mysqld-exporter
grafana 初始化配置
初始用户名admin,密码admin,修改密码后登录系统
-
添加数据源
点击“设置”-》“Data sources”-》“add data sources”-》“选择prometheus”
-
创建文件夹
文件夹的用于后续添加报警规则时使用

-
导入看板

监控springboot项目
监控SpringBoot应用需要依靠actuator及micrometer,通过暴露actuator的端点,Prometheus可以定时获取并存储指标信息。
-
修改项目的pom.xml文件,添加actuator及micrometer依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 集成micrometer,将监控数据存储到prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
-
修改应用配置文件application.yml,通过actuator暴露监控端口/actuator/prometheus
management:
endpoints:
web:
exposure:
# 暴露端点`/actuator/prometheus`
include: 'prometheus'
metrics:
tags:
application: ${spring.application.name}
-
修改Prometheus的配置文件prometheus.yml,创建一个任务定时扫描actuator暴露的指标信息
global:
scrape_interval: 5s
scrape_configs:
- job_name: '省监狱局和戒毒局MYSQL监控'
static_configs:
- targets: ['192.168.0.64:9104']
# 采集任务名称
- job_name: '省监狱局和戒毒局-前置服务'
scheme: https
# 采集时间间隔
scrape_interval: 15s
# 采集超时时间
scrape_timeout: 10s
# 采集数据路径
metrics_path: '/actuator/smartParkCFrtSvr'
# 采集服务的地址
static_configs:
- targets: ['sjyj.hxsmart.com']
- job_name: '省监狱局和戒毒局-管理系统'
scheme: https
# 采集时间间隔
scrape_interval: 15s
# 采集超时时间
scrape_timeout: 10s
# 采集数据路径
metrics_path: '/actuator/smartParkCMis'
# 采集服务的地址
static_configs:
- targets: ['sjyj.hxsmart.com']
- job_name: '省监狱局和戒毒局-门禁访客'
scheme: https
# 采集时间间隔
scrape_interval: 15s
# 采集超时时间
scrape_timeout: 10s
# 采集数据路径
metrics_path: '/actuator/accessCloudSvr'
# 采集服务的地址
static_configs:
- targets: ['sjyj.hxsmart.com']
-
我们可以通过Prometheus的可视化界面,来确定Prometheus是否能获取到指标信息

警告配置

-
修改邮箱


作者介绍

流逸穿风
V1