Skip to content

Commit

Permalink
Add pushgateway service
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-poskus committed Sep 17, 2017
1 parent 27ec27d commit 1cd0687
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Playbook installs and manages services using systemd. Currently supported:
- Prometheus
- Node Exporter (collects metrics of host machine)
- Alert manager
- Push gateway

Playbook includes extensive configuration options check default/main.yml

Expand Down Expand Up @@ -360,6 +361,21 @@ prometheus_alert_manager_web__listen_address: ':9093'
prometheus_alert_manager_web__route_prefix:
# Prefix for the internal routes of web endpoints. Defaults to path of -web.external-url.

# Pushgateway
# https://github.com/prometheus/pushgateway

prometheus_push_gateway_log__format:
# If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
prometheus_push_gateway_log__level: 'info'
# Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
prometheus_push_gateway_persistence__file:
# File to persist metrics. If empty, metrics are only kept in memory.
prometheus_push_gateway_persistence__interval:
# The minimum interval at which to write out the persistence file. (default 5m0s)
prometheus_push_gateway_web__listen_address: ':9091'
# Address to listen on for the web interface, API, and telemetry. (default ":9091")
prometheus_push_gateway_web__telemetry_path: '/metrics'
# Path under which to expose metrics. (default "/metrics")
```

Dependencies
Expand Down
19 changes: 19 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
prometheus_install: true
prometheus_node_exporter_install: true
prometheus_alert_manager_install: true
prometheus_push_gateway_install: false

prometheus_owner: 'prometheus'
prometheus_group: 'prometheus'
Expand All @@ -28,6 +29,9 @@ prometheus_node_exporter_version: '0.14.0'
# Alert manager
prometheus_alert_manager_version: '0.8.0'

# Pushgateway
prometheus_push_gateway_version: '0.4.0'

# Prometheus
# https://prometheus.io/docs/operating/configuration/

Expand Down Expand Up @@ -332,3 +336,18 @@ prometheus_alert_manager_web__listen_address: ':9093'
prometheus_alert_manager_web__route_prefix:
# Prefix for the internal routes of web endpoints. Defaults to path of -web.external-url.

# Pushgateway
# https://github.com/prometheus/pushgateway

prometheus_push_gateway_log__format:
# If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
prometheus_push_gateway_log__level: 'info'
# Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
prometheus_push_gateway_persistence__file:
# File to persist metrics. If empty, metrics are only kept in memory.
prometheus_push_gateway_persistence__interval:
# The minimum interval at which to write out the persistence file. (default 5m0s)
prometheus_push_gateway_web__listen_address: ':9091'
# Address to listen on for the web interface, API, and telemetry. (default ":9091")
prometheus_push_gateway_web__telemetry_path: '/metrics'
# Path under which to expose metrics. (default "/metrics")
9 changes: 9 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@

- name: start alertmanager
service: name=alertmanager state=started

- name: restart pushgateway
service: name=pushgateway state=restarted enabled=yes

- name: stop pushgateway
service: name=pushgateway state=stopped

- name: start pushgateway
service: name=pushgateway state=started
16 changes: 15 additions & 1 deletion parse_config.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
input = <<eos
-log.format value
If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
-log.level value
Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
-persistence.file string
File to persist metrics. If empty, metrics are only kept in memory.
-persistence.interval duration
The minimum interval at which to write out the persistence file. (default 5m0s)
-version
Print version information.
-web.listen-address string
Address to listen on for the web interface, API, and telemetry. (default ":9091")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
eos

PREFIX = 'prometheus_alert_manager'
PREFIX = 'prometheus_push_gateway'

puts '############################################################'
puts '# Auto generated'
Expand Down
16 changes: 16 additions & 0 deletions tasks/install-push_gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Download and extract Prometheus push gateway tarball
unarchive:
src: "{{ prometheus_push_gateway_tarball_url }}"
dest: "{{ prometheus_install_dir }}"
owner: "{{ prometheus_owner }}"
group: "{{ prometheus_group }}"
copy: no
creates: "{{ prometheus_install_dir }}/{{ prometheus_push_gateway_archive }}"

- name: Install Prometheus push gateway systemd service
template:
src: push_gateway.service.j2
dest: /etc/systemd/system/pushgateway.service
notify:
- reload daemon
- restart pushgateway
5 changes: 5 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- include_vars: 'nodeexporter.yml'
- include_vars: 'prometheus.yml'
- include_vars: 'alertmanager.yml'
- include_vars: 'pushgateway.yml'

- name: Create Prometheus group
group:
Expand Down Expand Up @@ -52,3 +53,7 @@
- name: Install Prometheus alert manager
include: install-alert_manager.yml
when: prometheus_alert_manager_install

- name: Install Pushgateway
include: install-push_gateway.yml
when: prometheus_push_gateway_install
20 changes: 20 additions & 0 deletions templates/push_gateway.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# {{ansible_managed}}

[Unit]
Description=Prometheus alert manager service
After=network.target
Wants=network.target

[Service]
ExecStart={{ prometheus_install_dir }}/{{ prometheus_push_gateway_archive }}/pushgateway {% for config in prometheus_push_gateway_service_config if config[1] is not none %}-{{ config[0] }}={{ config[1] }} {% endfor %}

Restart=always
RestartSec=20
TimeoutSec=300
User={{prometheus_owner}}
Group={{prometheus_group}}
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
6 changes: 5 additions & 1 deletion tests/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
- hosts: localhost
remote_user: root
roles:
- role: role_under_test
- role: role_under_test
prometheus_install: true
prometheus_node_exporter_install: true
prometheus_alert_manager_install: true
prometheus_push_gateway_install: true
9 changes: 9 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
register: command_result
failed_when: "'disabled' in command_result.stdout"

- name: Check if push gateway service is enabled
command: systemctl is-enabled pushgateway
register: command_result
failed_when: "'disabled' in command_result.stdout"

- shell: "systemctl status prometheus | grep -i running"
register: status
failed_when: status.rc != 0
Expand All @@ -29,3 +34,7 @@
- shell: "systemctl status alertmanager | grep -i running"
register: status
failed_when: status.rc != 0

- shell: "systemctl status pushgateway | grep -i running"
register: status
failed_when: status.rc != 0
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ prometheus_node_exporter_tarball_url: "https://github.com/prometheus/node_export

prometheus_alert_manager_archive: "alertmanager-{{ prometheus_alert_manager_version }}.{{ prometheus_platform_architecture }}"
prometheus_alert_manager_tarball_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ prometheus_alert_manager_version }}/{{ prometheus_alert_manager_archive }}.tar.gz"

prometheus_push_gateway_archive: "pushgateway-{{ prometheus_push_gateway_version }}.{{ prometheus_platform_architecture }}"
prometheus_push_gateway_tarball_url: "https://github.com/prometheus/pushgateway/releases/download/v{{ prometheus_push_gateway_version }}/{{ prometheus_push_gateway_archive }}.tar.gz"
10 changes: 10 additions & 0 deletions vars/pushgateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
############################################################
# Auto generated
############################################################
prometheus_push_gateway_service_config:
- ['log.format', "{{ prometheus_push_gateway_log__format }}"]
- ['log.level', "{{ prometheus_push_gateway_log__level }}"]
- ['persistence.file', "{{ prometheus_push_gateway_persistence__file }}"]
- ['persistence.interval', "{{ prometheus_push_gateway_persistence__interval }}"]
- ['web.listen-address', "{{ prometheus_push_gateway_web__listen_address }}"]
- ['web.telemetry-path', "{{ prometheus_push_gateway_web__telemetry_path }}"]

0 comments on commit 1cd0687

Please sign in to comment.