prometheus 监控告警安装与设置

1、什么是Prometheus?
Prometheus (普罗米修斯)是由 SoundCloud开发的开源监控报警系统和时序列数据库 。

2、Prometheus的特点

  • 多维度数据模型。 灵活的查询语言。
  • 不依赖分布式存储,单个服务器节点是自主的。
  • 通过基于HTTP的pull方式采集时序数据。
  • 可以通过中间网关进行时序列数据推送。
  • 通过服务发现或者静态配置来发现目标服务对象。
  • 支持多种多样的图表和界面展示,比如Grafana等。

官网地址:

https://prometheus.io/

3、基本原理
Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。

4、架构图

在这里插入图片描述
在这里插入图片描述
5、安装prometheus
官网下载,解压即可使用

wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz

配置文件:

vi  prometheus.yml

启动prometheus

./prometheus &

prometheus 加到系统服务

# vi /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System

[Service]
ExecStart=/data/app/prometheus/prometheus --config.file=/data/app/prometheus/prometheus.yml --web.listen-address=:9080

[Install]
WantedBy=multi-user.target

** 6、promethus 监控MySQL**

1、安装mysqld_exporter
下载解压安装即可

官网 https://github.com/prometheus/mysqld_exporter

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

2、配置:

# vi /usr/local/mysqld_exporter/.my.cnf

[client]
port=3306
user=user_repel
password=password

3、启动:

./mysqld_exporter --config.my-cnf=.my.cnf

4、prometheus.yml的scrape_configs节点增加如下配置
之后重启prometheus

  - job_name: "mysql"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["127.0.0.1:9104"]

5、Grafana中MySQL的Dashboard ID

7362

** 7、安装grafana**

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.2.1.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-8.2.1.linux-amd64.tar.gz

启动

./bin/grafana-server -config conf/defaults.ini &

访问

http://localhost:300 
admin
admin

增加邮件smtp配置

enabled = true                   #默认是false
host = smtp.mxhichina.com:465    #smtp服务器地址
user = test@xxx.com              #你登录邮箱的账号
password = xxxxxxx               #你邮箱账号的密码
from_address = test@xxx.com      #发邮件的账号
from_name = Grafana              #自定义的名字
ehlo_identity = dashboard.example.com    #无关紧要的一个标示

8、监控elasticsearch
解压即完成安装。

#官网 https://github.com/prometheus-community/elasticsearch_exporter/releases

wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.2.1/elasticsearch_exporter-1.2.1.linux-amd64.tar.gz

启动

nohup ./elasticsearch_exporter --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots --es.timeout=10s --web.list
en-address=":9105" --web.telemetry-path="/metrics" --es.uri http://127.0.0.1:8607 &

prometheus.yml的scrape_configs节点增加如下配置
之后重启prometheus

- job_name: 'es_19'  
    static_configs:
    - targets: ['127.0.0.1:9105']

Grafana中elasticsearch的Dashboard ID

2322

9、监控redis
下载解压即安装。

https://github.com/oliver006/redis_exporter

wget https://github.com/oliver006/redis_exporter/releases/download/v1.27.1/redis_exporter-v1.27.1.linux-amd64.tar.gz

启动

#对一个redis服务进行监控
nohup ./redis_exporter -redis.addr 47.103.23.154:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9122 &

#对多个redis服务进行监控
nohup ./redis_exporter -redis.addr 47.103.23.154:6379,47.103.23.164:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9122 &

prometheus.yml的scrape_configs节点增加如下配置
之后重启prometheus

- job_name: 'redis_15'  
    static_configs:
    - targets: ['127.0.0.1:9106']

9、监控rabbitmq

官网下载,解压即安装

https://github.com/kbudde/rabbitmq_exporter/

wget https://github.com/kbudde/rabbitmq_exporter/releases/download/v1.0.0-RC8/rabbitmq_exporter-1.0.0-RC8.linux-amd64.tar.gz

增加config.json配置

{
    "rabbit_url": "http://127.0.0.1:15672",
    "rabbit_user": "monitor", #必须具备admin权限
    "rabbit_pass": "1",
    "publish_port": "9107",
    "publish_addr": "",
    "output_format": "TTY",
    "ca_file": "ca.pem",
    "cert_file": "client-cert.pem",
    "key_file": "client-key.pem",
    "insecure_skip_verify": false,
    "exlude_metrics": [],
    "include_queues": ".*",
    "skip_queues": "^$",
    "skip_vhost": "^$",
    "include_vhost": ".*",
    "rabbit_capabilities": "no_sort,bert",
    "enabled_exporters": [
            "exchange",
            "node",
            "overview",
            "queue"
    ],
    "timeout": 30,
    "max_queues": 0
}

启动

nohup ./rabbitmq_exporter -config-file config.json &

prometheus.yml的scrape_configs节点增加如下配置
之后重启prometheus

- job_name: 'rabbitmq_15'  
    static_configs:
    - targets: ['127.0.0.1:9107']
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值