From 39d281a300541d2a10c8eeef6a233f2b0506acdb Mon Sep 17 00:00:00 2001 From: Ludovic Cartier Date: Fri, 11 Nov 2022 17:32:23 +0100 Subject: [PATCH] add memcached exporter - first draft --- tasks/memcached_exporter.yml | 52 +++++++++++++++++++ templates/conf/prometheus.yml.j2 | 17 ++++++ .../prometheus-memcached-exporter.service.j2 | 11 ++++ 3 files changed, 80 insertions(+) create mode 100644 tasks/memcached_exporter.yml create mode 100644 templates/systemd/prometheus-memcached-exporter.service.j2 diff --git a/tasks/memcached_exporter.yml b/tasks/memcached_exporter.yml new file mode 100644 index 0000000..ec3751c --- /dev/null +++ b/tasks/memcached_exporter.yml @@ -0,0 +1,52 @@ +--- +- name: 'prometheus | memcached exporter | get latest release from GitHub' + shell: curl --silent "https://api.github.com/repos/prometheus/memcached_exporter/releases/latest" | jq -r .tag_name | sed "s/v//" + args: + warn: false + register: prometheus_memcached_exporter_latest_version + run_once: true + +- name: 'prometheus | memcached exporter | download' + get_url: + url: https://github.com/prometheus/memcached_exporter/releases/download/v{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}/memcached_exporter-v{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64.tar.gz + dest: /tmp + +- name: 'prometheus | memcached exporter | unarchive' + unarchive: + remote_src: yes + src: /tmp/memcached_exporter-v{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64.tar.gz + dest: /tmp + +- name: 'prometheus | memcached exporter | move to /usr/local/bin' + copy: + src: /tmp/memcached_exporter-v{{ prometheus_memcached_exporter_version|default(prometheus_memcached_exporter_latest_version.stdout) }}.linux-amd64/memcached_exporter + dest: /usr/local/bin/prometheus-memcached-exporter + remote_src: yes + owner: root + group: root + mode: 0755 + +- name: 'prometheus | memcached exporter | install unit file to systemd' + template: + src: systemd/prometheus-memcached-exporter.service.j2 + dest: /etc/systemd/system/prometheus-memcached-exporter.service + owner: root + group: root + mode: 0600 + +# - name: 'prometheus | memcached exporter | configuration' +# template: +# src: conf/prometheus-memcached-exporter.j2 +# dest: /etc/default/prometheus-memcached-exporter +# owner: root +# group: root +# mode: 0600 +# register: prometheus_memcached_exporter_configuration +# notify: +# - 'prometheus | memcached exporter | restart service' + +- name: 'prometheus | memcached exporter | configure systemd to use service' + systemd: + daemon_reload: yes + enabled: yes + name: prometheus-memcached-exporter.service diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 0176e91..dd57e88 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -321,3 +321,20 @@ scrape_configs: - {{ target }} {% endfor %} {% endif %} + +{% if prometheus_memcached_exporter_targets is defined %} + # Memcached exporter # + - job_name: memcached + scrape_interval: 30s + scrape_timeout: 10s + static_configs: + - targets: +{% for target in prometheus_memcached_exporter_targets %} + - {{ target }}:9150 +{% endfor %} + relabel_configs: + - source_labels: [ __address__ ] + target_label: instance + regex: '(.*):9150' + replacement: '${1}' +{% endif %} diff --git a/templates/systemd/prometheus-memcached-exporter.service.j2 b/templates/systemd/prometheus-memcached-exporter.service.j2 new file mode 100644 index 0000000..c3cca33 --- /dev/null +++ b/templates/systemd/prometheus-memcached-exporter.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Prometheus Memcached Exporter +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/prometheus-memcached-exporter +EnvironmentFile=/etc/default/prometheus-memcached-exporter + +[Install] +WantedBy=multi-user.target