配置准备
插件地址:
https://grafana.com/plugins
仪表盘地址:
https://grafana.com/dashboards
1、查找方法
搜索mysql、redis,获取对应的仪表盘id
2、配置方法
grafana中import仪表盘,输入对应组件的仪表盘id,点击Load,即可
仪表盘在线ID:
Prometheus 2.0 Overview = 3662
Mysql - Prometheus = 6239
Redis Dashboard = 10819
Node Exporter 0.16 for Prometheus = 9894
JVM Dashboard = 4701
一、安装go
1、解压
tar -zxvf go1.17.2.linux-amd64.tar.gz
2、配置环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
3、查看go版本
go version
二、prometheus
1、下载
wget https://github.com/prometheus/prometheus/releases/download/v2.30.1/prometheus-2.30.1.linux-amd64.tar.gz
2、解压
tar -zxvf prometheus-2.30.1.tar.gz
3、启动
./prometheus --config.file=prometheus.yml &
4、访问
http://****:9090/
三、grafana
1、安装
rpm -ivh --nodeps grafana-5.4.2-1.x86_64.rpm
2、启动
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
sudo /bin/systemctl start grafana-server.service
重启:service grafana-server restart
3、访问
http://****:3000/login
admin/admin
四、监控linux机器
1、下载解压
https://github.com/prometheus/node_exporter
2、启动
/usr/local/node_exporter/node_exporter &
3、配置
vim /usr/local/Prometheus/prometheus.yml
- job_name: 'Prometheus'
static_configs:
- targets: ['192.168.0.102:9100']
labels:
instance: Prometheus
4、重启prometheus
五、开启面板Dashboard
1、导入Dashboard json
node-exporter_rev5.json
2、导入插件
piechart
grafana的默认插件目录是/var/lib/grafana/plugins,可以将下载好的插件解压到这个目录,重启grafana即可
service grafana-server restart
/usr/sbin/grafana-cli plugins ls #查看已安装插件
六、监控Mysql(本地数据库)
1、下载解压
https://github.com/prometheus/mysqld_exporter
2、启动
配置RDS数据库连接,当前目录创建my.cnf
[client]
user=
password=
port=
host=
/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address=":9101" &
/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf="conf/my.cnf" --web.listen-address=":9101" &
3、配置
vim /usr/local/Prometheus/prometheus.yml
- job_name: 'Prometheus'
static_configs:
- targets: ['192.168.0.102:9101']
labels:
instance: Prometheus
4、重启prometheus
七、监控阿里云Redis
1、下载解压
https://github.com/aylei/aliyun-exporter
2、启动
/usr/local/redis_exporter/redis_exporter -redis.addr *:6379 -redis.password * --web.listen-address=":9102" &
3、配置
vim /usr/local/Prometheus/prometheus.yml
- job_name: 'redis'
static_configs:
- targets: ['192.168.0.102:9102']
labels:
instance: Redis
4、重启prometheus
八、监控nacos
1、打开nacos监控配置
application.properties
management.endpoints.web.exposure.include=*
2、配置prometheus
- job_name: 'nacos'
metrics_path: '/nacos/actuator/prometheus'
static_configs:
- targets: ['172.29.251.233:8858','172.29.251.234:8858','172.29.251.235:8858']
九、监控微服务
1、增加监控依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
2、打开采集配置
management:
endpoints:
web:
exposure:
include: '*'
metrics:
tags:
application: ${spring.application.name}
3、增加启动注册
启动类中添加
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName);
}
4、配置job(user-admin服务)
- job_name: 'user-admin'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['172.29.251.233:10000','172.29.251.234:10000','172.29.251.235:10000']
十、监控alertManager
1、下载解压
https://github.com/prometheus/alertmanager
2、启动
/usr/local/alertmanager/alertmanager &
3、配置
vim /usr/local/alertmanager/alertmanager.yml
4、重启prometheus