目录
系统环境
环境:centos7.0
Prometheus版本:2.14.0
node_exporter版本:0.18.1
Prometheus 是什么?
- Prometheus是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的。随着发展,越来越多公司和组织接受采用Prometheus,社区也十分活跃,他们便将它独立成开源项目,并且有公司来运作。google SRE的书内也曾提到跟他们BorgMon监控系统相似的实现是Prometheus。现在最常见的Kubernetes容器管理系统中,通常会搭配Prometheus进行监控。
Prometheus 的优点
- 非常少的外部依赖,安装使用超简单
- 已经有非常多的系统集成 例如:docker HAProxy Nginx JMX等等
- 服务自动化发现
- 直接集成到代码
- 设计思想是按照分布式、微服务架构来实现的
Prometheus 的特性
- 自定义多维度的数据模型
- 非常高效的存储 平均一个采样数据占 ~3.5 bytes左右,320万的时间序列,每30秒采样,保持60天,消耗磁盘大概228G。
- 强大的查询语句
- 轻松实现数据可视化
Prometheus系统架构
- 下图说明了Prometheus的体系结构及其某些生态系统组件
Prometheus下载二进制文件并安装运行
[root@localhost ~]# mkdir -p /data/prometheus
[root@localhost ~]# cd /data/prometheus
[root@localhost prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.14.0-rc.0/prometheus-2.14.0-rc.0.linux-amd64.tar.gz
[root@localhost prometheus]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost prometheus]# tar -zxf prometheus-2.14.0-rc.0.linux-amd64.tar.gz
[root@localhost prometheus]# tar -zxf node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# cd /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# sed -i 's/localhost/192.168.100.228/g' prometheus.yml
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# nohup ./prometheus &
使用浏览器访问Prometheus
出现以下页面则表示Prometheus搭建成功
使用node_exporter获取监控主机的数据
[root@localhost prometheus]# cat /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64/prometheus.yml
# 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: ['192.168.100.228:9090']
- job_name: 'server'
static_configs:
- targets: ['192.168.100.228:9100']
[root@localhost ~]# cd /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64/ && nohup ./prometheus &
[root@localhost ~]# cd /data/prometheus/node_exporter-0.18.1.linux-amd64 &&nohup ./node_exporter &
再次使用浏览器查看Prometheus系统是否添加主机进来
Prometheus与grafana集成监控
[root@localhost ~]# mkdir -p /data/grafana
[root@localhost ~]# cd /data/grafana
[root@localhost grafana]# wget https://dl.grafana.com/oss/release/grafana-6.4.4.linux-amd64.tar.gz
[root@localhost grafana]# tar zxf grafana-6.4.4.linux-amd64.tar.gz
grafana默认账户密码为:admin/admin,第一次登陆成功后会强制修改默认密码
修改密码
点击添加数据源
然后选择第一个Prometheus
输入Prometheus监控系统的地址,这里为192.168.100.228
在grafana官网下载模板
获取模板ID
返回仪表盘,添加仪表盘,
将获取到的模板ID填入该文本框中
选择Prometheus,然后点击import
至此,grafana与Prometheus监控系统搭建成功