Skip to content

Commit

Permalink
Added prometheus scrape_config_files support
Browse files Browse the repository at this point in the history
Signed-off-by: Zdeněk Bělehrádek <zdenek.belehradek@ataccama.com>
  • Loading branch information
Zdeněk Bělehrádek committed Feb 15, 2024
1 parent f189e53 commit 7b92cb4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions roles/prometheus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ prometheus_static_targets_files:
- prometheus/targets/*.yml
- prometheus/targets/*.json

prometheus_scrape_config_files:
- prometheus/targets/*.yml
- prometheus/targets/*.json

# yamllint disable rule:line-length
prometheus_alert_rules: # noqa yaml[line-length] # noqa line-length
- alert: Watchdog
Expand Down
8 changes: 8 additions & 0 deletions roles/prometheus/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ argument_specs:
default:
- "prometheus/targets/*.yml"
- "prometheus/targets/*.json"
prometheus_scrape_config_files:
description:
- "List of folders where ansible will look for files containing custom scrape config configuration files which will be copied to C({{ prometheus_config_dir }}/scrapes/)."
type: "list"
elements: "str"
default:
- "prometheus/scrapes/*.yml"
- "prometheus/scrapes/*.json"
prometheus_stop_timeout:
description:
- "How long to wait for Prometheus to shutdown. This is passed as a systemd TimeoutStopSec time spec."
Expand Down
10 changes: 10 additions & 0 deletions roles/prometheus/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@
group: prometheus
mode: 0640
with_fileglob: "{{ prometheus_static_targets_files }}"

- name: Copy prometheus scrape config files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ prometheus_config_dir }}/scrapes/"
force: true
owner: root
group: prometheus
mode: 0640
with_fileglob: "{{ prometheus_static_scrape_files }}"
1 change: 1 addition & 0 deletions roles/prometheus/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- "{{ prometheus_config_dir }}"
- "{{ prometheus_config_dir }}/rules"
- "{{ prometheus_config_dir }}/file_sd"
- "{{ prometheus_config_dir }}/scrapes"

- name: Get prometheus binary
when:
Expand Down
5 changes: 5 additions & 0 deletions roles/prometheus/templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ alerting:

scrape_configs:
{{ prometheus_scrape_configs | to_nice_yaml(indent=2,sort_keys=False) | indent(2,False) }}

{% if prometheus_scrape_config_files != [] %}
scrape_config_files:
{{ prometheus_scrape_config_files | to_nice_yaml(indent=2) | indent(2,False) }}
{% endif %}

0 comments on commit 7b92cb4

Please sign in to comment.