发布时间:2025-12-09 11:47:14 浏览次数:1
Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,由 SoundCloud 公司开发。
Prometheus 基本原理是通过 HTTP 协议周期性抓取被监控组件的状态,这样做的好处是任意组件只要提供 HTTP 接口就可以接入监控系统,不需要任何 SDK 或者其他的集成过程。这样做非常适合虚拟化环境比如 VM 或者 Docker 。
Prometheus 应该是为数不多的适合 Docker、Mesos、Kubernetes 环境的监控系统之一。
易于管理:
强大的查询语言 PromQL:
高效:
可扩展:
sharding)+ 联邦集群(federation)可以对其进行扩展。易于集成:
可视化:
如上图,Prometheus 主要由以下部分组成:
Prometheus:主要是负责存储、抓取、聚合、查询方面。Alertemanager:主要是负责实现报警功能。Pushgateway:主要是实现接收有 Client-push 过来的指标数据,在指定的时间间隔,有主程序来抓取。*_exporter:主要是负责采集物理机、中间件的信息。准备工作:
主机名 | 操作系统 | IP 地址 |
|---|---|---|
Prometheus | CentOS 7.4 | 192.168.1.1 |
Client | CentOS 7.4 | 192.168.1.2 |
Granfana | CentOS 7.4 | 192.168.1.3 |
ntpdate 工具,并进行时间同步(因为 Prometheus 对时间要求非常严格)yum -y install ntpdate/usr/sbin/ntpdate ntp1.aliyun.com[root@Prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz[root@Prometheus ~]# tar xf prometheus-2.16.0.linux-amd64.tar.gz[root@Prometheus ~]# mv prometheus-2.16.0.linux-amd64 /usr/local/prometheus[root@Prometheus ~]# useradd -s /sbin/nologin prometheus[root@Prometheus ~]# chown -R prometheus:prometheus /usr/local/prometheus/[root@Prometheus ~]# vim /usr/lib/systemd/system/prometheus.service[Unit]Description=prometheusAfter=network.target [Service]User=prometheusGroup=prometheusWorkingDirectory=/usr/local/prometheusExecStart=/usr/local/prometheus/prometheus[Install]WantedBy=multi-user.target[root@Prometheus ~]# systemctl daemon-reload[root@Prometheus ~]# systemctl enable --now prometheus# 启动并开启自启当启动 Prometheus 后,便可以通过 9090 端口来访问 Prometheus 自带的 UI 界面:
/usr/local/prometheus/data 目录,存储数据的大小受限和扩展不便;influxdb 作为后端的数据库来存储数据。1)安装
[root@Prometheus ~]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.8.x86_64.rpm[root@Prometheus ~]# yum -y localinstall influxdb-1.7.8.x86_64.rpm[root@Prometheus ~]# cp /etc/influxdb/influxdb.conf /etc/influxdb/influxdb.conf.default[root@Prometheus ~]# systemctl enable --now influxdb2)验证
[root@Prometheus ~]# influxConnected to http://localhost:8086 version 1.7.8InfluxDB shell version: 1.7.8> create database prometheus;> exit3)配置 Prometheus 集成 infuxdb
[root@Prometheus ~]# vim /usr/local/prometheus/prometheus.yml在最后面添加:remote_write: - url: "http://localhost:8086/api/v1/prom/write?db=prometheus"remote_read: - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"[root@Prometheus ~]# systemctl restart prometheus# 重启 Prometheusinfluxdb 配置密码,请参考 官网文档 来进行配置。[root@Client ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz[root@Client ~]# tar xf node_exporter-0.18.1.linux-amd64.tar.gz[root@Client ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/exporter/[root@Client ~]# vim /usr/lib/systemd/system/node_exporter.service[Unit]Description=node_exporterAfter=network.target [Service]User=prometheusGroup=prometheusExecStart=/usr/local/exporter/node_exporter --web.listen-address=:20001 --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service --collector.processes[Install]WantedBy=multi-user.target[root@Client ~]# systemctl daemon-reload[root@Client ~]# systemctl enable --now node_exporter当启动 node_exporter 服务后,便可以通过 20001 端口来访问 Client 的监控指标。
[root@Prometheus ~]# vim /usr/local/prometheus/prometheus.yml- job_name: "Client" static_configs: - targets: - "192.168.1.2:20001"[root@Prometheus ~]# systemctl restart prometheus[root@Grafana ~]# wget https://dl.grafana.com/oss/release/grafana-6.1.4-1.x86_64.rpm[root@Grafana ~]# tar xf grafana-6.1.4-1.x86_64.rpm[root@Grafana ~]# systemctl enable --now grafana-server[root@Grafana ~]# netstat -anpt | grep 3000Add data source(添加数据源)
Import(导入模板)
161737.html