docker-prometheus.yml
约 348 字大约 1 分钟
docker-prometheus.yml
注意,数据库提前建好grafana 库:
create database grafana default character set utf8mb4 collate utf8mb4_unicode_ci;
version: "3.5"
services:
prometheus:
image: prom/prometheus:v2.30.0
container_name: prometheus
volumes:
- /opt/docker/prom/prometheus/tmp:/tmp
- /opt/docker/prom/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
command: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --storage.tsdb.wal-compression --storage.tsdb.retention.time=7d"
hostname: prometheus
restart: unless-stopped
ports:
- "11190:9090"
depends_on:
- exporter
alertmanager:
image: prom/alertmanager
container_name: alertmanager
hostname: alertmanager
restart: always
ports:
- "11193:9093"
cadvisor:
image: google/cadvisor:latest
container_name: cadvisor
hostname: cadvisor
restart: always
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
ports:
- "11180:8080"
prometheus-nacos-sd:
image: nien/prometheus-nacos-sd:1.0.0
container_name: prometheus-nacos-sd
hostname: prometheus-nacos-sd
restart: unless-stopped
volumes:
- /opt/docker/prom/prometheus_nacos_sd/tmp:/tmp
command: "--nacos.address=172.17.0.1:8848 --nacos.namespace=public --output.file=/tmp/nacos_sd_public.json --refresh.interval=600"
exporter:
image: prom/node-exporter:v1.2.2
container_name: exporter
restart: unless-stopped
hostname: exporter
ports:
- "11191:9100"
# 用于UI展示
# https://grafana.com/docs/grafana/latest/installation/docker
grafana:
image: grafana/grafana:8.1.5
container_name: grafana
hostname: grafana
restart: unless-stopped
ports:
- "11130:3000"
# volumes:
# - "/opt/docker/prom/grafana/grafana.ini:/etc/grafana/grafana.ini" # 邮箱配置
# - "/opt/docker/prom/grafana/grafana-storage:/var/lib/grafana"
# - "/opt/docker/prom/grafana/public:/usr/share/grafana/public" # 这里面可处理汉化包 可参考 https://github.com/WangHL0927/grafana-chinese
# - "/opt/docker/prom/grafana/conf:/usr/share/grafana/conf"
# - "/opt/docker/prom/grafana/log:/var/log/grafana"
# - "/etc/localtime:/etc/localtime"
environment:
GF_EXPLORE_ENABLED: "true"
GF_SECURITY_ADMIN_PASSWORD: "admin"
GF_INSTALL_PLUGINS: "grafana-clock-panel,grafana-simple-json-datasource,alexanderzobnin-zabbix-app"
# 持久化到mysql数据库
GF_DATABASE_URL: "mysql://root:123456@172.17.0.1:3306/grafana" # TODO修改
depends_on:
- prometheus
networks:
default:
external:
name: mkdtbs
prometheus.yml
# 可参考 https://prometheus.io/docs/prometheus/latest/getting_started
global:
scrape_interval: 15s
scrape_timeout: 15s
evaluation_interval: 10m
scrape_configs:
# springboot项目
- job_name: spring-boot
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /actuator/prometheus
scheme: http
basic_auth:
username: admin
password: 123456
static_configs:
- targets:
- 192.168.101.88:9200 # TODO 此处填写SpringBoot应用的IP+端口号
# cadvisor
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8899']
# prometheus
- job_name: prometheus
static_configs:
- targets: ['prometheus:9090']
labels:
instance: prometheus
# 采集node exporter监控数据,即linux
- job_name: linux
static_configs:
- targets: ['exporter:9100']
labels:
instance: localhost