Browse Source

Create prometheus user/group and define storage path

remove-logs
Andreas Linz 3 years ago
parent
commit
12b19566d4
4 changed files with 22 additions and 2 deletions
  1. +3
    -0
      roles/prometheus/defaults/main.yml
  2. +15
    -2
      roles/prometheus/tasks/main.yml
  3. +2
    -0
      roles/prometheus/templates/prometheus.service.tmpl
  4. +2
    -0
      roles/prometheus/templates/prometheus.yml.tmpl

+ 3
- 0
roles/prometheus/defaults/main.yml View File

@ -1,6 +1,9 @@
prometheus_path: /usr/bin/prometheus
prometheus_config_path: /etc/prometheus/config.yml
prometheus_port: 9090
prometheus_user: prometheus
prometheus_group: prometheus
prometheus_storage_path: /home/{{ prometheus_user }}/data
node_exporter_path: /usr/bin/node_exporter
node_exporter_port: 9091
node_exporter_address: "127.0.0.1:{{ node_exporter_port }}"

+ 15
- 2
roles/prometheus/tasks/main.yml View File

@ -1,18 +1,31 @@
- name: Build prometheus
command: make -C ./build/prometheus
delegate_to: localhost
- name: "Create user {{ prometheus_user }}"
user:
name: {{ prometheus_user }}
comment: "Prometheus run user"
append: true
group: {{ prometheus_group }}
shell: /bin/false
become: true
- name: Install prometheus
become: true
copy:
src: ./build/prometheus/prometheus
dest: "{{ prometheus_path }}"
mode: 0755
- name: Create prometheus folder
- name: Create prometheus folder paths
become: true
file:
path: /etc/prometheus
path: "{{ item }}"
state: directory
owner: "{{ prometheus_user }}"
group: "{{ prometheus_group }}"
mode: 0700
with_items:
- /etc/prometheus
- "{{ prometheus_storage_path }}"
- name: Install prometheus configuration
become: true
template:

+ 2
- 0
roles/prometheus/templates/prometheus.service.tmpl View File

@ -6,6 +6,8 @@ Wants=network-online.target systemd-networkd-wait-online.service
[Service]
Restart=on-abnormal
User={{ prometheus_user }}
Group={{ prometheus_group }}
ExecStart={{ prometheus_path }}\
-web.listen-address "127.0.0.1:{{ prometheus_port }}"\
-config.file {{ prometheus_config_path }}

+ 2
- 0
roles/prometheus/templates/prometheus.yml.tmpl View File

@ -9,6 +9,8 @@ global:
external_labels:
monitor: 'codelab-monitor'
storage.local.path: {{ prometheus_storage_path }}
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"

Loading…
Cancel
Save