首先在监控目标鸡上安装Netdata,通过portainer新建stack并贴入以下内容:
version: '3'
services:
netdata:
image: netdata/netdata
container_name: netdata
hostname: example.com # set to fqdn of host
ports:
- 19999:19999
restart: unless-stopped
cap_add:
- SYS_PTRACE
security_opt:
- apparmor:unconfined
volumes:
- netdataconfig:/etc/netdata
- netdatalib:/var/lib/netdata
- netdatacache:/var/cache/netdata
- /etc/passwd:/host/etc/passwd:ro
- /etc/group:/host/etc/group:ro
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /etc/os-release:/host/etc/os-release:ro
volumes:
netdataconfig:
netdatalib:
netdatacache:
准备在监测鸡上的docker安装prometheus,先建立对应文件夹/root/data/docker_data/prometheus,并在文件夹中生成配置文件prometheus.yml
mkdir -p /root/data/docker_data/prometheus
cd /root/data/docker_data/prometheus
touch prometheus.yml
使用以下内容建立portainer stack,或直接生成docker-compose文件
version: '3.3'
services:
prometheus:
ports:
- '9090:9090'
volumes:
- '/root/data/docker_data/prometheus:/etc/prometheus'
image: prom/prometheus
将以下内容贴入prometheus.yml,每增加一个netdata数据源,只需增加一段##号间的内容,并修改对应的job_name以及targets的ip地址和端口号
# 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: 'netdata-scrape'
metrics_path: '/api/v1/allmetrics'
params:
# format: prometheus | prometheus_all_hosts
# You can use `prometheus_all_hosts` if you want Prometheus to set the `instance` to your hostname instead of IP
format: [prometheus]
#
# source: as-collected | raw | average | sum | volume
# default is: average
#source: [as-collected]
#
# server name for this prometheus - the default is the client IP
# for Netdata to uniquely identify it
#server: ['prometheus1']
honor_labels: true
static_configs:
- targets: ['192.168.1.13:19999']
#############################################################################################
#############################################################################################
- job_name: 'netdata-scrape'
metrics_path: '/api/v1/allmetrics'
params:
# format: prometheus | prometheus_all_hosts
# You can use `prometheus_all_hosts` if you want Prometheus to set the `instance` to your hostname instead of IP
format: [prometheus]
#
# source: as-collected | raw | average | sum | volume
# default is: average
#source: [as-collected]
#
# server name for this prometheus - the default is the client IP
# for Netdata to uniquely identify it
#server: ['prometheus1']
honor_labels: true
static_configs:
- targets: ['192.168.1.13:19999']
#############################################################################################
最后安装grafana,使用以下内容创建docker stack
version: '3.3'
services:
grafana:
ports:
- '3000:3000'
container_name: grafana
image: grafana/grafana
剩下来的就是配置grafana的target,创建panel,编辑每一个监视unit了