普罗米修斯prometheus

普罗米修斯prometheus

一、简介

1 介绍

Prometheus 是一个开源的服务监控系统和时间序列数据库。

Prometheus通过抓取应用程序暴露的时间序列来工作。时间序列数据通常由应用程序本身通过客户端或exporter(导出器)来作为HTTP端点暴露。

架构在这里插入图片描述

2 构成
node_exporter、mysql_exporter、oracledb-exporter探测节点,类似与探测器,收集应用的数据
prometheus收集探测器发来的数据
grafana图形的方式显示数据
altermanager告警系统

二、配置文件

prometheus的配置文件

prometheus.yaml

检验yaml语法是否正确的网站 : http://www.yamllint.com/

也可以直接用promtool工具检查语法是否正确

默认配置文件prometheus.yaml中定义了4个YAML块:global、alerting、rule_files和scrape_configs。

2.1 global模块

控制prometheus服务器行为的全局配置

scrape_interval指定应用程序或服务抓取数据的时间间隔。建议设置全局抓取间隔,所有时间序列具有相同的粒度,可以组合在一起计算。
evaluation_interval指定prometheus评估规则的频率。记录规则recording rule :允许预先计算使用频率且开销大的表达式,并将结果作为一个新的时间序列数据;警报规则 alerting rule:允许定义警报条件
2.2 alerting模块

用来设置prometheus的警报。警报是由Alertmanager的独立工具进行管理的,Alertmanager是一个可以集群化的独立警报管理工具。

在这里插入图片描述

prometheus还支持Alertmanager的服务发现功能,可以查询外部源(如Consul服务器)来返回可用的alertmanager列表,而不是单独指定每个alertmanager。

2.3 rule_files 模块

指定包含记录规则或警报规则的文件列表

2.4 scrape_configs 模块

指定prometheus抓取的所有目标,目标中包含:标签、建立连接所需的身份验证等。若干目标构成的组称为作业,作业里每个目标都有一个名为实例instance的标签,用来唯一标识这个目标

在这里插入图片描述

默认配置中定义了一个作业prometheus,监控本地的9090端口,即Prometheus服务本身。

2.5 初始配置文件
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

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

    static_configs:
    - targets: ['localhost:9090']

http://localhost:9090/metrics 可以获取普罗米修斯自身的运行数据

三、启动Prometheus

1 使用promtool检查配置文件语法
#这个工具就在安装prometheus的目录下/usr/local/prometheus/
./promtool   check config  prometheus.yml
2 启动文件 配置文件
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
#  --config.file指定配置文件
# 修改普罗米修斯启动端口号
--web.listen-address=':9001'  #可选项

prometheus的启动参数

在这里插入图片描述
在这里插入图片描述

3 检查是否启动成功
lsof   -i:9090   #查看端口占用

http://prometheus服务器IP地址:9090/metric   # 访问网页

四、探测器

1 node_exporter

作用:Go语言编写的一个提供收集各种主机指标数据(包括CPU、内存和磁盘)的库。

检查node_exporter是否安装成功

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LfhjhICf-1626945732291)(C:\Users\WMY\AppData\Roaming\Typora\typora-user-images\image-20210722160431075.png)]

# ./node_exporter   --version   #查看版本号
# ./node_exporter   --help      # 各种参数

(img-WZP5kfS2-1626945732292)(C:\Users\WMY\AppData\Roaming\Typora\typora-user-images\image-20210722160952824.png)]
在这里插入图片描述

2 mysqld_exported

​ 安装mysqld_exported后,需要创建一个数据库用户moniter_user,授予它增删改查等权限,待会mysqld_exported就使用这个用户登录数据库然后收集数据库信息,所以在启动mysqld_exported时,需要指定写好数据库用户密码的配置文件。

在/home/prometheus/下新建.my.cnf文件
vim .my.cnf
[client]
user=mysqld_exporter
password=123456

启动

# --config.my-cnf启动参数指定配置文件
/usr/local/mysqld_exporter/mysqld_exporter    --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf

开机自启动

vim /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=Prometheus1
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter \
         --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf  
Restart=on-failure
[Install]
WantedBy=multi-user.target


groupadd -r prometheus && useradd -s /sbin/nologin -r -g prometheus prometheus
chown -R prometheus:prometheus /usr/local/mysqld_exporter/

systemctl enable mysql_exporter.service
systemctl start mysql_exporter.service

五、端口汇总

prometheus9090
grafana3000
altermanager9093
node_exporter9100
mysqld_exporter9104
oracledb_exporter9161

六、总结

1 监控流程

exporter软件相当于探测器,收集服务运行时产生的数据,并在特定的HTTP端口上暴露这些数据

比如,node_exporter收集服务器CPU、内存和磁盘等的运行数据,将这些数据暴露在http://被监控主机IP:9100/metrics

在启动node_exporter时,设置启动参数可以更改端口,暴露数据的URL地址

prometheus通过HTTP协议,也就是exporter暴露的IP地址和端口来获取被监控端的数据,需要在prometheus.yml配置文件中添加目标,即监控对象的名称和IP、端口。可以使用promtool工具检查修改后的prometheus.yml语法是否正确。启动prometheus时,设置启动参数可以更改端口,监控数据的保存时间,数据保存的位置。

grafana 将数据转化为图像的方式呈现,在安装完grafana后选择数据源时指定prometheus服务器的IP地址和端口。

数据的流动方向 :exporter ——> prometheus ——> grafana

2 部署安装是否正确的检查点
(1)检查exporter工具是否安装正确
lsof  -i:端口号     #检查端口号是否被占用
/usr/local/node_exporter/node_exporter  -version  #查版本号
http://被监控主机IP:端口号/metrics   访问浏览器页面,exporter #是否正确暴露出数据   
(2)检查prometheus是否正确安装

与上类似,检查端口号,版本,访问网页。http://部署prometheus服务器的IP:9090

(3)检查prometheus能否正确调用到exporter所在主机

在prometheus服务器上

curl -i http://exporter_IP/port 比如:curl -i http://10.12.11.56:9100

如果不通,要检查安装exporter的服务器的防火墙是否允许prometheus服务器访问它的端口。

七、其他参考资料

视频:

https://www.bilibili.com/video/BV16J411z7SQ?p=9&spm_id_from=pageDriver

文档:具体的安装步骤

链接:https://pan.baidu.com/s/1nm116LXaGoIAwngog8vFOA
提取码:2z9b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值