kubernetes-prometheus

部署

监控部署及基本使用

创建一个无终端的用户,之后的服务启动用户都为"prometheus"

useradd -M -s /sbin/nologin prometheus
prometheus部署
wget https://github.com/prometheus/prometheus/releases/download/v2.34.0/prometheus-2.34.0.linux-amd64.tar.gz

tar zxvf prometheus-2.34.0.linux-amd64.tar.gz -C /tmp/

mkdir -p /home/apps/ && mv /tmp/prometheus-2.34.0.linux-amd64 /home/apps/prometheus

chown -R prometheus.prometheus /home/apps/prometheus
node_exporter部署
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz

tar zxvf node_exporter-1.3.1.linux-amd64.tar.gz -C /tmp/

mv /tmp/node_exporter-1.3.1.linux-amd64/node_exporter /usr/local/bin/node_exporter && chmod +x /usr/local/bin/node_exporter

创建systemctl服务,方便管理

cat > /etc/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
prometheus配置监控项及基本的promQL语句

prometheus.yaml参数配置含义

参数含义
global此片段指定的是 prometheus 的全局配置, 比如采集间隔,抓取超时时间等。 rule_files: 此片段指定报警规则文件, prometheus 根据这些规则信息,会推送报警信息到 alertmanager 中。
scrape_configs此片段指定抓取配置,prometheus 的数据采集通过此片段配置。
alerting此片段指定报警配置, 这里主要是指定 prometheus 将报警规则推送到指定的 alertmanager 实例地址。
remote_write指定后端的存储的写入 api 地址。
remote_read指定后端的存储的读取 api 地址。

prometheus.yaml中scrapy_config片段参数含义

参数含义
scrape_interval抓取间隔,默认继承 global 值。 scrape_timeout: 抓取超时时间,默认继承 global 值。 metric_path
static_configs静态指定服务 job。 relabel_config: relabel 设置

配置prometheus获取node_exporter指标

[root@localhost prometheus]# pwd
/usr/local/prometheus
[root@localhost prometheus]# vim prometheus.yml 
scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      # 我这里使用的是两个实例,在这两个实例中都部署了node_exporter
      - targets: ["192.168.1.47:9100","192.168.1.48:9100"]
# 重启prometheus
[root@localhost prometheus]# systemctl restart prometheus

可以看到已经监控的一个指标,其中有两个链接
在这里插入图片描述
简单的来使用一下PromQL
查询指定 mertic_name
在这里插入图片描述
带标签查询
在这里插入图片描述
多标签查询
在这里插入图片描述
计算CPU使用率
在这里插入图片描述
计算内存使用率
在这里插入图片描述
计算磁盘使用率
在这里插入图片描述
机器上行带宽
在这里插入图片描述
机器下行带宽
在这里插入图片描述

prometheus通过grafana展示
# 下载安装grafana
wget https://dl.grafana.com/oss/release/grafana-8.4.3-1.x86_64.rpm
yum -y install grafana-8.4.3-1.x86_64.rpm
# 默认端口是3000,可以通过修改配置文件改为自己想要的端口
vim /etc/grafana/grafana.ini
# 启动grafana
systemctl start grafana-server

默认账号密码是admin/admin
在这里插入图片描述
添加一个数据源,prometheus中自己集成了TSDB,所以grafana是直接集成了prometheus的
在这里插入图片描述
选择prometheus后直接填入下面内容即可
在这里插入图片描述
绿色的data source即成功
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
我导入的是8919,效果如下
在这里插入图片描述
可以看看只改模板中的参数设置
在这里插入图片描述
在这里插入图片描述
如果要修改某一个参数,可以使用如下方式
在这里插入图片描述
在这里插入图片描述

告警模块alertmanager部署

1、下载部署alertmanager

wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz

tar zxvf alertmanager-0.24.0.linux-amd64.tar.gz -C /tmp/
mv /tmp/alertmanager-0.24.0.linux-amd64 /home/apps/alertmanager
cd /home/apps/alertmanager
./amtool check-config alertmanager.yml

2、将该服务加入systemd

cat > /etc/systemd/system/alertmanager.service << EOF
[Unit]
Description=alertmanager.service
 
[Service]
ExecStart=/home/apps/alertmanager/alertmanager --config.file=/home/apps/alertmanager/alertmanager.yml 
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
配置prometheus警告
配置一个简单的告警规则

修改altermanager配置

[root@localhost prometheus]# cat /usr/local/alertmanager/alertmanager.yml
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.163.com:25'  # 邮箱smtp服务器代理
  smtp_from: '123456@163.com'  # 邮件接收人员
  smtp_auth_username: '123456@163.com'  # 邮件发送者
  smtp_auth_password: 'NDKEUHFOLGNKF'  # 邮件发送者密码
  smtp_require_tls: false  # 配置不使用加密认证

route:
  receiver: 'default_receiver'   # 配置默认路由策略
  group_wait: 1s     # 最初告警通知等待时间,为了方便测试所以试用报告时间较短
  group_by: ['alertname']  # 根据标签进行分组
  group_interval: 10s  # 告警新通知等待时间,为了方便测试所以试用报告时间较短
  repeat_interval: 1m # 重复告警等待时间,为了方便测试所以试用报告时间较短

receivers:  # 将告警发送给谁
- name: 'default_receiver'   # 与如上的default_reveiver匹配
  email_configs:    # 邮件告警配置
  - to: '123456789@qq.com'
    headers: { Subject: "XXX报警邮件"}
    send_resolved: true  # 改参数表示恢复后会在发一次邮件
inhibit_rules:   # 告警抑制规则
- source_match:
    severity: 'critical'  # 当收到同一台机器发送的critical时候,屏蔽掉warning类型的告警
  target_match:
    severity: 'warning'
  equal: ['alertname', 'dev', 'instance']  # 根据这些标签来定义抑制

重启altermanager,使其生效

systemctl restart alertmanager

修改prometheus配置文件

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
           - 192.168.1.47:9093  # altermanager地址

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "rules/*.yml"  # 引用当前文件下中rules目录下的所有yml配置

编写一个简单的告警规则

[root@localhost prometheus]# vim rules/host_monitor.yml
groups:
- name: node-up
  rules:
  - alert: node-up
    # 使用的是up这个函数,可以查看下图所知up代表的含义
    expr: up{job="node_exporter"} == 0
    for: 15s
    labels:
      severity: 1
      team: node
    annotations:
      summary: "{{$labels.instance}}Instance has been down for more than 15s"

在这里插入图片描述
规则文件配置详解

参数含义
alert告警规则的名称。
expr基于 PromQL 表达式告警触发条件,用于计算是否有时间序列满足该条件。
for评估等待时间,可选参数。用于表示只有当触发条件持续一段时间后才发送告警。在 等待期间新产生告警的状态为 pending。
labels自定义标签,允许用户指定要附加到告警上的一组附加标签。
annotations用于指定一组附加信息,比如用于描述告警详细信息的文字等,annotations 的内容在告警产生时会一同作为参数发送到 Alertmanager。
summary
description
summary描述告警的概要信息
description 用于描述告警的详细信息。
同时 Alertmanager 的 UI 也会根据这两个标签值,显示告警信息。

重启prometheus,查看Alerts,可以看到已经有一个告警监控项了
在这里插入图片描述
停掉某一个节点的node_exporter,查看节点状态
在这里插入图片描述
告警已经变为了pending
在这里插入图片描述
一段时间后变为了FIRING
在这里插入图片描述
查看邮件
在这里插入图片描述
在这里插入图片描述
恢复节点后查看状态及邮件,都变为正常了
在这里插入图片描述

优化告警模板

[root@localhost alertmanager]# pwd
/usr/local/alertmanager
[root@localhost alertmanager]# vim email.tmp
{{ define "email.to.html" }}
{{ if gt (len .Alerts.Firing) 0 }}{{ range .Alerts }}
@告警
告警程序: prometheus_alert <br>
告警级别: {{ .Labels.severity }}<br>
告警类型: {{ .Labels.alertname }} <br>
故障主机: {{ .Labels.instance }} <br>
告警主题: {{ .Annotations.summary }} <br>
告警详情: {{ .Annotations.description }} <br>
触发时间: {{ .StartsAt }} <br>
{{ end }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}{{ range .Alerts }}
@恢复:
告警主机:{{ .Labels.instance }} <br>
告警主题:{{ .Annotations.summary }} <br>
恢复时间: {{ .EndsAt }} <br>
{{ end }}
{{ end }}
{{ end }}

[root@localhost alertmanager]# vim alertmanager.yml
# 加入使用模板方式发送的参数
templates:
  - '/usr/local/alertmanager/email.tmpl'

receivers:  # 将告警发送给谁
- name: 'default_receiver'   # 与如上的default_reveiver匹配
  email_configs:    # 邮件告警配置
  - to: '111111111@qq.com'
    html: '{{ template "email.to.html" . }}' # 使用模板的方式发送
    headers: { Subject: "xa项目报警邮件"}
    send_resolved: true
   
# 检测语法是否正确
[root@localhost alertmanager]# ./amtool check-config alertmanager.yml
Checking 'alertmanager.yml'  SUCCESS
Found:
 - global config
 - route
 - 1 inhibit rules
 - 1 receivers
 - 1 templates
  SUCCESS
# 重启服务
[root@localhost alertmanager]# systemctl restart alertmanager
# 模拟节点宕掉
[root@localhost alertmanager]# systemctl stop node_exporter

查看状态及邮件发送情况,这样子看着是不是比之前好多了呢
在这里插入图片描述

Alert状态说明

在这里插入图片描述

状态说明 Prometheus Alert 告警状态有三种状态:Inactive、Pending、Firing。

状态含义
Inactive非活动状态,表示正在监控,但是还未有任何警报触发。
Pending表示这个警报必须被触发。由于警报可以被分组、压抑/抑制或静默/静音,所 以等待验证,一旦所有的验证都通过,则将转到 Firing 状态。
Firing将警报发送到 AlertManager,它将按照配置将警报的发送给所有接收者。一旦警 报解除,则将状态转到 Inactive,如此循环
实现企业微信报警

企业微信获取连接信息
在这里插入图片描述

参数含义
corp_id企业微信账号唯一 ID, 可以在我的企业中查看。
to_party需要发送的组(部门)。
agent_id第三方企业应用的 ID
api_secret第三方企业应用的密钥
[root@localhost alertmanager]# vim alertmanager.yml
templates:
  - '/usr/local/alertmanager/email.tmpl'
route:
  group_by: ['alertname'] 
  group_wait: 10s 
  group_interval: 10s 
  repeat_interval: 1h 
  receiver: 'wechat'

receivers:
- name: 'wechat'
  wechat_configs:
  - corp_id: 'wwf4ee8ede83b63a1a'
    to_party: '1'
    agent_id: '1000003'
    api_secret: 'LbVzYRczEJMY2rq0c8I8ZjASPfCtzvl3f7zfiuyVKSc' send_resolved: true
    message: '{{ template "wechat.tmpl" . }}'
实现钉钉报警

钉钉那到webhook链接
在这里插入图片描述
在这里插入图片描述
点击创建即可那倒webhook,IP需要获取你服务器的出口的公网IP
在这里插入图片描述

想要实现钉钉报警功能,需要插件的支持,下载

[root@localhost dingding]# pwd
/usr/local/prometheus/dingding
[root@localhost dingding]# tar zxf prometheus-webhook-dingtalk-2.0.0.linux-amd64.tar.gz
[root@localhost dingding]# cd prometheus-webhook-dingtalk-2.0.0.linux-amd64

修改钉钉的配置文件

[root@localhost prometheus-webhook-dingtalk-2.0.0.linux-amd64]# cp config.example.yml config.yml
[root@localhost prometheus-webhook-dingtalk-2.0.0.linux-amd64]# vim config.yml 
timeout: 5s

templates:
  - ./dingding.tmpl

targets:
  webhook1:
    url: https://oapi.dingtalk.com/robot/send?access_token=自己钉钉的token

编写钉钉的告警模板(该模板网上荡的,可以根据自己的需求进行修改)

[root@localhost prometheus-webhook-dingtalk-2.0.0.linux-amd64]# vim dingding.tmpl 
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver }}{{ end }}

{{ define "__text_alert_list" }}{{ range . }}
告警程序:prometheus_alert
告警级别:{{ .Labels.severity }}
告警类型:{{ .Labels.alertname }}
主机: {{ .Labels.instance }}
命名空间: {{ .Labels.namespace }}
Pod: {{ .Labels.pod }}
告警主题: {{ .Annotations.summary }}
告警描叙: {{ .Annotations.description }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
------------------------

{{ end }}{{ end }}

{{ define "__text_resolve_list" }}{{ range .  }}
恢复程序:{{ .Labels.alertname }}
主机: {{ .Labels.instance }}
恢复描叙: {{ .Annotations.description }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
------------------------
{{ end }}{{ end }}


{{ define "ding.link.title" }}{{ template "__subject" . }}{{ end }}
{{ define "ding.link.content" }}#### \[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}\] **[{{ index .GroupLabels "alertname" }}]({{ template "__alertmanagerURL" . }})**
{{ if gt (len .Alerts.Firing) 0 -}}
![警报 图标](https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3626076420,1196179712&fm=15&gp=0.jpg)

**====侦测到故障====**

{{ template "__text_alert_list" .Alerts.Firing }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}
恢复列表:
{{ template "__text_resolve_list" .Alerts.Resolved }}
{{- end }}
{{- end }}

启动插件

# 启动后可以通过输出信息看到应用的配置模板和生成的url地址,&放入后台启动
[root@localhost prometheus-webhook-dingtalk-2.0.0.linux-amd64]# ./prometheus-webhook-dingtalk &
level=info ts=2022-03-21T13:23:07.380Z caller=main.go:60 msg="Starting prometheus-webhook-dingtalk" version="(version=2.0.0, branch=HEAD, revision=a848e5dc412d1808487b02561be587096d34fdb6)"
level=info ts=2022-03-21T13:23:07.380Z caller=main.go:61 msg="Build context" (gogo1.16.7,userroot@234305329b1e,date20210819-10:19:08)=(MISSING)
level=info ts=2022-03-21T13:23:07.381Z caller=coordinator.go:83 component=configuration file=config.yml msg="Loading configuration file"
level=info ts=2022-03-21T13:23:07.382Z caller=coordinator.go:91 component=configuration file=config.yml msg="Completed loading of configuration file"
level=info ts=2022-03-21T13:23:07.382Z caller=main.go:98 component=configuration msg="Loading templates" templates=./dingding.tmpl
ts=2022-03-21T13:23:07.388Z caller=main.go:114 component=configuration msg="Webhook urls for prometheus alertmanager" urls=http://localhost:8060/dingtalk/webhook1/send
level=info ts=2022-03-21T13:23:07.388Z caller=web.go:210 component=web msg="Start listening for connections" address=:8060


altermanager修改配置

[root@localhost alertmanager]# vim alertmanager.yml
# 替换一下两段即可,其他的不用变
route:
  receiver: 'dingding'
  group_wait: 1s
  group_by: ['alertname']
  group_interval: 10s
  repeat_interval: 1m

receivers:  
- name: 'dingding'   
  webhook_configs:
  - url: 'http://192.168.1.47:8060/dingtalk/webhook1/send'
    send_resolved: true
# 重启altermanager并停止node_exporter测试
[root@localhost alertmanager]# systemctl restart alertmanager
[root@localhost alertmanager]# systemctl stop node_exporter

可以看到重启和停止都会发出告警
在这里插入图片描述
在这里插入图片描述

告警的标签、路由、分组

定义告警等级

[root@localhost alertmanager]# vim alertmanager.yml
global:
  resolve_timeout: 5m
  smtp_smarthost: 'smtp.163.com:25'  # 邮箱smtp服务器代理
  smtp_from: 'xxxxxx@163.com'  # 邮件接收人员
  smtp_auth_username: 'xxxxxx@163.com'  # 邮件发送者
  smtp_auth_password: 'DASJKDNCKAJNSD'  # 邮件发送者密码
  smtp_require_tls: false

route:
  group_wait: 1s
  group_by: ['alertname']  
  group_interval: 10s  
  repeat_interval: 1m
  # 必须有一个基础的路由
  receiver: 'email'
  routes:
  # severity告警级别在下面的"inhibit_rules"模块有做设置
  - match:
      severity: critical
    receiver: 'leader'
    continue: true
  - match_re:
      severity: ^(warning|critical)$
    receiver: 'devops'
    continue: true 

receivers:  # 将告警发送给谁
- name: 'leader'   # 与如上的receiver中的'leader'匹配,当匹配到critical的告警等级时,就会发往以下地址
  webhook_configs:
  - url: 'http://192.168.1.47:8060/dingtalk/webhook1/send' # 钉钉webhook插件的地址
    send_resolved: true
- name: 'devops'   # 与如上的路由分组匹配的devops,匹配到warning和都会发往以下地址
  email_configs:    # 邮件告警配置
  - to: '111111111@qq.com'
    html: '{{ template "email.to.html" . }}' # 使用模板的方式发送
    headers: { Subject: "报警邮件"}
    send_resolved: true
- name: 'email'
  email_configs:    # 邮件告警配置
  - to: '111111111@qq.com'
    html: '{{ template "email.to.html" . }}' # 使用模板的方式发送
    headers: { Subject: "报警邮件"}
    send_resolved: true

templates:
 - '/usr/local/alertmanager/*.tmpl'
inhibit_rules:   # 告警抑制规则
- source_match:
    severity: 'critical'  # 当收到同一台机器发送的critical时候,屏蔽掉warning类型的告警
  target_match:
    severity: 'warning'
  equal: ['alertname']  # 根据这些标签来定义抑制

创建告警规则

# 创建告警规则,一个CPU的和一个节点的
[root@localhost alertmanager]# cat /usr/local/prometheus/rules/cpu.yml 
groups:
- name: cpu_load
  rules:
  - alert: cpu_load
    expr: node_load5 / (count without (cpu, mode) (node_cpu_seconds_total{mode="system"})) > 0 # 因为他的值正常都会是0以上,所以为了方便测试,设置大于0就报警
    for: 15s 
    labels:
      severity: 'warning'
      team: cpu
    annotations:
      summary: "CPU load (5m) avg is hige\n VALUE = {{ $value }} \n LABELS: {{ $labels }}"
[root@localhost alertmanager]# cat /usr/local/prometheus/rules/host_monitor.yml 
groups:
- name: node-up
  rules:
  - alert: node-up
    expr: up == 0 
    for: 15s 
    labels:
      severity: critical
      team: node 
    annotations:
      summary: "{{$labels.instance}}Instance has been down for more than 15s"
# 检查文件配置
[root@localhost alertmanager]# ../prometheus/promtool check config ../prometheus/prometheus.yml 
Checking ../prometheus/prometheus.yml
  SUCCESS: 2 rule files found
 SUCCESS: ../prometheus/prometheus.yml is valid prometheus config file syntax

Checking ../prometheus/rules/cpu.yml
  SUCCESS: 1 rules found

Checking ../prometheus/rules/host_monitor.yml
  SUCCESS: 1 rules found

# 重启服务
[root@localhost alertmanager]# systemctl restart alertmanager
[root@localhost alertmanager]# systemctl restart prometheus

为了方便测试,我将配置修改为了>0就会发出警告
在这里插入图片描述
可以看到钉钉进行了警告,但是QQ是没有收到的
在这里插入图片描述
现在把node_exporter也停掉触发critical,看看QQ会不会收到
可以看到QQ也收到了,而且钉钉也能正常接收,时间有问题是一个是因为模板的问题,修改下模板就好了,一个就是机器没有进行时间同步
在这里插入图片描述
在这里插入图片描述

MySQL监控及告警配置

MySQL监控

要去监控MySQL需要下载mysql_exporter
安装数据库的步骤省略。。。

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar zxf mysqld_exporter-0.14.0.linux-amd64.tar.gz 
mv mysqld_exporter-0.14.0.linux-amd64 /usr/local/mysqld_exporter

通过systemd管理

vim /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=mysql Monitoring System

[Service]
# 配置的是监控项,可以使用./mysqld_exporter --help查看有哪些监控项
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
          --collect.info_schema.processlist \
          --collect.info_schema.innodb_tablespaces \
          --collect.info_schema.innodb_metrics \
          --collect.perf_schema.tableiowaits \
          --collect.perf_schema.indexiowaits \
          --collect.perf_schema.tablelocks \
          --collect.engine_innodb_status \
          --collect.perf_schema.file_events \
          --collect.binlog_size \
          --collect.info_schema.clientstats \
          --collect.perf_schema.eventswaits \
          --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install] 
WantedBy=multi-user.target

# mysql创建授权用户
mysql> grant all privileges on *.* to 'ihs_admin'@'%'  identified by 'Jhxt@123';
# 编写mysqld_exporter的MySQL授权信息
[root@localhost ~]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
host=192.168.1.47
user=ihs_admin
password=Jhxt@123
# 启动
[root@localhost system]# systemctl start mysqld_exporter

# 修改prometheus配置文件,进行对MySQL的监控
scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["192.168.1.47:9100","192.168.1.48:9100"]
  - job_name: "mysqld_exporter"
    static_configs:
      - targets: ["192.168.1.47:9104"]
[root@localhost prometheus]# systemctl restart prometheus

已经进行了监控
在这里插入图片描述
使用grafana这次用的模板是7362
在这里插入图片描述

MySQL主从监控
# 47和48做主从,其余的mysqld_exporter配置都一样
[root@localhost system]# scp mysqld_exporter.service 192.168.1.48:/etc/systemd/system/

[root@localhost local]# scp -r /usr/local/mysqld_exporter/ 192.168.1.48:/usr/local/
# 修改48的mysqld_exporter配置
[root@localhost mysql]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
host=192.168.1.48
user=ihs_admin
password=Jhxt@123

# 启动服务
[root@localhost mysqld_exporter]# systemctl restart mysqld_exporter 

# 查看端口
[root@localhost mysqld_exporter]# netstat -antp
tcp6       0      0 :::9104                 :::*                    LISTEN      14708/mysqld_export 

# 47的prometheus配置监听,并重启服务
scrape_configs:
  - job_name: "node_exporter"
    static_configs:
      - targets: ["192.168.1.47:9100","192.168.1.48:9100"]
  - job_name: "mysqld_exporter"
    static_configs:
      - targets: ["192.168.1.47:9104","192.168.1.48:9104"]

[root@localhost prometheus]# systemctl daemon-reload
[root@localhost prometheus]# systemctl restart prometheus

在这里插入图片描述
这里用的模板是7371,查看的是48的数据信息,因为47是没有IO和SQL线程的
在这里插入图片描述

配置MySQL警告
# 编辑prometheus监控指标
[root@docker-3 rules]# cat /usr/local/prometheus/rules/mysql.yml 
groups:
- name: MySQL-rules
  rules:
  - alert: MySQL Status
    expr: up{job="mysqld_exporter"} == 0 
    for: 5s 
    labels:
      severity: critical 
    annotations:
      summary: "{{$labels.instance}}: MySQL has stop " 
      description: "MySQL 数据库挂了,请检查"
  - alert: MySQL Slave IO Thread Status
    expr: mysql_slave_status_slave_io_running == 0 
    for: 5s
    labels:
      severity: warning 
    annotations:
      summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop "     
      description: "检测 MySQL 主从 IO 线程运行状态"
  - alert: MySQL Slave SQL Thread Status
    expr: mysql_slave_status_slave_sql_running == 0 
    for: 5s
    labels:
      severity: warning 
    annotations:
      summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop "     
      description: "检测 MySQL 主从 SQL 线程运行状态"

# 测试的话可以停掉从库IO线程或者SQL线程进行测试
mysql> stop slave sql_thread;
Redis警告

持续更新中。。。。。。

prometheus使用方式

看官网去吧

整理

整理一下部署及应用prometheus的步骤
在k8s中集成了一些promethues的监控指标和接口,所以在k8s集群方面,prometheus监控是一种极好的选择方案
架构如下所示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值