From 4f15932d6ca1211eca29f17bed1a4a04bb23339c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannig=20Perr=C3=A9?= Date: Sat, 20 Nov 2021 15:11:13 +0100 Subject: [PATCH] :memo: Exemple chapitre 15 --- chapitre-15/blackbox.yml | 83 +++++++++++++++++++++++ chapitre-15/blackbox_exporter.service | 18 +++++ chapitre-15/prometheus.yml | 95 +++++++++++++++++++++++++++ chapitre-15/snmp_exporter.service | 18 +++++ 4 files changed, 214 insertions(+) create mode 100644 chapitre-15/blackbox.yml create mode 100644 chapitre-15/blackbox_exporter.service create mode 100644 chapitre-15/prometheus.yml create mode 100644 chapitre-15/snmp_exporter.service diff --git a/chapitre-15/blackbox.yml b/chapitre-15/blackbox.yml new file mode 100644 index 0000000..d56a314 --- /dev/null +++ b/chapitre-15/blackbox.yml @@ -0,0 +1,83 @@ +modules: + http_2xx: + prober: http + http: + preferred_ip_protocol: ipv4 + http_insecure_tls: + prober: http + http: + preferred_ip_protocol: ipv4 + tls_config: + insecure_skip_verify: true + http_post_2xx: + prober: http + http: + method: POST + tcp_connect: + prober: tcp + pop3s_banner: + prober: tcp + tcp: + query_response: + - expect: "^+OK" + tls: true + tls_config: + insecure_skip_verify: false + ssh_banner: + prober: tcp + tcp: + query_response: + - expect: "^SSH-2.0-" + - send: "SSH-2.0-blackbox-ssh-check" + irc_banner: + prober: tcp + tcp: + query_response: + - send: "NICK prober" + - send: "USER prober prober prober :prober" + - expect: "PING :([^ ]+)" + send: "PONG ${1}" + - expect: "^:[^ ]+ 001" + icmp: + prober: icmp + smtp_banner: + prober: tcp + timeout: 20s + tcp: + preferred_ip_protocol: ip4 + query_response: + - expect: "220.*ESMTP" + - send: "EHLO prober\r" + - expect: "250-Hello prober" + - send: "QUIT" + smtp_starttls: + prober: tcp + timeout: 2s + tcp: + preferred_ip_protocol: ip4 + query_response: + - expect: "220.*ESMTP" + - send: "EHLO prober" + - expect: "250" + - send: "STARTTLS" + - expect: "220" + - starttls: true + - send: "EHLO prober" + - expect: "250" + - send: "QUIT" + smtp_tls: + prober: tcp + timeout: 20s + tcp: + tls: true + preferred_ip_protocol: ip4 + query_response: + - expect: "220.*ESMTP" + - send: "EHLO prober\r" + - expect: "250-Hello prober" + - send: "QUIT" + tcp_tls: + prober: tcp + timeout: 20s + tcp: + tls: true diff --git a/chapitre-15/blackbox_exporter.service b/chapitre-15/blackbox_exporter.service new file mode 100644 index 0000000..e15d7f9 --- /dev/null +++ b/chapitre-15/blackbox_exporter.service @@ -0,0 +1,18 @@ +[Unit] +Description=Blackbox exporter for Prometheus +Documentation=http://prometheus.io +Wants=network-online.target + +[Service] +WorkingDirectory=/opt/blackbox_exporter +User=prometheus +Group=prometheus +Restart=on-failure +ExecReload=/bin/kill -HUP $MAINPID +ExecStart=/opt/blackbox_exporter/blackbox_exporter + +TimeoutStopSec=20 +UMask=0027 + +[Install] +WantedBy=multi-user.target diff --git a/chapitre-15/prometheus.yml b/chapitre-15/prometheus.yml new file mode 100644 index 0000000..85a309a --- /dev/null +++ b/chapitre-15/prometheus.yml @@ -0,0 +1,95 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + +alerting: + alertmanagers: + - static_configs: + #- targets: [ localhost:9093 ] + +rule_files: + - rules/*.yaml + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + - job_name: 'node' + static_configs: + - targets: ['localhost:9100'] + file_sd_configs: + - files: ['nodes/*.yaml'] + relabel_configs: + - source_labels: [__address__] + regex: '(xen-host-.*):(.*)' + target_label: xenhost + replacement: '$1' + - job_name: 'grafana' + static_configs: + - targets: ['localhost:3000'] + # - job_name: 'win-exporter' + # static_configs: + # - targets: ['windows:9182'] + # - job_name: 'postgres' + # static_configs: + # - targets: ['localhost:9187'] + # - job_name: 'mysql' + # static_configs: + # - targets: ['localhost:9104'] + - job_name: 'pushgateway' + honor_labels: true + static_configs: + - targets: ['localhost:9091'] + + - job_name: 'smtp_status' + metrics_path: /probe + params: + module: [smtp_banner] + static_configs: + - targets: [ 'localhost:1025' ] + relabel_configs: + Write target address in target parameter + - source_labels: [__address__] + target_label: __param_target + Make instance label the target + - source_labels: [__param_target] + target_label: instance + Actually talk to the blackbox exporter though + - target_label: __address__ + replacement: 127.0.0.1:9115 + + - job_name: 'blackbox' + metrics_path: /probe + params: + module: [http_2xx] + static_configs: + - targets: [ 'www.google.fr', "www.google.com", "prometheus.io" ] + relabel_configs: + # Write target address in target parameter + - source_labels: [__address__] + target_label: __param_target + # Make instance label the target + - source_labels: [__param_target] + target_label: instance + # Actually talk to the blackbox exporter though + - target_label: __address__ + replacement: 127.0.0.1:9115 + + - job_name: 'snmp' + metrics_path: /snmp + params: + module: [if_mib_mycommunity] + static_configs: + - targets: [ '192.168.0.40' ] + relabel_configs: + Write target address in target parameter + - source_labels: [__address__] + target_label: __param_target + Make instance label the target + - source_labels: [__param_target] + target_label: instance + Actually talk to the snmp exporter though + - target_label: __address__ + replacement: 127.0.0.1:9116 diff --git a/chapitre-15/snmp_exporter.service b/chapitre-15/snmp_exporter.service new file mode 100644 index 0000000..50a4616 --- /dev/null +++ b/chapitre-15/snmp_exporter.service @@ -0,0 +1,18 @@ +[Unit] +Description=SNMP exporter for Prometheus +Documentation=http://prometheus.io +Wants=network-online.target + +[Service] +WorkingDirectory=/opt/snmp_exporter +User=prometheus +Group=prometheus +Restart=on-failure +ExecReload=/bin/kill -HUP $MAINPID +ExecStart=/opt/snmp_exporter/snmp_exporter + +TimeoutStopSec=20 +UMask=0027 + +[Install] +WantedBy=multi-user.target