aboutsummaryrefslogtreecommitdiff
path: root/roles/monitoring/tasks
diff options
context:
space:
mode:
authorKumar Damani <me@kumardamani.net>2022-09-07 20:40:17 +0000
committerKumar Damani <me@kumardamani.net>2022-09-07 20:40:17 +0000
commitbbe10895d9df8dd7899bbd65575d5bf12e57f8c8 (patch)
tree244d2f1ad38320863fb60f695c88c97799be1171 /roles/monitoring/tasks
parent4d34de2f5e757bfeae5738547aabb61d3d28a2f8 (diff)
parentc85806e3289b5e207d51d382f8dc75edad04404d (diff)
Merge branch 'alpine' into 'master'
switched to alpine initial commit See merge request kdam0/vps!2
Diffstat (limited to 'roles/monitoring/tasks')
-rw-r--r--roles/monitoring/tasks/blackbox.yaml21
-rw-r--r--roles/monitoring/tasks/main.yaml19
-rw-r--r--roles/monitoring/tasks/node.yaml23
-rw-r--r--roles/monitoring/tasks/prometheus.yaml23
-rw-r--r--roles/monitoring/tasks/zfs.yaml49
5 files changed, 135 insertions, 0 deletions
diff --git a/roles/monitoring/tasks/blackbox.yaml b/roles/monitoring/tasks/blackbox.yaml
new file mode 100644
index 0000000..932b457
--- /dev/null
+++ b/roles/monitoring/tasks/blackbox.yaml
@@ -0,0 +1,21 @@
+---
+
+# Blackbox Exporter for service level monitoring
+- name: 'Copy the blackbox.yml config file to conf dir'
+ template:
+ src: 'blackbox.yml.j2'
+ dest: '{{ monitoring_root_dir }}/blackbox.yml'
+ mode: '0644'
+
+- name: 'Make sure the blackbox exporter container is created and running'
+ docker_container:
+ name: 'blackbox-exporter'
+ image: 'prom/blackbox-exporter:v0.22.0'
+ pull: true
+ state: 'started'
+ recreate: true
+ command: '--config.file=/config/blackbox.yml'
+ volumes:
+ - "{{ monitoring_root_dir }}/blackbox.yml:/config/blackbox.yml"
+ network_mode: 'host'
+ restart_policy: unless-stopped
diff --git a/roles/monitoring/tasks/main.yaml b/roles/monitoring/tasks/main.yaml
new file mode 100644
index 0000000..268659b
--- /dev/null
+++ b/roles/monitoring/tasks/main.yaml
@@ -0,0 +1,19 @@
+---
+
+- name: 'Ensure monitoring root dir exists'
+ file:
+ path: '{{ monitoring_root_dir }}'
+ state: 'directory'
+ mode: '755'
+
+- name: 'Setup the Node Exporter'
+ import_tasks: 'node.yaml'
+
+- name: 'Setup the Blackbox Exporter'
+ import_tasks: 'blackbox.yaml'
+
+- name: 'Setup the ZFS Exporter'
+ import_tasks: 'zfs.yaml'
+
+- name: 'Setup Prometheus'
+ import_tasks: 'prometheus.yaml'
diff --git a/roles/monitoring/tasks/node.yaml b/roles/monitoring/tasks/node.yaml
new file mode 100644
index 0000000..5d38f1f
--- /dev/null
+++ b/roles/monitoring/tasks/node.yaml
@@ -0,0 +1,23 @@
+# https://www.robustperception.io/temperature-and-hardware-monitoring-metrics-from-the-node-exporter/
+---
+
+# Need to install lm-sensors lm-sensors-detect
+# Run sensors, for configurations.
+
+# Node Exporter for OS level monitoring is recommneded to be installed w/o Docker.
+- block:
+ - name: 'Install node-exporter'
+ become: true
+ become_method: 'doas'
+ package:
+ name: 'prometheus-node-exporter'
+ state: 'present'
+
+ - name: 'Start and enable node-exporter service'
+ become: true
+ become_method: 'doas'
+ service:
+ name: 'node-exporter'
+ state: 'started'
+ enabled: true
+ when: 'ansible_os_family == "Alpine"'
diff --git a/roles/monitoring/tasks/prometheus.yaml b/roles/monitoring/tasks/prometheus.yaml
new file mode 100644
index 0000000..0fbfd89
--- /dev/null
+++ b/roles/monitoring/tasks/prometheus.yaml
@@ -0,0 +1,23 @@
+---
+
+# Install Prometheus as TSDB for monitoring metrics
+- name: 'Copy the prometheus.yml config file to conf dir'
+ template:
+ src: 'prometheus.yml.j2'
+ dest: '{{ monitoring_root_dir }}/prometheus.yml'
+ mode: '0644'
+
+- name: 'Make sure prometheus container is created and running'
+ docker_container:
+ name: 'prometheus'
+ image: 'prom/prometheus:v2.37.0'
+ pull: true
+ state: 'started'
+ recreate: true
+ command: '--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus'
+ user: 'root'
+ volumes:
+ - "{{ monitoring_root_dir }}/prometheus.yml:/etc/prometheus/prometheus.yml"
+ - "{{ monitoring_root_dir }}/prom_data:/data/prometheus"
+ network_mode: 'host'
+ restart_policy: unless-stopped
diff --git a/roles/monitoring/tasks/zfs.yaml b/roles/monitoring/tasks/zfs.yaml
new file mode 100644
index 0000000..2f18e32
--- /dev/null
+++ b/roles/monitoring/tasks/zfs.yaml
@@ -0,0 +1,49 @@
+# https://github.com/pdf/zfs_exporter
+
+---
+
+# ZFS Exporter for ZFS monitoring
+
+- name: 'Download zfs exporter tarball'
+ get_url:
+ url: 'https://github.com/pdf/zfs_exporter/releases/download/v2.2.5/zfs_exporter-2.2.5.linux-arm64.tar.gz'
+ dest: '{{ monitoring_root_dir }}/zfs_exporter.tar.gz'
+ mode: '644'
+
+- name: 'Ensure the zfs exporter dir exists'
+ file:
+ path: '{{ monitoring_root_dir }}/zfs_exporter-2.2.5.linux-arm64'
+ state: 'directory'
+ mode: '755'
+
+- name: 'Extract ZFS exporter to dir'
+ command: 'tar -xf zfs_exporter-2.2.5.linux-arm64.tar.gz'
+ args:
+ chdir: '{{ monitoring_root_dir }}'
+
+- name: 'Copy the executable to /usr/bin'
+ become: true
+ become_method: 'doas'
+ copy:
+ src: '{{ monitoring_root_dir }}/zfs_exporter-2.2.5.linux-arm64/zfs_exporter'
+ dest: '/usr/bin/zfs_exporter'
+ mode: '0755'
+ owner: 'root'
+ remote_src: true
+
+- name: 'Create service file to start zfs_exporter on boot'
+ become: true
+ become_method: 'doas'
+ copy:
+ src: 'zfs-exporter'
+ dest: '/etc/init.d/zfs-exporter'
+ mode: '0755'
+ owner: 'root'
+
+- name: 'Start and enable the zfs-exporter service'
+ become: true
+ become_method: 'doas'
+ service:
+ name: 'zfs-exporter'
+ state: 'started'
+ enabled: true