Prometheus详解

1、prometheus后台启动

 

复制代码
```bash
[root@VM-0-9-centos system]# cat /usr/lib/systemd/system/prometheusd.service 
[Unit]
Description=Prometheus

[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle  
Restart=on-failure

[Install]
WantedBy=multi-user.target

[root@VM-0-9-centos system]# systemctl daemon-reload
[root@VM-0-9-centos system]# systemctl start prometheusd
```
复制代码

 

2、node-exporter后台启动

复制代码
```bash
[root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# vim /usr/lib/systemd/system/node-exporter.service
[Unit]
Description=This is prometheus node exporter
After=node_exporter.service

[Service]
Type=simple
ExecStart=/usr/local/node_exporter-1.3.1.linux-amd64/node_exporter
ExecReload=/bin/kill -HUP 
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# systemctl daemon-reload 
[root@VM-0-9-centos node_exporter-1.3.1.linux-amd64]# systemctl start node-exporter.service 
```
复制代码

 

3、PromQL

 

复制代码
```bash
PromQL可以理解为MySQL中的SQL
```

#### 3.1、普通查询

```bash
prometheus_http_requests_total{code="200"}
```

#### 3.2、正则匹配

```bash
prometheus_http_requests_total{code=~"200|400"}
prometheus_http_requests_total{code!~"200"}
```

#### 3.3、算术计算

```bash
node_memory_MemTotal_bytes / 1024 / 1024 / 1024
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100
```

#### 3.4、函数

##### 3.4.1、求和函数sum

```bash
sum(prometheus_http_requests_total{code!="200"}) by (job)
```
复制代码

 

 

4、监控MySQL

 

复制代码
```bash
# 下载MySQL的源
[root@VM-0-3-centos ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
[root@VM-0-3-centos ~]# rpm -ivh mysql80-community-release-el7-5.noarch.rpm 
warning: mysql80-community-release-el7-5.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el7-5  ################################# [100%]
[root@VM-0-3-centos ~]# yum install mysql-community-server -y
# 启动
[root@VM-0-3-centos ~]# systemctl start mysqld

# 下载mysqld_exporter
[root@VM-0-3-centos ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

[root@VM-0-3-centos ~]# tar -xf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local/
[root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# ln -s /usr/local/mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter

[root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
user=root
password=Test123!

[root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# vim /usr/lib/systemd/system/mysqld-exporter.service
[Unit]
Description=Prometheus

[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf --web.listen-address=:9104
Restart=on-failure

[Install]
WantedBy=multi-user.target
[root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# systemctl daemon-reload
[root@VM-0-3-centos mysqld_exporter-0.13.0.linux-amd64]# systemctl restart mysqld-exporter.service
复制代码

 

posted @   Mipse  阅读(325)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示