entercloudsuite.prometheus-exporter

Ansible角色:prometheus-exporter

构建状态 Galaxy

在Ubuntu 16.04(Xenial)上安装prometheus-exporter。

需求

此角色需要Ansible 2.4或更高版本。

角色变量

该角色在defaults/main.yml中定义了大多数变量。

示例剧本

使用默认变量运行:

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

测试

使用Molecule进行测试。

安装Molecule或使用docker-compose run --rm molecule来运行基于enterclousuite/molecule项目的本地Docker容器,在这里可以使用molecule

  1. 运行molecule create以在本地引擎上启动目标Docker容器。
  2. 使用molecule login登录运行中的容器。
  3. 编辑角色文件。
  4. 在molecule/default/requirements.yml文件中添加其他所需的角色(外部)。
  5. 编辑molecule/default/playbook.yml。
  6. 使用goos验证器在molecule/default/tests文件夹下定义基础设施测试。
  7. 准备好后,使用molecule converge运行Ansible剧本,并使用molecule verify执行测试套件。
    注意,converge过程开始对角色进行语法检查。
    使用命令molecule destroy销毁Docker容器。

要用一个命令运行所有步骤,请运行molecule test

为了运行目标虚拟机的角色,可以使用playbook_deploy.yml文件,通过以下命令:ansible-playbook ansible-prometheus-exporter/molecule/default/playbook_deploy.yml -i VM_IP_OR_FQDN, -u ubuntu --private-key private.pem

更多示例

部署node_exporter

剧本

简单示例

- name: 在所有实例上安装node_exporter
  hosts: all
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: node_exporter

更多选项

- name: 在所有实例上安装node_exporter
  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'

部署haproxy_exporter

剧本

- 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配置

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

部署mysqld_exporter

剧本

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配置

创建监控用户

shell
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
ansible任务示例 mysql_user模块
- name: 为监控创建用户
  mysql_user:
    name: "exporter"
    host: localhost
    password: "v3rys3cr3tp4sw0rd"
    priv: '*.*:PROCESS,REPLICATION CLIENT,SELECT'
    state: present

部署blackbox_exporter

配置文件 https://github.com/prometheus/blackbox_exporter/blob/master/blackbox.yml

设置prometheus_exporter_custom_conf_destination变量以便在特定位置部署配置文件

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

prometheus_exporter_conf_main配置文件在剧本目录中的位置:

示例:


prometheus_exporter_conf_main: black_box_exporter_example_config.yaml

文件位置:

$PLAYBOOKPATH/black_box_exporter_example_config.yaml

prometheus_exporter_conf_main: prometheus_cof/black_boxexporter/black_box_exporter_example_config.yaml

文件位置:

$PLAYBOOKPATH/prometheus_cof/black_boxexporter/black_box_exporter_example_config.yaml
prometheus_exporter_conf_main: black_box_exporter_example_config.yaml

剧本

- name: 在组上安装blackbox_exporter
  hosts: blackbox_exporter
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: blackbox_exporter
      prometheus_exporter_version: 0.12.0
      # playbookpath/{{prometheus_exporter_conf_main}} 自定义路径
      prometheus_exporter_conf_main: black_box_exporter_example_config.yaml
      prometheus_exporter_config_flags:
        "--config.file": "{{ prometheus_exporter_custom_conf_destination }}/black_box_exporter_example_config.yaml"

部署postgres_exporter

- name: 在postgres_exporter组上安装postgres_exporter
  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'

部署uwsgi_exporter

- name: 在uwsgi实例上安装uwsgi_exporter
  hosts: uwsgi
  roles:
    - role: ansible-prometheus-exporter
      prometheus_exporter_name: uWSGI_expoter
      url: https://github.com/AndreaGreco/prometeus_uwsgi_exporter/files/1734745/uWSGI_expoter-v1.1.linux-amd64.tar.gz
      prometheus_exporter_conf_main: prometheus/config_uwsgi_expoter.yaml
      prometheus_exporter_config_flags:
        "-c": "{{ prometheus_exporters_common_root_dir }}/{{prometheus_exporter_name}}_current/config_uwsgi_expoter.yaml"
        "-n": ""

许可证

MIT

关于项目

Playbook for prometheus-exporter.

安装
ansible-galaxy install entercloudsuite.prometheus-exporter
许可证
mit
下载
211.4k