Skip to content

mwinfie/ansible-prometheus-exporter

 
 

Repository files navigation

Ansible Role: prometheus-exporter

Build Status Galaxy

Installs prometheus-exporter on Ubuntu 16.04 (Xenial)

Requirements

This role requires Ansible 2.4 or higher.

Role Variables

The role defines most of its variables in defaults/main.yml:

Example Playbook

Run with default vars:

- hosts: all
  roles:
    - { role: ansible-prometheus-exporter }

Testing

Tests are performed using Molecule.

Install Molecule or use docker-compose run --rm molecule to run a local Docker container, based on the enterclousuite/molecule project, from where you can use molecule.

  1. Run molecule create to start the target Docker container on your local engine.
  2. Use molecule login to log in to the running container.
  3. Edit the role files.
  4. Add other required roles (external) in the molecule/default/requirements.yml file.
  5. Edit the molecule/default/playbook.yml.
  6. Define infra tests under the molecule/default/tests folder using the goos verifier.
  7. When ready, use molecule converge to run the Ansible Playbook and molecule verify to execute the test suite.
    Note that the converge process starts performing a syntax check of the role.
    Destroy the Docker container with the command molecule destroy.

To run all the steps with just one command, run molecule test.

In order to run the role targeting a VM, use the playbook_deploy.yml file for example with the following command: ansible-playbook ansible-prometheus-exporter/molecule/default/playbook_deploy.yml -i VM_IP_OR_FQDN, -u ubuntu --private-key private.pem.

More example

Playbook

simple

- name: install node_exporter on all the instances
  hosts: all
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: node_exporter

more options

- name: install node_exporter on all the instances
  hosts: all
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: node_exporter
      prometheus_exporter_config_flags:
        '--web.listen-address': '0.0.0.0:9100'
        '--log.level': 'info'

Playbook

    - role: entercloudsuite.prometheus-exporter
      prometheus_exporter_version: 0.9.0
      prometheus_exporter_name: "haproxy_exporter"
      prometheus_enable_exporter_config_flags: true
      prometheus_exporter_config_flags:
       '--haproxy.scrape-uri': 'unix:/run/haproxy/admin.sock'

HAproxy configuration

stats socket /run/haproxy/admin.sock mode 666 level admin

Playbook

  hosts: mysql_exporter
  roles:
    - role: entercloudsuite.prometheus-exporter
      prometheus_exporter_name: mysqld_exporter
      prometheus_exporter_version: 0.10.0
      prometheus_environment_variables:
        'DATA_SOURCE_NAME': 'exporter:v3rys3cr3tp4sw0rd@(mysqlhost:3306)/'

mysql configuration

Creae user from monitoring

shell
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
ansible task example mysql_user module
  - name: Create user for monitoring
    mysql_user:
      name: "exporter"
      host: localhost
      password: "v3rys3cr3tp4sw0rd"
      priv: '*.*:PROCESS,REPLICATION CLIENT,SELECT'
      state: present

config file https://github.com/prometheus/blackbox_exporter/blob/master/blackbox.yml

Set prometheus_expoter_custom_conf_destination variable for deploy configuration file in a specific location

default-value: "{{ prometheus_exporters_common_root_dir }}/{{prometheus_exporter_name}}_current"

prometheus_expoter_conf_main config file location in playbook dir:

example:


prometheus_expoter_conf_main: black_box_expoter_example_config.yaml

file location:

$PLAYBOOKPATH/black_box_expoter_example_config.yaml

prometheus_expoter_conf_main: prometheus_cof/black_boxexpoter/black_box_expoter_example_config.yaml

file location:

$PLAYBOOKPATH/prometheus_cof/black_boxexpoter/black_box_expoter_example_config.yaml
prometheus_expoter_conf_main: black_box_expoter_example_config.yaml

Playbook

- name: install blackbox_exporter on group
  hosts: blackbox_exporter
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: blackbox_exporter
      prometheus_exporter_version: 0.12.0
      # path to playbookpath/{{prometheus_expoter_conf_main}} custom path
      prometheus_expoter_conf_main: black_box_expoter_example_config.yaml
      prometheus_exporter_config_flags:
        "--config.file": "{{ prometheus_expoter_custom_conf_destination }}/black_box_expoter_example_config.yaml"
- name: install postgres_exporter on postgres_exporter group
  hosts: postgres_exporter
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: postgres_exporter
      url: https://github.com/wrouesnel/postgres_exporter/releases/download/v0.4.6/postgres_exporter_v0.4.6_linux-amd64.tar.gz
      prometheus_environment_variables:
        'DATA_SOURCE_NAME': 'postgresql://user:password@localhost:5432/?sslmode=disable'

License

MIT

About

Installs Prometheus Exporters on Ubuntu Xenial servers

Resources

License

Stars

Watchers

Forks

Packages

No packages published