一、拉取镜像
docker pull prom/prometheus
二、配置
sudo mkdir /etc/prometheus/
sudo vim /etc/prometheus/prometheus.yml
添加监控节点
# 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). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: ‘codelab-monitor‘ # Load rules once and periodically evaluate them according to the global ‘evaluation_interval‘. rule_files: # - "first.rules" # - "second.rules" # 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: [‘172.17.0.1:9090‘] - job_name: ‘mysql‘ static_configs: - targets: [‘172.17.0.1:9104‘] labels: instance: mysql - job_name: ‘monitor‘ static_configs: - targets: [‘172.17.0.1:9100‘] labels: instance: monitor
启动prometheus
# 因为目录/data用户组和用户是jtserver,docker执行命令是root用户,先将/data/lib/prometheus给其他组权限才能执行 sudo mkdir /data/lib/prometheus sudo chmod 767 /data/lib/prometheus docker run -d -p 9090:9090 --restart=always --name prometheus -v /data/lib/prometheus:/data/lib/prometheus -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data/lib/prometheus
三、拉取node-exporter
docker pull prom/node-exporter
启动
docker run -d -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" --net="host" --restart=always prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
四、grafana
sudo apt-get install -y adduser libfontconfig1 wget https://dl.grafana.com/oss/release/grafana_6.7.2_amd64.deb sudo dpkg -i grafana_6.7.2_amd64.deb sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - # echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" sudo apt-get update sudo apt-get install grafana sudo update-rc.d grafana-server defaults
原文:https://www.cnblogs.com/f-society/p/13156826.html