prometheus
Prometheus是一个开源的服务监控系统,它通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。
- 多维数据模型(时序列数据由metric名和一组key/value组成)
- 在多维度上灵活的查询语言(PromQl)
- 不依赖分布式存储,单主节点工作.
- 通过基于HTTP的pull方式采集时序数据
- 可以通过push gateway进行时序列数据推送(pushing)
- 可以通过服务发现或者静态配置去获取要采集的目标服务器
- 多种可视化图表及仪表盘支持
- Prometheus通过安装在远程机器上的exporter来收集监控数据,后面我们将使用到node_exporter收集系统数据。
grafana
Grafana 是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点。
安装docker
Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。
通过 uname -r 命令查看你当前的内核版本
#第一步先卸载以前的doker 如果之前每一安装直接忽略
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
#安装docker
yum install -y docker
#启动docker
systemctl start docker
#查看状态
安装node-exporter
#下载镜像
docker pull prom/node-exporter
#运行
docker run -d \
-p 9100:9100 \
quay.io/prometheus/node-exporter
安装grafana
#下载镜像
docker pull grafana/grafana
#运行
进入 http://192.168.30.114:3000,grafana的默认账号密码是admin/admin
安装prometheus
docker 安装
#下载镜像
docker pull prom/prometheus
#运行
sudo docker run -d \
-p 9090:9090 \
-v /usr/local/src/file/prometheus.yml:/usr/local/src/file/prometheus.yml \
quay.io/prometheus/prometheus \
--config.file=/usr/local/src/file/prometheus.yml
进入http://192.168.142.130:9090
都运行成功后看下 docker
[root@localhost file]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
654487ad7621 oliver006/redis_exporter "/bin/redis_export..." 2 hours ago Up 31 minutes 0.0.0.0:9121->9121/tcp redis_exporter
11e82881d752 quay.io/prometheus/prometheus "/bin/prometheus -..." 3 hours ago Up 27 minutes 0.0.0.0:9090->9090/tcp priceless_lamport
05d8d6fad0aa grafana/grafana "/run.sh" 3 hours ago Up 31 minutes 0.0.0.0:3000->3000/tcp grafana
d8897ae17fab quay.io/prometheus/node-exporter "/bin/node_exporter"
有个prometheus.yml需要自己创建位置是/usr/local/src/file/ 这个文件放哪里都可以 到时候指定下就行了
# 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.30.114:9090']
- job_name: 'redis'
static_configs:
- targets: ['192.168.30.114:9121']
labels:
instance: redis
- job_name: 'AtomData' #会在grafana的页面展现出同一job下的所有ip监控信息
static_configs:
- targets: ['192.168.30.114:9100']
- targets: ['192.168.30.115:9100']
- targets: ['192.168.30.118:9101']
- targets: ['192.168.30.116:9100']
- targets: ['192.168.30.117:9100']
【重要】若想同时监控好几台机器,则在需要监控的机器上安装node_expoter即可,并且重启prometheus和重启grafana
- 192.168.30.115、192.168.30.116、192.168.30.117、192.168.30.118上执行【安装node-exporter】如何安装node_expoter按照上面的安装步骤执行即可
- docker ps(获取到ID)
- docker restart XXX
- 重启后,再次进入grafana进行刷新,即可看到115、116、117、118的机器监控信息
然后打开192.168.142.130:9090 看到图下的up证明都启动好了没啥问题
然后打开http://192.168.30.114:3000登录 配置 数据源,添加的dashboard为11074
1.作者:Syw
2.本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
3.如果文中有什么错误,欢迎指出。以免更多的人被误导。