prometheus
Prometheus是一個開源的服務監(jiān)控系統(tǒng),它通過HTTP協(xié)議從遠程的機器收集數(shù)據(jù)并存儲在本地的時序數(shù)據(jù)庫上碟贾。
- 多維數(shù)據(jù)模型(時序列數(shù)據(jù)由metric名和一組key/value組成)
- 在多維度上靈活的查詢語言(PromQl)
- 不依賴分布式存儲移盆,單主節(jié)點工作.
- 通過基于HTTP的pull方式采集時序數(shù)據(jù)
- 可以通過push gateway進行時序列數(shù)據(jù)推送(pushing)
- 可以通過服務發(fā)現(xiàn)或者靜態(tài)配置去獲取要采集的目標服務器
- 多種可視化圖表及儀表盤支持
- Prometheus通過安裝在遠程機器上的exporter來收集監(jiān)控數(shù)據(jù)悼院,后面我們將使用到node_exporter收集系統(tǒng)數(shù)據(jù)。
grafana
Grafana 是一個開箱即用的可視化工具咒循,具有功能齊全的度量儀表盤和圖形編輯器据途,有靈活豐富的圖形化選項绞愚,可以混合多種風格,支持多個數(shù)據(jù)源特點颖医。
安裝docker
Docker 要求 CentOS 系統(tǒng)的內(nèi)核版本高于 3.10 位衩,查看本頁面的前提條件來驗證你的CentOS 版本是否支持 Docker 。
通過 uname -r 命令查看你當前的內(nèi)核版本
#第一步先卸載以前的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
#查看狀態(tài)
systemctl status docker
安裝node-exporter
#下載鏡像
docker pull prom/node-exporter
#運行
docker run -d \
-p 9100:9100 \
quay.io/prometheus/node-exporter
安裝redis_exporter
#下載鏡像
docker pull oliver006/redis_exporter
#運行
docker run -d \
--name redis_exporter \
-p 9121:9121 \
oliver006/redis_exporter --redis.addr redis://192.168.10.208:6379
安裝grafana
#下載鏡像
docker pull grafana/grafana
#運行
docker run -d --name=grafana -p 3000:3000 grafana/grafana
grafana的默認賬號密碼是admin/admin
安裝prometheus
有個prometheus.yml需要自己創(chuàng)建位置是/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: ['localhost:9090']
- job_name: 'redis'
static_configs:
- targets: ['192.168.142.130:9121']
labels:
instance: redis
- job_name: 'linux'
static_configs:
- targets: ['192.168.142.130:9100']
labels:
instance: node
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
都運行成功后看下 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" 4 hours ago Up 31 minutes 0.0.0.0:9100->9100/tcp kind_kowalevski
然后打開192.168.142.130:9090 看到圖下的up證明都啟動好了沒啥問題
然后打開http://192.168.142.130:3000登錄 配置 數(shù)據(jù)源
redis監(jiān)控模板 https://grafana.com/api/dashboards/763/revisions/1/download 下載 鼠標放在grafana+點擊import導入就行了