Prometheus及Grafana监控服务的安装使用
说明
Prometheus 是一个开放性的监控解决方案,通过 Node Exporter 采集当前主机的系统资源使用情况,并通过 Grafana 创建一个简单的可视化仪表盘。
docker 安装 prometheus(未持久化数据)
docker run -d \
-p 9090:9090 \
-v ./prometheus.yml:/etc/prometheus/prometheus.yml \
--name=prometheus \
prom/prometheus:latest \
--web.enable-lifecycle
配置的 prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ["10.10.20.11:9100", "10.10.20.12:9100", "10.10.20.13:9100"]
labels: appname:'local-linux'
重载配置
curl -X POST http://10.10.20.11:9090/-/reload
docker 安装 grafana(未持久化数据)
docker run -d --name=grafana -p 3000:3000 grafana/grafana
访问:http://10.10.20.11:3000/ admin/admin
添加数据源,导入模板 12884 即可
docker 安装 node-exporter
暴露节点信息给 Prometheus
docker run -d --restart=always \
-p 9100:9100 \
--name node-exporter \
quay.io/prometheus/node-exporter:latest
docker-compose 部署 prometheus 及 grafana
version: "3"
services:
# prometheus
prom:
restart: unless-stopped
image: prom/prometheus:v2.39.1
container_name: prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/etc/prometheus/console_libraries"
- "--web.console.templates=/etc/prometheus/consoles"
- "--storage.tsdb.retention=200h"
- "--web.enable-lifecycle"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:rw
- ./prometheus_data:/prometheus
ports:
- 9090:9090
# grafana
grafana:
restart: unless-stopped
container_name: grafana
image: grafana/grafana:6.7.2
ports:
- "3000:3000"
volumes:
- ./grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false
depends_on:
- prom
#设置权限 chmod 777 ./grafana_data&&chmod 777 ./prometheus_data
设置权限
chmod 777 ./grafana_data && chmod 777 ./prometheus_data
ubuntu 服务器安装 prometheus-node-exporter
- 我们执行这个命令来更新可用软件包的列表和它们的所有版本。
sudo apt-get update - 通过这个命令,我们将继续安装软件包
sudo apt-get install prometheus-node-exporter - 要检查你是否已经成功安装了软件包,你可以用下面的命令列出所有已安装的软件包。
dpkg -l prometheus-node-exporter
windows 服务器安装 prometheus-node-exporter
下载地址:https://github.com/prometheus-community/windows_exporter/releases
监控配置
k8s 插件安装
插件名 DevOpsProdigy KubeGraf
k8s 监控需要安装插件 DevOpsProdigy KubeGraf,版本用 6.7.2,配置 config basic64 解码配置,进入容器中 安装依赖 grafana-cli plugins install grafana-piechart-panel
clickhouse 插件安装
插件名 vertamedia-clickhouse-datasource
redis 监控
安装 redis_exporter
docker pull oliver006/redis_exporter
运行
docker run -d --restart=always --name redis_exporter -p 9121:9121 oliver006/redis_exporter --redis.addr redis://192.168.0.666:6380
配置 prometheus.yml
- job_name: "redis_exporter_targets"
static_configs:
- targets:
[
"redis://192.168.0.147:6380",
"redis://192.168.0.149:6380",
"redis://192.168.0.150:6380",
]
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.0.149:9121
grafana 面板
version:v6.7.2
envoy:11021
windows:12566
Linux:10180
k8s:插件 DevOpsProdigy KubeGraf,配置 config basic64 解码配置,进入容器中 安装依赖 grafana-cli plugins install grafana-piechart-panel
redis:763
clickhouse:2515,需要安装插件并配置数据源 grafana-cli plugins install vertamedia-clickhouse-datasource 1.9.5