赞
踩
Prometheus 介绍
Prometheus是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的。随着发展,越来越多公司和组织接受采用Prometheus,社区也十分活跃,他们便将它独立成开源项目,并且有公司来运作。google SRE的书内也曾提到跟他们BorgMon监控系统相似的实现是Prometheus。现在最常见的Kubernetes容器管理系统中,通常会搭配Prometheus进行监控。
Prometheus 的优点
1. 非常少的外部依赖,安装使用超简单
2. 已经有非常多的系统集成 例如:docker HAProxy Nginx JMX等等
3. 服务自动化发现
4. 直接集成到代码
5. 设计思想是按照分布式、微服务架构来实现的
Prometheus 的特性
1. 自定义多维度的数据模型
2. 非常高效的存储 平均一个采样数据占 ~3.5 bytes左右,320万的时间序列,每30秒采样,保持60天,消耗磁盘大概228G。
3. 强大的查询语句
4. 轻松实现数据可视化
Prometheus架构
Grafana介绍
Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下几个特点:
展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;
通知提醒:4.0之后的添加了报警功能,可以以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
1.安装node_exporter
源码地址:https://github.com/prometheus/node_exporter
在下载安装Prometheus之前我们先安装node_exporter插件,用于提供服务器监控的指标(比如:CPU、内存、磁盘、磁盘读写速率等指标),是一个非常常用的Prometheus Client插件。
下载
wget -c https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
解压
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz
后台运行
nohup yourPath/node_exporter > yourLogPath/node_exporter.stdout 2>&1 &
2.安装Prometheus
下载地址:https://prometheus.io/download/
下载版本号为2.13.0,也可以根据自己需要下载其他版本
wget -c https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gz
解压
tar -zxvf prometheus-2.13.0.linux-amd64.tar.gz
配置
在prometheus.yml配置文件中追加node_exporter的job,监控本机服务器
- - job_name: 'node_exporter'
- static_configs:
- - targets: ['localhost:9100']
注:如果需要监控多台服务器指标,则只需要在其他服务器上安装node_exporter即可,不需要安装prometheus。参考配置如下:
- - job_name: 'node_exporter'
- static_configs:
- - '192.168.20.165:9100'
- - '192.168.20.166:9100'
- - '192.168.20.167:9100'
启动
nohup yourPath/prometheus > yourLogPath/prometheus.stdout 2>&1 &
注:yourPath是prometheus可执行程序所在路径,yourLogPath是日志路径,prometheus默认会加载prometheus.yml文件进行初始化,默认端口为9090。
启动成功后可以访问9090端口(注意防火墙需要开启该端口)
insert metric at cursor里面是prometheus监控的指标
Status -> Targets是监控的目标节点
下载地址: https://grafana.com/grafana/download
下载 版本号为6.4.1
wget https://dl.grafana.com/oss/release/grafana-6.4.1.linux-amd64.tar.gz
解压
tar -zxvf grafana-6.4.1.linux-amd64.tar.gz
下载饼图插件grafana-piechart-panel
可以到grafana的bin目录下:grafana-cli plugins install grafana-piechart-panel将下载后的插件,放入到grafana文件的data/plugins。因为grafana启动会去加载data/plugins中的插件。
也可以用以下方式安装饼图
- cd /var/lib/grafana/plugins/
-
- git clone https://github.com/grafana/piechart-panel.git
后台启动grafana
nohup yourPath/bin/grafana-server > yourLogPath/grafana.stdout 2>&1 &
登录grafana,默认端口为3000, 初始账号密码为admin/admin
登录之后添加prometheus数据源
数据源为prometheus(http://localhost:9090)
添加node_exporter对应的仪表盘
导入后就可以看到node_exporter提供的监控指标,如下图所示
注:关于Granafa仪表盘ID可参考:
https://grafana.com/grafana/dashboards
后续文章会使用prometheus+grafana监控Kafka、EMQ、服务进程等功能。
参考文章
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。