All components are activated to form the container, part of the startup file reference prometheus for swarm
Prometheus deployment
Write startup files
$ mkdir -p /opt/k8s/prometheus/conf $ cd /opt/k8s/prometheus/ $ cat > prome-stack.yml<<EOF version: "3" services: prometheus: image: prom/prometheus:v2.16.0 ports: - "9090:9090" volumes: - ./conf/:/etc/prometheus/ - prometheus_data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - '--web.console.libraries=/usr/share/prometheus/console_libraries' - '--web.console.templates=/usr/share/prometheus/consoles' networks: - mcsas-network deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: - node.role == manager networks: mcsas-network: external: true volumes: prometheus_data: {} EOF
Edit Profile
$ cd /opt/k8s/prometheus/prom/conf/ $ cat > prometheus.yml<<EOF global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'springboot' metrics_path: /actuator/prometheus file_sd_configs: - files: - /etc/prometheus/service.yaml - job_name: 'node-exporter' scrape_interval: 5s dns_sd_configs: - names: - 'tasks.node-exporter' type: 'A' port: 9100 - job_name: 'cadvisor' scrape_interval: 5s dns_sd_configs: - names: - 'tasks.cadvisor' type: 'A' port: 8080 EOF
- Of node-exporter, cadvisor using dns service discovery form
- For system applications using file_sd_configs, through conf / service.yaml in configuration to the service we provide prometheus monitor
- Because Prometheus no specific swarm of service discovery component, corresponding to the file manually in file_sd_configs added, there is a program on the official Prometheus specific reference prometheus-swarm-discovery
Start prometheus
$ cd /opt/k8s/prometheus/prom $ docker stack deploy -c prome-stack.yml prom
Deployment of node-exporter
Node-Exporter is not designed for the Mac platform, system-related information running on a Mac is not collected properly, if the platform is Mac, do not deploy this component
$ cd /opt/k8s/prometheus $ cat > node-exporter-stack.yml<<EOF version: "3" services: node-exporter: image: quay.azk8s.cn/prometheus/node-exporter:v0.18.1 volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro command: - '--path.procfs=/host/proc' - '--path.sysfs=/host/sys' - --collector.filesystem.ignored-mount-points - "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)" #ports: # - 9100:9100 networks: - mcsas-network deploy: mode: global restart_policy: condition: on-failure networks: mcsas-network: external: true EOF
Start node-exporter
$ cd /opt/k8s/prometheus $ docker stack deploy -c node-exporter-stack.yml node
Deployment cadvisor
$ cd /opt/k8s/prometheus $ cat > cadvisor-stack.yml<<EOF version: "3" services: cadvisor: image: gcr.azk8s.cn/google_containers/cadvisor:v0.35.0 volumes: - /:/rootfs:ro - /var/run:/var/run:rw - /sys:/sys:ro - /var/lib/docker/:/var/lib/docker:ro #ports: # - 8080:8080 networks: - mcsas-network deploy: mode: global restart_policy: condition: on-failure networks: mcsas-network: external: true EOF
- About Mirror: google / cadvisor has not recommended re-use, the new image is no longer updated, use gcr.io/google-containers/cadvisor, but the country did not send download, replaced download from gcr.azk8s.cn
Start cadvisor
$ docker stack deploy -c cadvisor-stack.yml cadvisor
Department grafana
$ cd /opt/k8s/prometheus $ cat > grafana-stack.yml<<EOF version: "3" services: grafana: image: grafana/grafana:6.6.2 volumes: - grafana-data:/var/lib/grafana deploy: replicas: 1 restart_policy: condition: on-failure resources: limits: cpus: "0.2" memory: 200M ports: - 3000:3000 networks: - mcsas-network volumes: grafana-data: {} networks: mcsas-network: external: true EOF
Start grafana
$ docker stack deploy -c grafana-stack.yml grafana
Deployment assembly completed, the specific steps performed on dashboard indicator arranged in monitoring grafana reference Prometheus grafana installation