docker

Docker for services
git clone git://git.unixkoans.com/docker.git
Log | Files | Refs

commit 4cea88b009a23d3cca8ba120bade192aab83e933
parent 2c73450a50d5c01973a459d465e6e4aaaef5a99b
Author: Xiaodong Xu <xxdlhy@gmail.com>
Date:   Wed Jun 20 15:46:34 +0800

Add Prometheus and Grafana

Diffstat:
monitor/client/docker-compose.yml | 21+++++++++++++++++++++
monitor/server/blackbox.yml | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
monitor/server/docker-compose.yml | 37+++++++++++++++++++++++++++++++++++++
monitor/server/prometheus.yml | 39+++++++++++++++++++++++++++++++++++++++
4 files changed, 209 insertions(+), 0 deletions(-)
diff --git a/monitor/client/docker-compose.yml b/monitor/client/docker-compose.yml @@ -0,0 +1,21 @@ +version: '2' + +services: + cadvisor: + image: google/cadvisor + restart: always + ports: + - 9002:8080 + volumes: + - /var/run:/var/run:rw + - /sys:/sys:ro + - /dev/disk/:/dev/disk:ro + node-exporter: + image: prom/node-exporter + restart: always + ports: + - 9003:9100 + volumes: + - /proc:/host/proc:ro + - /sys:/host/sys:ro + command: "--collector.procfs /host/proc --collector.sysfs /host/sys --collector.filesystem.ignored-mount-points '^/(sys|proc|dev|host|etc)($$|/)'" diff --git a/monitor/server/blackbox.yml b/monitor/server/blackbox.yml @@ -0,0 +1,112 @@ +modules: + http_2xx: + prober: http + timeout: 5s + http: + valid_http_versions: ["HTTP/1.1", "HTTP/2"] + valid_status_codes: [] # Defaults to 2xx + method: GET + #headers: + # Host: vhost.example.com + # Accept-Language: en-US + no_follow_redirects: false + fail_if_ssl: false + fail_if_not_ssl: false + fail_if_matches_regexp: + - "Could not connect to database" + fail_if_not_matches_regexp: + - "Download the latest version here" + tls_config: + insecure_skip_verify: false + preferred_ip_protocol: "ip4" # defaults to "ip6" + http_post_2xx: + prober: http + timeout: 5s + http: + method: POST + headers: + Content-Type: application/json + body: '{}' + http_basic_auth: + prober: http + timeout: 5s + http: + method: POST + headers: + Host: "login.example.com" + basic_auth: + username: "username" + password: "mysecret" + tls_connect: + prober: tcp + timeout: 5s + tcp: + tls: true + tcp_connect: + prober: tcp + timeout: 5s + imap_starttls: + prober: tcp + timeout: 5s + tcp: + query_response: + - expect: "OK.*STARTTLS" + - send: ". STARTTLS" + - expect: "OK" + - starttls: true + - send: ". capability" + - expect: "CAPABILITY IMAP4rev1" + smtp_starttls: + prober: tcp + timeout: 5s + tcp: + query_response: + - expect: "^220 ([^ ]+) ESMTP (.+)$" + - send: "EHLO prober" + - expect: "^250-STARTTLS" + - send: "STARTTLS" + - expect: "^220" + - starttls: true + - send: "EHLO prober" + - expect: "^250-AUTH" + - send: "QUIT" + irc_banner: + prober: tcp + timeout: 5s + tcp: + query_response: + - send: "NICK prober" + - send: "USER prober prober prober :prober" + - expect: "PING :([^ ]+)" + send: "PONG ${1}" + - expect: "^:[^ ]+ 001" + icmp: + prober: icmp + timeout: 5s + icmp: + preferred_ip_protocol: "ip4" + dns_udp: + prober: dns + timeout: 5s + dns: + query_name: "www.prometheus.io" + query_type: "A" + valid_rcodes: + - NOERROR + validate_answer_rrs: + fail_if_matches_regexp: + - ".*127.0.0.1" + fail_if_not_matches_regexp: + - "www.prometheus.io.\t300\tIN\tA\t127.0.0.1" + validate_authority_rrs: + fail_if_matches_regexp: + - ".*127.0.0.1" + validate_additional_rrs: + fail_if_matches_regexp: + - ".*127.0.0.1" + dns_tcp: + prober: dns + dns: + transport_protocol: "tcp" # defaults to "udp" + preferred_ip_protocol: "ip4" # defaults to "ip6" + query_name: "www.prometheus.io" diff --git a/monitor/server/docker-compose.yml b/monitor/server/docker-compose.yml @@ -0,0 +1,37 @@ +version: '2' +services: + + grafana: + image: grafana/grafana + restart: always + ports: + - 9000:3000 + volumes: + - ./data/grafana:/var/lib/grafana + environment: + - GF_SECURITY_ADMIN_PASSWORD=jZFEnD49nZZT3Dp6 + - GF_USERS_ALLOW_SIGN_UP=false + #- GF_SMTP_ENABLED=true + #- GF_SMTP_FROM_ADDRESS= + #- GF_SMTP_FROM_NAME=Selfhost Monitor + #- GF_SMTP_HOST=smtp.exmail.qq.com:465 + #- GF_SMTP_USER= + #- GF_SMTP_PASSWORD= + + prometheus: + image: prom/prometheus + command: -config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -web.console.libraries=/usr/share/prometheus/console_libraries -web.console.templates=/usr/share/prometheus/consoles -storage.local.target-heap-size=1073741824 + restart: always + ports: + - 9001:9090 + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro + - ./data/prometheus:/prometheus + links: + - blackbox_exporter + + blackbox_exporter: + image: prom/blackbox-exporter + restart: always + volumes: + - ./blackbox.yml:/etc/blackbox_exporter/config.yml:ro diff --git a/monitor/server/prometheus.yml b/monitor/server/prometheus.yml @@ -0,0 +1,39 @@ +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: monitor + static_configs: + - targets: + - localhost:9002 + + - job_name: 'blackbox' + metrics_path: /probe + params: + module: [http_2xx] + static_configs: + - targets: + - http://api.domainname.com + - https://api.domainname.com + relabel_configs: + - source_labels: [__address__] + target_label: __param_target + - source_labels: [__param_target] + target_label: instance + - target_label: __address__ + replacement: blackbox_exporter:9115