diff --git a/docker-host/setup/files/services/node_exporter.service b/docker-host/setup/files/services/node_exporter.service new file mode 100644 index 0000000..b28b189 --- /dev/null +++ b/docker-host/setup/files/services/node_exporter.service @@ -0,0 +1,17 @@ +[Unit] +Description=Node Exporter which exposes host metrics for Prometheus +After=network.target + +[Service] +WorkingDirectory=/opt/prom-node-exporter +Type=simple +Restart=simple +Restart=always +Restart=10 +ExecStart=/opt/prom-node-exporter/node_exporter + +[Install] +WantedBy=multi-user.target + + + diff --git a/docker-host/setup/tasks/prometheus.yml b/docker-host/setup/tasks/prometheus.yml new file mode 100644 index 0000000..f7d3dfb --- /dev/null +++ b/docker-host/setup/tasks/prometheus.yml @@ -0,0 +1,63 @@ +--- +- hosts: leftcoastlab + vars: + PROM_URL: "https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz" + become: yes + tasks: + - name: Include Global Vars + include_vars: + dir: ../vars + +# - name: Download prometheus Node Explorer static binary tarball +# get_url: +# url: "{{ PROM_URL }}" +# dest: /tmp/prom-node-exporer.tar.gz +# +# - name: Untar node exporter tarball package +# unarchive: +# src: /tmp/prom-node-exporer.tar.gz +# dest: /opt/prom-node-exporter +# creates: /opt/prom-node-exporter +# remote_src: yes +# +# - name: Copy Unit file for node exporter +# copy: +# src: ../files/services/node_exporter.service +# dest: /etc/systemd/system/node_exporter.service +# +# - name: Install Node Exporter Service and Start +# systemd: +# daemon_reload: yes +# name: node_exporter +# state: restarted +# enabled: yes + + - name: Ensure Prom Docker Volume Exists + community.docker.docker_volume: + name: prometheus-volume + + - name: Ensure Config directory exists + file: + path: /opt/prometheus + state: directory + + - name: Copy Prometheus template to target directory + template: + dest: /opt/prometheus/prometheus.yml + src: ../templates/prometheus.yml.j2 + + - name: Setup Prometheus (Containerized) Service + community.docker.docker_container: + name: prometheus + image: prom/prometheus + pull: yes + restart_policy: always + recreate: yes + volumes: + - "prometheus-volume:/prometheus" + - "/opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml" + ports: + - "{{PROM_PORT}}:{{PROM_PORT}}" + + + diff --git a/docker-host/setup/templates/prometheus.yml.j2 b/docker-host/setup/templates/prometheus.yml.j2 new file mode 100644 index 0000000..662fd4a --- /dev/null +++ b/docker-host/setup/templates/prometheus.yml.j2 @@ -0,0 +1,26 @@ +global: + scrape_interval: 15s + scrape_timeout: 10s + evaluation_interval: 15s +alerting: + alertmanagers: + - follow_redirects: true + enable_http2: true + scheme: http + timeout: 10s + api_version: v2 + static_configs: + - targets: [] +scrape_configs: +- job_name: prometheus-scraper + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + follow_redirects: true + enable_http2: true + static_configs: + - targets: + - localhost:9090 + - "{{PRIVATE_IP}}":9100 diff --git a/docker-host/setup/vars/main.yml b/docker-host/setup/vars/main.yml index b63188d..7f52cad 100644 --- a/docker-host/setup/vars/main.yml +++ b/docker-host/setup/vars/main.yml @@ -7,3 +7,4 @@ FILEBROWSER_PORT: 8080 LOKI_PORT: 3100 GRAFANA_PORT: 6000 SUBSONIC_PORT: 4040 +PROM_PORT: 9090