Centos7.X 搭建Prometheus+node_exporter+Grafana及时监控平台
分布式系统一致性问题与Raft算法(上)
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:数据采样器
进修参考网站(此章博客有参考以下网站~用作进修)
手艺大牛博客:
中文手艺文档:
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.yml ${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.yml --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.yml
假如是随着我的装置步骤走的话,它的途径是 /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了哈,不懂的能够检察这篇博客:
设置完以后,就可以自动读取prometheus存储的数据,然后就dengdengdengdeng!!厉酷炫吧!!
假如你读取失利,请务必搜检本身的prometheus和Node_exporter是不是有装置胜利,经由过程接见9090和9100端口的网址来推断即可!
Lambda表达式