aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-03-05 22:33:19 -0500
committerMitch Riedstra <mitch@riedstra.us>2019-03-05 22:33:19 -0500
commita436d3d340a96d473c2b7c7a29cebd54367a60b4 (patch)
tree13059eb336ce2bd4ec25ec97c47d27e45006ee09
downloadprometheus-a436d3d340a96d473c2b7c7a29cebd54367a60b4.tar.gz
prometheus-a436d3d340a96d473c2b7c7a29cebd54367a60b4.tar.xz
Initial
-rw-r--r--defaults/main.yml20
-rw-r--r--tasks/main.yml85
-rw-r--r--tasks/main.yml.bak58
-rw-r--r--templates/prometheus/prometheus.yml53
-rw-r--r--templates/prometheus/runit/run5
-rw-r--r--templates/prometheus/systemd.unit15
6 files changed, 236 insertions, 0 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..634243f
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,20 @@
+---
+
+prometheus_ui_listen: ':9090'
+prometheus_home_dir: /var/lib/prometheus
+prometheus_data_dir: '{{prometheus_home_dir}}/data'
+prometheus_user: prometheus
+prometheus_version: "2.7.2"
+prometheus_os: "{{ansible_facts['system']|lower}}" # Should resolve to "linux"
+prometheus_checksum: fca1b17bef8bd19c2ad90caf13d7ffa85e8c4655aa03315fb5e228bd06c4e0ae
+prometheus_architecture: amd64
+# https://github.com/prometheus/prometheus/releases/download/v2.7.2/prometheus-2.7.2.linux-amd64.tar.gz
+prometheus_url: "https://github.com/prometheus/prometheus/releases/download/v{{prometheus_version}}/prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}.tar.gz"
+
+
+prometheus_netdata_hosts:
+ - localhost:19999
+
+# Only inserted into the template if defined
+# prometheus_netdata_tls_hosts:
+# - example.com:19443
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..10648a0
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,85 @@
+- name: Setup Prometheus User
+ user:
+ name: "{{prometheus_user}}"
+ home: "{{prometheus_home_dir}}"
+ state: present
+- set_fact: "prometheus_extract_dir=prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}"
+- name: Create configuration directory
+ file:
+ state: directory
+ dest: "{{prometheus_home_dir}}/conf"
+ mode: '0700'
+ owner: "{{prometheus_user}}"
+- name: Create Data directory
+ file:
+ state: directory
+ dest: "{{prometheus_data_dir}}"
+ mode: '0700'
+ owner: "{{prometheus_user}}"
+- name: Download Prometheus
+ get_url:
+ url: "{{prometheus_url}}"
+ dest: "{{prometheus_home_dir}}/prometheus-{{prometheus_version}}.tgz"
+ mode: '0600'
+ owner: "{{prometheus_user}}"
+# There's a bug in become_user that doesn't set permissions on the temp directory
+# which is asinine when my user has sudo persmissions.
+- name: Extract Prometheus
+ shell: |
+ if ! [ -e "{{prometheus_home_dir}}/{{prometheus_extract_dir}}" ] ; then
+ sudo su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
+ fi
+ changed_when: false
+- name: Link prometheus directory
+ file:
+ state: link
+ src: '{{prometheus_extract_dir}}'
+ dest: '{{prometheus_home_dir}}/prometheus'
+ force: yes
+- name: Link configuration files
+ file:
+ state: link
+ src: '../conf/{{item}}'
+ dest: '{{prometheus_home_dir}}/prometheus/{{item}}'
+ force: yes
+ loop:
+ - prometheus.yml
+- name: Write prometheus template
+ template:
+ src: prometheus/prometheus.yml
+ dest: '{{prometheus_home_dir}}/conf/prometheus.yml'
+ owner: '{{prometheus_user}}'
+ mode: '0600'
+- name: Write Systemd Unite
+ template:
+ src: prometheus/systemd.unit
+ dest: /etc/systemd/system/prometheus.service
+ when: ansible_facts['distribution'].lower() == "ubuntu"
+- name: 'Enable Prometheus [Ubuntu]'
+ systemd:
+ enabled: yes
+ daemon_reload: yes
+ name: prometheus
+ when: ansible_facts['distribution'].lower() == "ubuntu"
+- name: Create Runit Directory
+ file:
+ state: directory
+ dest: /etc/sv.local/prometheus
+ owner: root
+ group: adm
+ mode: '0755'
+ when: ansible_facts['distribution'].lower() == "void"
+- name: Write runit service
+ template:
+ src: prometheus/runit/run
+ dest: /etc/sv.local/prometheus/run
+ owner: root
+ group: adm
+ mode: '0755'
+ when: ansible_facts['distribution'].lower() == "void"
+- name: Enable Runit service
+ file:
+ state: link
+ src: /etc/sv.local/prometheus
+ dest: /var/service/prometheus
+ when: ansible_facts['distribution'].lower() == "void"
diff --git a/tasks/main.yml.bak b/tasks/main.yml.bak
new file mode 100644
index 0000000..587dfc5
--- /dev/null
+++ b/tasks/main.yml.bak
@@ -0,0 +1,58 @@
+- name: Setup Prometheus User
+ user:
+ name: "{{prometheus_user}}"
+ home: "{{prometheus_home_dir}}"
+ state: present
+- name: Get User home directory
+ shell: "awk -F: '{if($1==\"{{prometheus_user}}\"){print $6}}' /etc/passwd"
+ changed_when: false
+ register: get_home_command_output
+- set_fact: "prometheus_user_home={{get_home_command_output['stdout']}}"
+- set_fact: "prometheus_dir=prometheus-{{prometheus_version}}.{{prometheus_os}}-{{prometheus_architecture}}"
+- name: Create configuration directory
+ file:
+ state: directory
+ dest: "{{prometheus_user_home}}/conf"
+ mode: '0700'
+ owner: "{{prometheus_user}}"
+- name: Create Data directory
+ file:
+ state: directory
+ dest: "{{prometheus_data_dir}}"
+ mode: '0700'
+ owner: "{{prometheus_user}}"
+- name: Download Prometheus
+ get_url:
+ url: "{{prometheus_url}}"
+ dest: "{{prometheus_user_home}}/prometheus-{{prometheus_version}}.tgz"
+ mode: '0600'
+ owner: "{{prometheus_user}}"
+# There's a bug in become_user that doesn't set permissions on the temp directory
+# which is asinine when my user has sudo persmissions.
+- name: Extract Prometheus
+ shell: |
+ if ! [ -e "{{prometheus_user_home}}/{{prometheus_dir}}" ] ; then
+ sudo su - '{{prometheus_user}}' -c 'tar xzf prometheus-{{prometheus_version}}.tgz'
+ fi
+ changed_when: false
+- name: Link prometheus directory
+ file:
+ state: link
+ src: '{{prometheus_dir}}'
+ dest: '{{prometheus_user_home}}/prometheus'
+ force: yes
+- name: Link configuration files
+ file:
+ state: link
+ src: '../conf/{{item}}'
+ dest: '{{prometheus_user_home}}/prometheus/{{item}}'
+ force: yes
+ loop:
+ - prometheus.yml
+- name: Write prometheus template
+ template:
+ src: prometheus/prometheus.yml
+ dest: '{{prometheus_user_home}}/conf/prometheus.yml'
+ owner: '{{prometheus_user}}'
+ mode: '0600'
+
diff --git a/templates/prometheus/prometheus.yml b/templates/prometheus/prometheus.yml
new file mode 100644
index 0000000..2099b8b
--- /dev/null
+++ b/templates/prometheus/prometheus.yml
@@ -0,0 +1,53 @@
+# my global config
+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).
+
+# Alertmanager configuration
+alerting:
+ alertmanagers:
+ - static_configs:
+ - targets:
+ # - alertmanager:9093
+
+# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
+rule_files:
+ # - "first_rules.yml"
+ # - "second_rules.yml"
+
+# 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: 'prometheus'
+
+ # metrics_path defaults to '/metrics'
+ # scheme defaults to 'http'.
+
+ static_configs:
+ - targets: ['localhost:9090']
+
+ - job_name: 'netdata'
+
+ metrics_path: /api/v1/allmetrics
+ params:
+ format: [ prometheus ]
+
+ static_configs:
+{% for h in prometheus_netdata_hosts %} - targets: ['{{h}}']
+{%endfor%}
+
+{% if prometheus_netdata_tls_hosts is defined %}
+ - job_name: 'netdata_tls'
+
+ scheme: https
+
+ metrics_path: /api/v1/allmetrics
+ params:
+ format: [ prometheus ]
+
+ static_configs:
+{% for h in prometheus_netdata_tls_hosts %} - targets: ['{{h}}']
+{%endfor%}
+{% endif %}
diff --git a/templates/prometheus/runit/run b/templates/prometheus/runit/run
new file mode 100644
index 0000000..f70f1ae
--- /dev/null
+++ b/templates/prometheus/runit/run
@@ -0,0 +1,5 @@
+#!/bin/sh
+exec {{prometheus_home_dir}}/prometheus/prometheus \
+ --config.file "{{prometheus_home_dir}}/conf/prometheus.yml" \
+ --storage.tsdb.path "{{prometheus_data_dir}}" \
+ --web.listen-address "{{prometheus_ui_listen}}"
diff --git a/templates/prometheus/systemd.unit b/templates/prometheus/systemd.unit
new file mode 100644
index 0000000..856f299
--- /dev/null
+++ b/templates/prometheus/systemd.unit
@@ -0,0 +1,15 @@
+# /etc/systemd/system/prometheus.service
+[Unit]
+Description=Prometheus Server
+Documentation=https://prometheus.io/docs/introduction/overview/
+After=network-online.target
+
+[Service]
+User=prometheus
+Restart=on-failure
+ExecStart={{prometheus_home_dir}}/prometheus/prometheus \
+ --config.file "{{prometheus_home_dir}}/conf/prometheus.yml" \
+ --storage.tsdb.path "{{prometheus_data_dir}}" \
+ --web.listen-address "{{prometheus_ui_listen}}"
+[Install]
+WantedBy=multi-user.target