Prometheus 简介
什么是 Prometheus
Prometheus 是一个开源监控报警系统和时序列数据库
主要功能
多维数据模型 (时序由 metric 名字和 k/v 的 labels 构成)
灵活的查询语句 (PromQL)
无依赖存储, 支持 local 和 remote 不同模型
采用 http 协议, 使用 pull 模式, 拉取数据, 简单易懂
监控目标, 可以采用服务发现或静态配置的方式
支持多种 DashBoard, 图形化友好
核心组件
Prometheus Server, 主要用于抓取数据和存储时序数据, 另外还提供查询和 Alert Rule 配置管理.
client libraries, 用于对接 Prometheus Server, 可以查询和上报数据.
push gateway , 用于批量, 短期的监控数据的汇总节点, 主要用于业务数据汇报等.
各种汇报数据的 exporters , 例如汇报机器数据的 node_exporter, 汇报 MongoDB 信息的 MongoDB exporter 等等.
用于告警通知管理的 alertmanager .
基础架构
主要模块包含: Server, Exporters, Pushgateway, PromQL, Alertmanager, webUI 等.
Prometheus Server: 主要是负责存储, 抓取, 聚合, 查询方面
Alertmanager: 主要是负责实现报警功能
Pushgateway : 主要是实现接收由 Client push 过来的指标数据, 在指定的时间间隔, 由主程序来抓取
exporter: 数据采样器
学习参考网站 (此章博客有参考以下网站~ 用作学习)
技术大牛博客: https://www.k8stech.net/
中文技术文档:
Prometheus+node_exporter+Grafana 资源监控架构图
Centos7.x 安装 Prometheus
下载安装 Prometheus
- PROM_PATH='/data/prometheus'
- mkdir -p ${
- PROM_PATH
- }
- mkdir -p ${
- PROM_PATH
- }/{
- data,conf,logs,bin
- }
- useradd prometheus
- cd /usr/local/src
- wget https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz
- tar -xvf prometheus-2.13.0.Linux-amd64.tar.gz
- cd prometheus-2.13.0.Linux-amd64/
- cp prometheus promtool ${
- PROM_PATH
- }/bin/
- cp prometheus.YAML ${
- PROM_PATH
- }/conf/
- chown -R prometheus.prometheus /data/prometheus
- # Setting Variables
- cat>> /etc/profile <<EOF
- PATH=/data/prometheus/bin:$PATH:$HOME/bin
- EOF
将 Prometheus 配置系统服务
- cat>>/etc/systemd/system/prometheus.service <<EOF
- [Unit]
- Description=Prometheus
- Documentation=https://prometheus.io/
- After=network.target
- [Service]
- Type=simple
- User=prometheus
- ExecStart=/data/prometheus/bin/prometheus --config.file=/data/prometheus/conf/prometheus.YAML --storage.tsdb.path=/data/prometheus/data --storage.tsdb.retention=90d
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- EOF
现在使用下面的 systemctl 命令重新加载 systemd 系统, 并查看服务是否启动
- systemctl daemon-reload
- systemctl enable prometheus.service
- systemctl start prometheus.service
- systemctl status prometheus.servic
查看端口是否正常
netstat -plntu |grep 9090
这里需要放行 9090 端口, 也可以直接关闭防火墙
- systemctl stop firewalld
- systemctl status firewall
访问 http://IP:9090
出现上图就是成功了!!
Centos7.x 安装 Node_exporter
下载安装 Node_exporter
- NODE_PATH='/data/prometheus/node_exporter/'
- cd /usr/local/src/
- mkdir -p ${
- NODE_PATH
- }
- wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
- tar -xvf node_exporter-0.18.0.Linux-amd64.tar.gz
- cp node_exporter-0.18.0.Linux-amd64/node_exporter ${
- NODE_PATH
- }
- chown -R prometheus.prometheus ${
- NODE_PATH
- }
配置 Node_exporter 系统服务
- cat> /lib/systemd/system/node_exporter.service <<EOF
- [Unit]
- Description=node_exporter
- Documentation=https://prometheus.io/
- After=network.target
- [Service]
- Type=simple
- User=prometheus
- ExecStart=/data/prometheus/node_exporter/node_exporter
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- EOF
现在使用下面的 systemctl 命令重新加载 systemd 系统, 并查看服务是否启动
- systemctl daemon-reload
- systemctl enable node_exporter.service
- systemctl start node_exporter.service
- systemctl status node_exporter.service
查看端口是否正常
netstat -plntu |grep 9100
这里需要放行 9100 端口
访问 http://IP:9100/metrics
如果出现上图, 就成功啦!!!
最后一步, 配置 prometheus.YAML
如果是跟着我的安装步骤走的话, 它的路径是 /data/prometheus/conf
- # 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']
- # 主要是新增了 node_exporter 的 job, 如果有多个 node_exporter, 在 targets 数组后面加即可
- - job_name: 'node_exporter'
- static_configs:
- - targets: ['localhost:9100']
配置 Grafana
这里就不展开如何安装 Grafana 了哈, 不懂的可以查看这篇博客: https://www.cnblogs.com/poloyy/p/12219145.html
配置完之后, 就能自动读取 prometheus 存储的数据, 然后就 dengdengdengdeng!! 厉酷炫吧!!
如果你读取失败, 请务必检查自己的 prometheus 和 Node_exporter 是否有安装成功, 通过访问 9090 和 9100 端口的网址来判断即可!
来源: https://www.cnblogs.com/poloyy/p/12375039.html