Skip to content

Commit

Permalink
Add extras directory to prometheus config
Browse files Browse the repository at this point in the history
All files within the directory are recursively templated. This provides
a mechanism to include extra files that you can reference in
prometheus.yml, for example:

scape_targets:
  - job_name: ipmi
    params:
      module: default
    scrape_interval: 1m
    scrape_timeout: 30s
    metrics_path: /ipmi
    scheme: http
    file_sd_configs:
    - files:
      - /etc/prometheus/extras/file_sd/ipmi-exporter-targets.yml
      refresh_interval: 5m

Change-Id: Ie2f085204b71725b901a179ee51541f1f383c6fa
(cherry picked from commit cf6ef62)
  • Loading branch information
jovial committed Oct 15, 2019
1 parent 44e1f93 commit 8ea87b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions ansible/roles/prometheus/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- service.enabled | bool
- config_json.changed | bool
or prometheus_confs.changed | bool
or prometheus_extra_confs.changed | bool
or prometheus_alerting_rules.changed | bool
or prometheus_container.changed | bool

Expand Down
46 changes: 46 additions & 0 deletions ansible/roles/prometheus/tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,52 @@
notify:
- Restart prometheus-jiralert container

- block:
- name: Find extra prometheus server config files
become: true
local_action:
module: find
paths: "{{ node_custom_config }}/prometheus/extras/"
patterns: "*"
recurse: true
register: prometheus_config_extras_result
run_once: true

- name: Create subdirectories for extra config files
become: true
vars:
dirs: >-
{{ prometheus_config_extras_result.files | default([])
| map(attribute='path') | map('dirname') | unique
| map('relpath', base) | list }}
file:
path: "{{ node_config_directory }}/prometheus-server/{{ item }}"
state: "directory"
owner: "{{ config_owner_user }}"
group: "{{ config_owner_group }}"
mode: "0770"
recurse: true
with_items: "{{ dirs }}"

- name: Template extra prometheus server config files
become: true
vars:
relpath: "{{ item | relpath(base) }}"
template:
src: "{{ item }}"
dest: "{{ node_config_directory }}/prometheus-server/{{ relpath }}"
mode: "0660"
with_items: "{{ prometheus_config_extras_result.files | default([]) | map(attribute='path') | list }}"
register: prometheus_extra_confs
notify:
- Restart prometheus-server container
vars:
base: "{{ node_custom_config }}/prometheus/extras/"
service: "{{ prometheus_services['prometheus-server']}}"
when:
- inventory_hostname in groups[service.group]
- service.enabled | bool

- name: Check prometheus containers
become: true
kolla_docker:
Expand Down

0 comments on commit 8ea87b4

Please sign in to comment.