add memcached_exporter (#1)
* add memcached_exporter * remove user/group and add consul service * fix consul tags * unpack bin from tarball Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
3568c975d1
commit
c2ce8b4287
14
README.md
14
README.md
|
@ -1,6 +1,12 @@
|
|||
# Description
|
||||
|
||||
This role installs and configures [memcached](https://memcached.org/) service.
|
||||
This role installs and configures [memcached](https://memcached.org/) and [memcached\_exporter](https://github.com/prometheus/memcached_exporter/) services.
|
||||
|
||||
The exporter is available on port `9150` and the prometheus metrics can be fetched via the `/metrics` http endpoint:
|
||||
|
||||
```
|
||||
curl 0.0.0.0:9150/metrics
|
||||
```
|
||||
|
||||
# Configuration
|
||||
|
||||
|
@ -11,3 +17,9 @@ memcached_port: 11211
|
|||
memcached_size_mb: 64
|
||||
memcached_maxconn: 1024
|
||||
```
|
||||
|
||||
The installation of `memcached_exporter` is optional. It is installed by default but can be disabled by setting:
|
||||
|
||||
```yaml
|
||||
memcached_exporter_enabled: false
|
||||
```
|
||||
|
|
|
@ -15,3 +15,13 @@ memcached_cfg_file: '/etc/memcached.conf'
|
|||
memcached_consul_tags_default: ['memcached', 'cache']
|
||||
memcached_consul_tags_extra: []
|
||||
memcached_consul_tags: '{{ memcached_consul_tags_default + memcached_consul_tags_extra }}'
|
||||
|
||||
memcached_exporter_enabled: true
|
||||
memcached_exporter_port: 9150
|
||||
memcached_exporter_version: '0.8.0'
|
||||
memcached_exporter_release_name: 'memcached_exporter-{{ memcached_exporter_version }}.linux-amd64'
|
||||
memcached_exporter_url: 'https://github.com/prometheus/memcached_exporter/releases/download/v{{ memcached_exporter_version }}/{{ memcached_exporter_release_name }}.tar.gz'
|
||||
memcached_exporter_checksum: '0a666f41d733ebdc20cf2dc66fbb0c2899afc237002db67b7a31ff7f9f7dde3f'
|
||||
|
||||
memcached_exporter_consul_service: 'memcached_exporter'
|
||||
memcached_exporter_consul_tags: '{{ memcached_consul_tags + ["exporter", "metrics"] }}'
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- name: restart memcached_exporter
|
||||
systemd:
|
||||
daemon_reload: true
|
||||
name: memcached_exporter
|
||||
state: restarted
|
|
@ -18,6 +18,9 @@
|
|||
state: restarted
|
||||
when: memcached_config.changed
|
||||
|
||||
- include_tasks: memcached_exporter.yml
|
||||
when: memcached_exporter_enabled
|
||||
|
||||
- name: Create Consul service definition
|
||||
include_role: name=consul-service
|
||||
vars:
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
- name: Download memcached_exporter tarball
|
||||
get_url:
|
||||
url: '{{ memcached_exporter_url }}'
|
||||
dest: '/tmp/{{ memcached_exporter_release_name }}.tar.gz'
|
||||
checksum: 'sha256:{{ memcached_exporter_checksum }}'
|
||||
mode: 0644
|
||||
|
||||
- name: Unpack binary from tarball
|
||||
unarchive:
|
||||
src: '/tmp/{{ memcached_exporter_release_name }}.tar.gz'
|
||||
dest: '/usr/local/bin'
|
||||
creates: '/usr/local/bin/memcached_exporter'
|
||||
remote_src: true
|
||||
extra_ops:
|
||||
- '--wildcards'
|
||||
- '--strip=1'
|
||||
- '*/memcached_exporter'
|
||||
notify: restart memcached_exporter
|
||||
|
||||
- name: Copy the memcached_exporter systemd service file
|
||||
template:
|
||||
src: 'memcached_exporter.service.j2'
|
||||
dest: '/lib/systemd/system/memcached_exporter.service'
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: restart memcached_exporter
|
||||
|
||||
- name: Create Consul service definition
|
||||
include_role: name=consul-service
|
||||
vars:
|
||||
consul_config_name: '{{ memcached_exporter_consul_service }}'
|
||||
consul_services:
|
||||
- name: '{{ memcached_exporter_consul_service }}'
|
||||
tags: '{{ memcached_exporter_consul_tags }}'
|
||||
port: '{{ memcached_exporter_port }}'
|
||||
address: '{{ memcached_addr }}'
|
||||
checks:
|
||||
- id: '{{ memcached_exporter_consul_service }}-health'
|
||||
name: '{{ memcached_exporter_consul_service }}'
|
||||
type: 'tcp'
|
||||
tcp: '{{ memcached_addr }}:{{ memcached_exporter_port }}'
|
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description="Memcached Exporter for Prometheus"
|
||||
Documentation=https://github.com/prometheus/memcached_exporter
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/bin/memcached_exporter --memcached.address={{ memcached_addr }}:{{ memcached_port }}
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in New Issue