以下所有工具都通过docker-compose安装,docker、docker-compose请自行安装。
node-exporter安装
version: '3.1'
services:
node_exporter:
image: registry.cn-shanghai.aliyuncs.com/mamy-ns/node-exporter
container_name: node_exporter
command:
- '--path.rootfs=/host'
pid: host
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
ports:
- 9100:9100
volumes:
- '/:/host:ro,rslave'
启动node-exporter
docker-compose up -d
点击Metrics
prometheus安装
创建两个文件夹,分别存放prometheus数据和配置文件
mkdir -p /data/prometheus/data
mkdir -p /data/prometheus/config
创建prometheus配置文件prometheus.yml, 并将其放在/data/prometheus/config文件夹中
global:
scrape_interval: 15s
evaluation_interval: 15s
# Alertmanager configuration
# alerting:
# alertmanagers:
# - static_configs:
# - targets: ['192.168.0.106:9093']
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
# rule_files:
# - "node_down.yml"
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
config.
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.101.10:9100'] # node-exporter地址
prometheus安装yml
version: '3.1'
services:
prometheus:
image: registry.cn-shanghai.aliyuncs.com/mamy-ns/prometheus
container_name: prometheus
hostname: prometheus
restart: always
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
volumes:
- /data/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml
- /data/prometheus/data:/prometheus
ports:
- '9090:9090'
启动prometheus
docker-compose up -d
grafana安装
version: '3.1'
services:
grafana:
image: registry.cn-shanghai.aliyuncs.com/mamy-ns/grafana
container_name: grafana
hostname: grafana
restart: always
ports:
- '3000:3000'
访问默认密码admin/admin
配置数据源,填写prometheus访问地址
配置面板
这里我们使用ID为8919的模版,导入后填写名称、选择数据源,点击import
最后效果