记一次利用grafana+prometheus实现服务器资源以及mysql数据库监控

3/3/2022 Linux数据库

监控界面
监控界面

首先我这其实就是利用了一个单独的Linux服务器来进行监控的,首先需要配置好mysql等服务.

给mysqld_exporter一个登录mysql的权限

mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO 'exporter'@'localhost' IDENTIFIED BY 'exporter123' WITH MAX_USER_CONNECTIONS 3; mysql> flush privileges;


`mysqld_exporter的GIthubhttps://github.com/prometheus/mysqld_exporter`

然后安装利用`http://pingfan.world/?p=179`这个教程

配置prometheus的话,在配置文件最后加上

```text
1
2
3
4
5
6
7
8
  • job_name: 'mysql' static_configs: - targets: ["localhost:9104"]

即可
Prometheus监控服务状态 
![Prometheus监控状态](https://oss.datehoer.com/blog/imgs/mLxKV1zSgOZfcUl.jpg "Prometheus监控状态")

然后就是grafana的模板,这个可以直接去他的官网找`https://grafana.com/grafana/dashboards/?search=mysql`我是感觉差不多,随便找了一个用
![granfana模板导入](https://oss.datehoer.com/blog/imgs/uqbZjpoextg1WD6.jpg "granfana模板导入")  
将模板的id或者url填进去就能够加载对应的模板了.

再就是有一个写的比较全的CSDN文档`https://blog.csdn.net/u014756339/article/details/107816038`可以参考一下

Prometheus中文文档:`https://yunlzheng.gitbook.io/prometheus-book/`
1
2
3
4
5
6
7
8
9
10
11