Giter VIP home page Giter VIP logo

mesaguy / ansible-prometheus Goto Github PK

View Code? Open in Web Editor NEW
70.0 3.0 31.0 6.29 MB

Ansible role for the management of Prometheus software and Prometheus exporters

Home Page: https://galaxy.ansible.com/mesaguy/prometheus

License: MIT License

Shell 17.91% Ruby 64.58% Dockerfile 0.13% Python 14.84% Jinja 2.54%
prometheus prometheus-tgroup prometheus-clients prometheus-components prometheus-servers ansible node-exporter haproxy-exporter jmx-exporter alertmanager

ansible-prometheus's Introduction

Ansible Prometheus

Kitchen tests Validate Ansible awesome_bot tests Latest tag Ansible Galaxy MIT License

Installs and manages Prometheus server, Alertmanager, PushGateway, and numerous Prometheus exporters

This role was designed to allow adding new exporters with ease. Regular releases ensure it always provides the latest Prometheus software.

This role can register client exporters with the Prometheus server/s automatically (see tgroup management below).

Requirements

  • Ansible >= 2.8.0
  • Facts must be gathered (gather_facts: true)

Supported Software and Operating Systems

Supported Operating Systems, Distributions, and Architectures

This module is intended to support as many distributions and architectures as possible. The following table specifies which combinations are currently tested. Most exporters will also work on ARM architectures:

OS Release Architectures
Alpine 3.2 through 3.11, edge x86_64 (amd64)
AmazonLinux 1 and 2 x86_64 (amd64)
ArchLinux Current x86_64 (amd64)
Enterprise Linux 6, 7, 8 x86_64 (amd64)
Fedora 20 through 31, rawhide x86_64 (amd64)
Gentoo (openrc) Current x86_64 (amd64)
Gentoo (systemd) Current x86_64 (amd64)
OpenSUSE 13.1 through tumbleweed x86_64 (amd64)
Oracle Linux 6, 7, 8 x86_64 (amd64)
Ubuntu 16.04 through 20.04 x86_64 (amd64)

Managed Prometheus software

The following core Prometheus software is supported in addition to the list of exporters below. This software is fully tested on all supported OS, distributions, and architectures.

Prometheus software Usage Author CI tested
prometheus usage prometheus Yes
alertmanager usage prometheus Yes
push_gateway usage prometheus Yes

Managed exporters

All exporters are verified to install. Currently select modules receive testing via CI (Continuous Integration) and Inspec

See each exporter's usage page for more details:

Exporter Usage Author CI tested
389ds_exporter_terrycain usage terrycain Yes
apache_exporter_lusitaniae usage Lusitaniae Yes
aerospike_exporter_alicebob usage alicebob Yes
bigip_exporter_expressenab usage ExpressenAB Yes
bind_exporter_prometheus_community usage prometheus-community Partial
blackbox_exporter usage prometheus Yes
ceph_exporter_digitalocean usage digitalocean Partial
clickhouse_exporter_clickhouse usage clickhouse Yes
cloudwatch_exporter usage prometheus Partial
collectd_exporter usage prometheus Yes
consul_exporter usage prometheus Yes
couchbase_exporter_blakelead usage leansys-team Yes
couchdb_exporter_gesellix usage gesellix Yes
digitalocean_exporter_metalmatze usage metalmatze Yes
elasticsearch_exporter_prometheus_community usage prometheus_community Yes
fping_exporter_schweikert usage schweikert Yes
gluster_exporter_ofesseler usage ofesseler Yes
graphite_exporter usage prometheus Yes
grok_exporter_fstab usage fstab Yes
haproxy_exporter usage prometheus Yes
influxdb_exporter usage prometheus Yes
ipmi_exporter_prometheus_community usage prometheus-community Yes
iperf3_exporter_edgard usage edgard Yes
iptables_exporter_retailnext usage retailnext Yes
jmx_exporter usage prometheus No
kafka_exporter_danielqsj usage danielqsj Partial
keepalived_exporter_gen2brain usage gen2brain Yes
memcached_exporter usage prometheus Yes
mongodb_exporter_percona usage percona Yes
mysqld_exporter usage prometheus Partial
nginx_exporter_nginxinc usage nginxinc Partial
node_exporter usage prometheus Yes
ntp_exporter_sapcc usage sapcc Yes
nvidia_exporter_bugroger usage BugRoger Partial
nvidia_gpu_exporter_mindprince usage mindprince Partial
openldap_exporter_tomcz usage tomcz Yes
openvpn_exporter_kumina usage kumina Partial
phpfpm_exporter_hipages usage hipages Yes
ping_exporter_czerwonk usage czerwonk Yes
postgres_exporter_prometheus_community usage prometheus-community Yes
process_exporter_ncabatoff usage ncabatoff Yes
proxysql_exporter_percona usage percona Yes
rabbitmq_exporter_kbudde usage kbudde Yes
redis_exporter_oliver006 usage oliver006 Yes
script_exporter_adhocteam usage adhocteam Yes
smokeping_exporter_superq usage SuperQ Yes
snmp_exporter usage prometheus Yes
sql_exporter_free usage free Yes
squid_exporter_boynux usage boynux Yes
ssl_exporter_ribbybibby usage ribbybibby Yes
statsd_exporter usage prometheus Yes
wireguard_exporter_mdlayher usage mdlayher Partial

Managed node_exporter textfiles scripts

Numerous node_exporter textfiles scripts are supported and can be installed via the following variables. These scripts are installed under '/opt/prometheus/scripts' by default:

node_exporter textfiles script Source Enable variable
apt.sh node_exporter examples prometheus_script_apt: true
btrfs_stats.py node_exporter examples prometheus_script_btrfs_stats: true
deleted_libraries.py node_exporter examples prometheus_script_deleted_libraries: true
directory-size.sh node_exporter examples prometheus_script_directory_size: true
inotify-instances node_exporter examples prometheus_script_inotify_instances: true
ipmitool node_exporter examples prometheus_script_ipmitool: true
lvm-prom-collector node_exporter examples prometheus_script_lvm_prom_collector: true
md_info.sh node_exporter examples prometheus_script_md_info: true
md_info_detail.sh node_exporter examples prometheus_script_md_info_detail: true
mellanox_hca_temp node_exporter examples prometheus_script_mellanox_hca_temp: true
multipathd_info node_exporter examples prometheus_script_multipathd_info: true
ntpd_metrics.py node_exporter examples prometheus_script_ntpd_metrics: true
nvme_metrics.sh node_exporter examples prometheus_script_nvme_metrics: true
pacman.sh node_exporter examples prometheus_script_pacman: true
promcron.sh mesaguy/ansible-prometheus prometheus_script_promcron: true
promrun.sh mesaguy/ansible-prometheus prometheus_script_promrun: true
smartmon.py node_exporter examples prometheus_script_smartmon_python: true
smartmon.sh node_exporter examples prometheus_script_smartmon: true
sssd_check.sh mesaguy/ansible-prometheus prometheus_script_sssd_check: true
storcli.py node_exporter examples prometheus_script_storcli: true
tw_cli.py node_exporter examples prometheus_script_tw_cli: true
yum.sh node_exporter examples prometheus_script_yum: true

Role Variables

A 'prometheus_components' array variable is used to specify the Prometheus software to install. This example installs all supported prometheus_components:

# Demonstration only. Clients should only have applicable software and exporters defined:
prometheus_components:
 # Core components:
 - alertmanager
 - prometheus
 - push_gateway
 # Exporters
 - 389ds_exporter_terrycain
 - apache_exporter_lusitaniae
 - aerospike_exporter_alicebob
 - bigip_exporter_expressenab
 - bind_exporter_prometheus_community
 - blackbox_exporter
 - ceph_exporter_digitalocean
 - clickhouse_exporter_clickhouse
 - cloudwatch_exporter
 - collectd_exporter
 - consul_exporter
 - couchbase_exporter_blakelead
 - couchdb_exporter_gesellix
 - digitalocean_exporter_metalmatze
 - elasticsearch_exporter_prometheus_community
 - fping_exporter_schweikert
 - gluster exporter_ofesseler
 - graphite_exporter
 - grok_exporter_fstab
 - haproxy_exporter
 - influxdb_exporter
 - iperf3_exporter_edgard
 - ipmi_exporter_prometheus_community
 - iptables_exporter_retailnext
 - jmx_exporter
 - kafka_exporter_danielqsj
 - keepalived_exporter_gen2brain
 - memcached_exporter
 - mysqld_exporter
 - nginx_exporter_nginxinc
 - node_exporter
 - ntp_exporter_sapcc
 - nvidia_exporter_bugroger
 - nvidia_gpu_exporter_mindprince
 - openldap_exporter_tomcz
 - openvpn_exporter_kumina
 - phpfpm_exporter_hipages
 - ping_exporter_czerwonk
 - postgres_exporter_prometheus_community
 - process_exporter_ncabatoff
 - proxysql_exporter_percona
 - rabbitmq_exporter_kbudde
 - redis_exporter_oliver006
 - script_exporter_adhocteam
 - smokeping_exporter_superq
 - snmp_exporter
 - sql_exporter_free
 - squid_exporter_boynux
 - ssl_exporter_ribbybibby
 - statsd_exporter
 - wireguard_exporter_mdlayher

Mesaguy script documentation

  • promcron for monitoring the execution of cron jobs
  • promrun for monitoring the execution of commands
  • sssd_check for monitoring the status of SSSD

Common variables

By default, if a Prometheus software or exporter binary fails to install, the installation fails. This default can be overridden causing an installation via source by setting the global 'prometheus_fallback_to_build' boolean or a software specific override. For example, to allow the blackbox_exporter to be built from source if no binary can be found set:

prometheus_blackbox_exporter_fallback_to_build: true

All daemon installer tasks have a 'runas' parameter to specify which user the daemon will run as. By default all users run as the 'prometheus_user' (defaults to: prometheus). For example, to have the blackbox_exporter run as user 'test' set the following variable:

prometheus_blackbox_exporter_runas: test

Global variables

Link the Prometheus etc directory to '/etc/prometheus'. The Prometheus etc directory defaults to '/opt/prometheus/etc':

prometheus_link_etc: true

Attempt to force the etc directory symlink referenced above:

prometheus_link_etc_force: false

Install the 'sponge' utility. Recommended by the Prometheus project when writing to node_exporter's textfile directory. The EPEL repository is required if installing on a Red Hat Enterprise Linux derivative. CentOS 8.x requires the 'CentOS-PowerTools' yum repository, OracleLinux 7 requires the 'ol7_optional_archive' repository, and Red Hat Enterprise Linux 8 requires the 'Red Hat CodeReady Linux Builder' yum repository be enabled:

prometheus_install_sponge: false

Purge old and now orphaned versions of software:

prometheus_purge_orphans: false

Purge backups of prometheus configuration files from the prometheus 'etc' directory files after 'prometheus_etc_backup_max_age' days (Default: 31d). Option 'prometheus_etc_purge_backups' defaults to 'false':

prometheus_etc_purge_backups: true
prometheus_etc_backup_max_age: 31d

Root directory to install Prometheus software:

prometheus_root_dir: '/opt/prometheus'

Test each service port after installing and starting each service:

prometheus_test_service_port: true

Manage the 'prometheus' service user and group:

prometheus_manage_group: true
prometheus_manage_user: true

Name of the Prometheus service and group:

prometheus_group: prometheus
prometheus_user: prometheus

Create the Prometheus user and group as system accounts, defaults to 'false':

prometheus_group_is_system: true
prometheus_user_is_system: true

Configure ulimits for 'prometheus' user:

prometheus_configure_ulimits: false
prometheus_ulimit_hard_nofile: 8192
prometheus_ulimit_soft_nofile: 4096

If installing a Prometheus application binary fails, fall back to installing the Prometheus software via source. Installation from source generally requires installing compilers. It is also possible to enable 'fallback_to_build' on a case-by-case basis (ie: prometheus_blackbox_exporter_fallback_to_build: true):

prometheus_fallback_to_build: false

Go version to use when building Prometheus software:

prometheus_go_version: 1.13.10

The Prometheus etc directory, defaults to '/opt/prometheus/etc':

prometheus_etc_dir: "{{ prometheus_root_dir }}/etc"

The root directory in which exporters are installed, defaults to '/opt/prometheus/exporters':

prometheus_exporters_dir: "{{ prometheus_root_dir }}/exporters"

The root directory in which 'go' is installed. Go is only installed if Prometheus software is being installed from source. Defaults to '/opt/prometheus/go':

prometheus_go_dir: "{{ prometheus_root_dir }}/go"

The directory in which logs are created. Systems using journalctl will generally log to journalctl instead of files:

prometheus_log_dir: "/var/log/prometheus"

The directory to use for temporary space, principally when building Prometheus software. Defaults to '/opt/prometheus/tmp':

prometheus_tmp_dir: "{{ prometheus_root_dir }}/tmp"

The directory to use when storing persistent Prometheus data (ie: The Prometheus server's data), defaults to '/opt/prometheus/var':

prometheus_var_dir: "{{ prometheus_root_dir }}/var"

Optionally disable symlink of tool applications (amtool, promtool, etc) to /usr/local/bin. Defaults to 'true':

prometheus_symlink_tools: false

Cache downloaded software on the Ansible host and push cached software to the remote hosts Ansible is configuring. Defaults to disabled via 'false':

prometheus_local_archive: true
prometheus_local_archive_dir: ../archive/prometheus

Prometheus rule management variables

Enable management of Prometheus 'rules':

prometheus_manage_rules: true

Local location to find rules files, defaults to empty (disabled):

prometheus_rules_source_dirs:
 - ../files/prometheus/rules
 - ../files/prometheus/additional_rules

Ownership and permissions of rules files, defaults:

prometheus_rules_dir_mode: 0755
prometheus_rules_file_mode: 0644
prometheus_rules_group: '{{ prometheus_group }}' # prometheus
prometheus_rules_owner: '{{ prometheus_user }}'  # prometheus

Purge backups of rules files after 'prometheus_rules_backup_max_age' days (Default: 90d). Option 'prometheus_rules_purge_backups' defaults to 'false':

prometheus_rules_purge_backups: true
prometheus_rules_backup_max_age: 90d

Purge undefined (orphaned) rules from Prometheus servers. Defaults to 'false':

prometheus_rules_purge_orphans: true

Prometheus log rotation variables

Log rotation is disabled by default, but can be configured simply using the following variables. Log rotation is configured for all .log files in the Prometheus log directory (ie: /var/log/prometheus/.log).

Enable installing a prometheus log rotation script. Defaults to 'false':

prometheus_logrotate: true

Number of log rotation (days) to keep:

prometheus_logrotate_count: 31

Boolean specifying whether logs should be compressed:

prometheus_logrotate_compress: true

Log rotation configuration file directory:

prometheus_logrotate_dir: /etc/logrotate.d

Prometheus client variables

Cause all Prometheus servers defined in a 'prometheus_servers' array/list variable to verify connectivity to each of the client's exporters:

prometheus_software_server_side_connect_test: true

Configure firewalld rules to permit server IPs defined in a 'prometheus_server_ips' array/list variable to connect to each of the client's exporters. This functionality requires that the python 'netaddr' module be installed (ie: yum install -y python-netaddr or dnf install -y python-netaddr or pip install netaddr). Only enable this variable on servers that use firewalld, otherwise the task will fail:

prometheus_manage_client_firewalld: true
# Optionally set:
prometheus_firewalld_zone: public

If firewalld customization is required, one can add firewalld rules using a playbook as follows:

- name: Allow incoming prometheus server connections to node_exporter
  become: true
  firewalld:
    immediate: true
    port: 9100/tcp
    permanent: true
    source: "{{ item }}"
    state: enabled
    zone: public
  with_items: "{{ prometheus_server_ips }}"
  when: uses_firewalld is defined and 'node_exporter' in prometheus_components

Configure iptables rules to permit server IPs defined in a 'prometheus_server_ips' array/list variable to connect to each of the client's exporters. Only enable this variable on servers that use iptables, otherwise the task will fail:

prometheus_manage_client_iptables: true

If iptables_raw has been installed, you can enable the following variable:

prometheus_manage_client_iptables_raw: true

This role can manage your Prometheus server 'target groups' (tgroups) automatically, dynamically creating tgroup files in a specified directory (/opt/prometheus/etc/tgroups by default) for each client exporter.

Automatic tgroup file management can be enabled for client side operation, server side operation, or both. In client mode, client's exporters are registered automatically on the Prometheus server specified in a 'prometheus_servers' array. In server mode, the inventory is parsed to determine which exporters are available on each host and all clients are registered with the server's specified in each client's 'prometheus_servers' array.

By default, client and server tgroups use 'inventory_hostname' (fqdn) and 'inventory_hostname_short' (hostname) values for server fqdn/hostnames and ignore facts. This is done because server-side population of tgroups cannot account for client's facts unless clients are configured to cache their facts. To use fact based 'ansible_fqdn' (fqdn) and 'ansible_hostname' (hostname) variables enable 'prometheus_tgroup_use_facts'. At this time, enabling 'prometheus_tgroup_use_facts' for any clients disables server side tgroup management:

prometheus_tgroup_use_facts: true

To enable automatic tgroup file generation on the client side, you must define 'prometheus_manage_client_tgroups' as true and list your Prometheus servers in a 'prometheus_servers' variable in your Ansible variables or inventory. The following will create tgroup files in /opt/prometheus/etc/ansible_tgroups:

prometheus_manage_client_tgroups: true
prometheus_servers:
 - 'prometheus1'
 - 'prometheus2'
# Optional, defaults to /opt/prometheus/etc/tgroups:
prometheus_managed_tgroup_dir: '/opt/prometheus/etc/ansible_tgroups'

If this role is managing your tgroup files, you can apply labels to your exporter/s using the 'prometheus_tgroup_labels' variable:

- hosts: prometheus_clients
  vars:
    prometheus_components:
      - node_exporter
    prometheus_tgroup_labels:
      environment: development
      site: primary
  roles:
    - mesaguy.prometheus

Using 'set_fact' to do the same:

  • name: Set Prometheus labels for host set_fact: prometheus_tgroup_labels: environment: 'development' site: primary

Exporters that aren't managed by this role can be specified using a 'prometheus_additional_exporters' variable as follows. Any labels specified in 'prometheus_tgroup_labels' will be merged with labels defined in 'prometheus_additional_exporters'. Firewall rules will be created for additional exporters if 'prometheus_manage_client_firewalld' or 'prometheus_manage_client_iptables' is defined.

prometheus_additional_exporters:
 - name: docker
   port: 9323
   labels: {}
 - name: foo
   port: 9999
   labels:
     team: foo
     department: IT

To enable automatic tgroup file generation on the server side, you must define 'prometheus_manage_server_tgroups' as true and list your Prometheus servers in a 'prometheus_servers' variable in your Ansible variables or inventory. The following will create tgroup files in /opt/prometheus/etc/ansible_tgroups for all clients that have 'prometheus_compenents' and/or 'prometheus_additional_exporters', clients must also have 'prometheus_servers' array configured:

prometheus_manage_server_tgroups: true

To only configure server tgroups and perform no role tasks, enable 'prometheus_manage_server_tgroups_only':

- hosts: prometheus_servers
  vars:
    prometheus_manage_server_tgroups_only: true
  roles:
    - mesaguy.prometheus

Purge undefined (orphaned) exporters. When run in client mode, this option only effects client's orphaned files. When run in server mode this affects all tgroup files:

prometheus_tgroup_dir_purge_orphans: true

Specify a FQDN for a host when the FQDN isn't in Ansible's inventory and isn't the host's official FQDN. This option should be generally avoided, fixing DNS or Ansible's inventory is a better option:

prometheus_override_fqdn: weird-hostname.example.org

Prometheus server configuration

To enable prometheus server include role task: prometheus

Prometheus configuration files are validated using 'promtool' before Prometheus is restarted.

The configuration content. The example below utilizes a file named 'prometheus_server.yml' in your Ansible root directory's 'files' directory. If no configuration content is defined, a default configuration file is utilized. You will want to customize your configuration file content!:

prometheus_server_cfg: '{{ lookup("file", "../files/prometheus_server.yml") | from_yaml }}'

Or embedding the YAML directly into your playbook:

  prometheus_server_cfg:
    global:
      scrape_interval: 15s

      # Attach these labels to any time series or alerts when communicating with
      # external systems (federation, remote storage, Alertmanager).
      external_labels:
        monitor: 'codelab-monitor'

    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'

        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s

        static_configs:
          - targets: ['localhost:9090']

An array of additional flags to pass to the prometheus daemon:

prometheus_extra_opts: []

The version of Prometheus to install. The default version can be found in the prometheus variables file and the default version can be overridden using the following variable:

prometheus_version: "v1.0.0"

Allow the use of prerelease versions (beta, test, development, etc versions), defaults to 'false':

prometheus_use_prerelease: true

Where to store Prometheus's database, defaults to /opt/prometheus/var/prometheus

prometheus_storage_dir: /opt/prometheus/var/prometheus

Prometheus web console templates to utilize. The defaults suffice under most circumstances and this variable should remain unset under most circumstances:

prometheus_web_console_libraries_dir: /opt/prometheus/prometheus/x.x.x/console_libraries
prometheus_web_console_templates_dir: /opt/prometheus/prometheus/x.x.x/consoles

Port and IP to listen on. Defaults to listening on all available IPs on port 9090:

prometheus_host: "0.0.0.0"
prometheus_port: 9090

Example Playbook

Prometheus server

The following example installs Prometheus (server), alertmanager, blackbox_exporter, and the node_exporter. The Prometheus (server) port and storage retention parameters have been changed from the defaults.

The Prometheus server should be installed only on designated Prometheus server hosts. Prometheus clients should only have select and specific exporters installed.

Class use method:

- hosts: prometheus_servers
  vars:
    prometheus_components:
      - prometheus
      - alertmanager
      - blackbox_exporter
      - node_exporter
    prometheus_port: 10000
    prometheus_extra_opts:
     - '--storage.tsdb.retention=90d'
  roles:
    - mesaguy.prometheus

Longer 'include_role' use method:

- hosts: prometheus_servers
  vars:
    prometheus_port: 10000
    prometheus_extra_opts:
     - '--storage.tsdb.retention=90d'
  tasks:
  - name: Prometheus server
    include_role:
      name: mesaguy.prometheus
      tasks_from: '{{ prometheus_component }}'
    loop_control:
      loop_var: prometheus_component
    with_items:
      - prometheus
      - alertmanager
      - blackbox_exporter
      - node_exporter

Additional information

Software installation methods

Installations are performed using pre-compiled binary files where possible. Where pre-compiled binaries are not available, this Ansible role:

  1. Installs the tools necessary to compile the binaries
  2. Compiles the binaries
  3. Installs the binaries in a directory specifying both the version of the Prometheus software and version of go utilized for the installation (ie: /opt/prometheus/exporters/smokeping_exporter_superq/v0.3.1__go-1.14.14/smokeping_prober)

If a binary fails to install or is unavailable despite the existence of some pre-compiled binaries, then the Prometheus module will still be installed using source code.

Security

This module does not manage firewall rules, employ https, or employ authentication to secure the Prometheus software. All of these security measures are worthwhile, but are currently outside the scope of this role.

We closely monitor the release of new Prometheus software as well as the Go compiler and release new versions of this Ansible role accordingly.

All daemons are run via a non-privileged 'prometheus' user by default.

When Prometheus software is installed using source code, the installation destination directory is named for both the Prometheus software version and the Go compiler version. This naming convention ensures that the use of newer versions of the Go compiler force a rebuild of the Prometheus modules build from source. This naming convention also differentiate installations by binary versus installations by compiled source. Forcing Prometheus source rebuilds each time a new version of Go is released has the negative of introducing more work by the clients, but have the benefit of ensuring that and vulnerabilities within the Go core libraries are patched. We assume that Prometheus software that is provided in binary form is monitored for vulnerabilities by the developer and rebuilt as necessary.

Future: When source is compiled, all compile commands are executed using an unprivileged user account. This combined with running daemons as an unprivileged user mitigates many security risks. -- This is currently complicated by limits with become

License

MIT See the LICENSE file

Author Information

Mesaguy

ansible-prometheus's People

Contributors

dekimsey avatar f9n avatar gaarm avatar minitux avatar spy-t avatar urusha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-prometheus's Issues

nginx_exporter_nginxinc is broken because of kebab-case variable names

The nginx_exporter_nginxinc exporter is broken because it declares it's software name as nginx-prometheus-exporter_nginxinc. When overriding the default variables the resulting variable names (eg prometheus_nginx-prometheus-exporter_nginxinc_host) can not be processed by ansible resulting in

ERROR! Invalid variable name in vars specified for IncludeRole: 'prometheus_nginx-prometheus-exporter_nginxinc_host' is not a valid variable name
  • ansible version: 2.10.9
  • mesaguy.prometheus version: v0.12.38

prometheus_extra_opts: [] Does not appear to be functioning correctly.

Hey mesaguy,

Once again thanks for your work on this module it is truly appreciated.

Think I have found a bug. It seems that anything being defined in the prometheus_extra_opts: [] array is summarily ignored during deploy. There is no error the options are just not set in the prometheus.service file when the build finishes. For reference, I am trying to pass the following storage options:

prometheus_extra_opts:
  -  '--storage.tsdb.wal-compression'
  -  '--storage.tsdb.retention.time=31d'
  -  '--storage.tsdb.retention.size=20GB'

I am curious if something changed with the last release? I feel like your module used to default to having the the storage.tsdb.retention flag set to a default of 90days if no other options were defined in the vars but that does not seem to be the case anymore.

Thank you in advance for taking a look at this.

Support for rules.yml file

Hey mesaguy,

Thank you for all of your hard work on this code!

Maybe I missed it but I do not see any support for defining a rules.yml file under /etc/prometheus. If i missed it can you point me in the right direction? If I am right, can I make a feature request to support deploying a rules.yml file. I think it could be done similarly to how the prometheus server config file is deployed.

Thanks.

cloudwatch_exporter does not start in case custom metrics are provided

{{ prometheus_cloudwatch_exporter_cfg | to_nice_yaml(width=80, indent=2) | indent(2) }}

Cloudwatch_exporter cannot be started in case you provide custom metrics - via prometheus_cloudwatch_exporter_cfg.
In that case metrics section is indented to the right which causes error - inability for cloudwatch_exporter to start.

Config file is generated like this:

---
#
# Do not edit manually, this file is managed using automation tools
#
modules: 
  metrics:
  - aws_dimensions:
    - LoadBalancer
    aws_metric_name: ActiveConnectionCount
    aws_namespace: AWS/ApplicationELB

but it should be like this (no indentation for metric section):

---
#
# Do not edit manually, this file is managed using automation tools
#
modules: 
metrics:
- aws_dimensions:
  - LoadBalancer
  aws_metric_name: ActiveConnectionCount
  aws_namespace: AWS/ApplicationELB

See more here:
https://github.com/prometheus/cloudwatch_exporter

@mesaguy

statsd_exporter: no way to specify global defaults

There is no way to specify global defaults ( https://github.com/prometheus/statsd_exporter#global-defaults ) with prometheus_statsd_exporter_cfg.
We could remove mappings: from https://github.com/mesaguy/ansible-prometheus/blob/master/templates/statsd_exporter.yml.j2 but that would not be backward compatible (although this could be fixed in the template by transforming cfg variable). Or we could add prometheus_statsd_exporter_cfg_defaults to the template.
I'm ready to make a PR if it's needed, please advice what way to choose.

By the way https://github.com/mesaguy/ansible-prometheus/blob/master/docs/statsd_exporter.md doesn't mention that we also need to add extra_opts to use templated config.

prometheus_statsd_exporter_extra_opts:
- "--statsd.mapping-config={{prometheus_etc_dir}}/statsd_exporter.yml"

Instead we see confusing: If no configuration content is defined, a default configuration file is utilized.

Incorrect usage of FirewallD module

Hi,

The task _setup_firewall.yml is currently trying to set a port and a source when calling the FirewallD module. However, this is not supported and erroring out. For example:
failed: [hostname.network] (item=10.0.0.1) => { "ansible_loop_var": "prometheus_server_ip", "changed": false, "invocation": { "module_args": { "icmp_block": null, "icmp_block_inversion": null, "immediate": true, "interface": null, "masquerade": null, "offline": null, "permanent": true, "port": "9100/tcp", "rich_rule": null, "service": null, "source": "10.0.0.1", "state": "enabled", "timeout": 0, "zone": "public" } }, "msg": "can only operate on port, service, rich_rule, masquerade, icmp_block, icmp_block_inversion, interface or source at once", "prometheus_server_ip": "10.0.0.1" }

postfix_exporter_kumina exporter

Thanks for the amazing job you're doing on this project, I find it extremely useful and invaluable.

This is more of a question than an actual issue.

I would like to use the postfix_exporter_kumina exporter for some mailservers, but I see its not mentioned in the documentation, and in a wip directory. Does this mean it is currently a "work in progress".

Will it still work if I include it as:

prometheus_components:
  - node_exporter
  - postfix_exporter_kumina

Unsupported parameter for "command" module

The Find {{ prometheus_software_name_version }} archive contents task fails with the following error:

FAILED! => {
  "changed": false,
  "msg": "Unsupported parameters for (ansible.legacy.command) module: warn. Supported parameters include: _uses_shell, strip_empty_ends, executable, _raw_params, removes, stdin_add_newline, stdin, argv, creates, chdir."}

The unsupported parameter is warn here:

- name: Find {{ prometheus_software_name_version }} archive contents
command: 'tar -tf {{ prometheus_software_archive_file }}'
args:
# Do not warn that we are running the tar command directly
warn: false

Publishing the role as ansible collection

Dear Mesaguy,

Thank you for the fantastic ansible role!

Have you thought about publishing the role as a collection?

We are thinking about developing a thin abstraction level over your role, which would generate prometheus configs from ansible inventories, and thinking about distribution options. The new "collection" feature of ansible/galaxy looks like a better option than raw roles. It for example allows to share several separate roles as a package, and also allows to share playbooks. Both features look useful in our case. Unfortunately, collections can only use other collections but not roles as dependencies.

Looking at the structure of your role, it seems that you can also benefit from using collections, by being able to split all the software specific roles into separate entities. Your abstraction model with _install.yaml etc, as I understand, can also be transparently translated to a separate roles model.

We will definitely go with your current role, and it is in no way a blocker for us, so this is rather a feature request for the future. Thanks again for your work!

Timing issue on deploy.

Hey mesaguy,

Thanks for the recent update for implementing the rules directory.

I am running in to an issue which I believe is a timing issue. When I try to build with the rules_file: parameter defined in my prometheus.yml file it fails trying to validate the file. I believe this is a result of the rules directory and files not being present when it attempts to validate.

Section in prometheus.yml

rule_files:
 #- /etc/prometheus/rules/rules.yml
 - /opt/prometheus/etc/rules/

Note: neither of the paths above seem to pass validation.

Here is the error:

TASK [mesaguy.prometheus : Setup prometheus-v2.16.0 configuration file] ********
fatal: [server.example.com]: FAILED! => {"changed": false, "checksum": "8311456b0852d76683984c4434af49d5a5e16419", "exit_status": 1, "msg": "failed to validate", "stderr": "  FAILED: \"/opt/prometheus/etc/rules/\" does not point to an existing file\n", "stderr_lines": ["  FAILED: \"/opt/prometheus/etc/rules/\" does not point to an existing file"], 

Thanks in advance for your help.

Using local rules file

I have a custom config file for Prometheus server in which 'rule_files' points to a file on that server. This rule file has to be copied from the controller. In prometheus.yml, the prometheus server config file is created before copying the local rule files:

- name: Setup {{ prometheus_software_name_version }} configuration file
  become: true
  template:
    src: 'templates/generic-config.yml.j2'
    dest: '{{ prometheus_etc_dir }}/prometheus.yml'
    owner: root
    group: '{{ prometheus_group }}'
    mode: 0640
    backup: true
    validate: '{{ prometheus_software_install_dir }}/promtool check config %s'
  notify:
    - Reload Prometheus service

- name: Include task to setup Prometheus rules
  include_tasks: _rules.yml
  when: prometheus_manage_rules | default(false) | bool

This runs into a validation error because the rule file doesn't exist yet:

fatal: [prometheus]: FAILED! => {"changed": false, "checksum": "de45e00cd186d6c11d37e4ce5eebe6fe1d00eb27", "exit_status": 1, "msg": "failed to validate", "stderr": "  FAILED: \"/apps/shared/monitoring/prometheus/rules.yml\" does not point to an existing file\n", "stderr_lines": ["  FAILED: \"/apps/shared/monitoring/prometheus/rules.yml\" does not point to an existing file"], "stdout": "Checking /root/.ansible/tmp/ansible-tmp-1632221852.5072598-70971-236443730807695/source\n\n", "stdout_lines": ["Checking /root/.ansible/tmp/ansible-tmp-1632221852.5072598-70971-236443730807695/source", ""]}

It works fine when I switch the order of these 2 tasks.

Playbook:

- connection: docker
  hosts: prometheus
  vars:
    prometheus_components:
      - prometheus
    prometheus_version: v2.27.1
    prometheus_root_dir: /apps/shared/monitoring/prometheus
    prometheus_manage_rules: true
    prometheus_rules_dir: '{{ prometheus_root_dir }}'
    prometheus_rules_source_dirs:
      - './rules'
    prometheus_server_cfg: '{{ lookup("file", "./prometheus-config.yml") | from_yaml }}'
  roles:
    - mesaguy.prometheus

Am I missing something?

Installing v0.9.0 nginx_exporter_nginxinc binaries fails

In version 0.9.0 nginx changed the file name schema from ...linux-amd64.tar.gz to ...linux_amd64.tar.gz.

I guess the easiest solution would be to remove all binaries prior to v0.9.0 from vars/software/nginx-prometheus-exporter_nginxinc.yml and switch the architecture to the new schema.

I can send a corresponding PR if you like.

when my input path and patterns_dir set ok. grok_exporter_fstab ansible error.

when my input path and patterns_dir set ok. grok_exporter_fstab ansible error, but service grok_exporter_fstab staus is running.

---
- name: install prometheus grok_exporter
  hosts: prometheusserver
  vars:
    prometheus_link_etc: false
    prometheus_software_src_dir_suffix: grok_exporter
    prometheus_grok_exporter_fstab_cfg: '{{ lookup("file", "./files/grok_exporter_fstab/grok_exporter_fstab.yml") }}'
    prometheus_components:
     - grok_exporter_fstab

  roles:
    - mesaguy.prometheus
---
global:
    config_version: 2
input:
    type: file
    path: /opt/prometheus/exporters/grok_exporter_fstab/active/example/example.log
    readall: true
grok:
    #patterns_dir: ./logstash-patterns-core/patterns
    patterns_dir: /opt/prometheus/exporters/grok_exporter_fstab/active/patterns
metrics:
    - type: counter
      name: grok_example_lines_total
      help: Counter metric example with labels.
      match: '%{DATE} %{TIME} %{USER:user} %{NUMBER}'
      labels:
          user: '{{.user}}'
server:
    port: 9144

fatal: [host1]: FAILED! => {"msg": "The conditional check 'prometheus_servers' failed. The error was: error while evaluating conditional (prometheus_servers): 'prometheus_servers' is undefined\n\nThe error appears to have been in '/root/devops/roles/mesaguy.prometheus/tasks/_service.yml': line 48, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n- block:\n - name: Set {{ prometheus_software_name_version }} tgroup facts\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n"}

sysvinit issue on Devuan

I think your ansible role is pretty impressive.

Was wondering about you adding support for Devuan. Which is basically
Debian using sysvinit.

All worked so far except it fails here:

TASK [mesaguy.prometheus : Include task to symlink latest node_exporter-v1.0.0 directory to an "active" directory] ****************************************************************************
included: /home/ds/src/ds-santanas-ansible/roles_external/mesaguy.prometheus/tasks/_install_active_symlink.yml for stone

TASK [mesaguy.prometheus : Link /opt/prometheus/exporters/node_exporter/v1.0.0 to /opt/prometheus/exporters/node_exporter/active] *************************************************************
changed: [stone]

TASK [mesaguy.prometheus : Include task to setup capabilites for node_exporter-v1.0.0 files] **************************************************************************************************
skipping: [stone]

TASK [mesaguy.prometheus : Include task to setup node_exporter-v1.0.0 service] ****************************************************************************************************************
included: /home/ds/src/ds-santanas-ansible/roles_external/mesaguy.prometheus/tasks/_service.yml for stone

TASK [mesaguy.prometheus : Verify node_exporter-v1.0.0 permissions] ***************************************************************************************************************************
ok: [stone]

TASK [mesaguy.prometheus : Create environment file for node_exporter service] *****************************************************************************************************************
skipping: [stone]

TASK [mesaguy.prometheus : Include task to setup node_exporter-v1.0.0 sysvinit service] *******************************************************************************************************
fatal: [stone]: FAILED! => {"reason": "Could not find or access '/home/ds/src/ds-santanas-ansible/playbooks/_service_mgr_sysvinit.yml' on the Ansible Controller."}

v0.13.0 broken at vars/software/mysqld_exporter.yml

mysqld_exporter v0.13.0 will fallback to building from source despite a binary being available as the data in vars/software/mysqld_exporter.yml is bad.

---[snip]---

  • name: v0.13.0
    commit:
    sha: ad2847c7fa67b9debafccd5a08bacb12fc9031f1
    timestamp: '2021-05-21T14:14:17'
    timestamp: '2021-05-21T14:15:04'
    prerelease: false
    files: []
    ---[end]---

This looks autogenerated, so not sending a pull request manually fixing it.

prometheus_node_exporter_textfiles_directory undefined

Hi

Version: v0.12.22

Hitting an issue with a variable being undefined.

The error was: 'prometheus_node_exporter_textfiles_directory' is undefined
The error appears to be in '../roles/mesaguy.prometheus/tasks/main.yml': line 2, column 3,

Docs describe the variables purpose, but there is no default set for it.


    prometheus_node_exporter_textfiles_directory: '/opt/prometheus/etc/node_exporter_textfiles'

Maybe this needs to be added to defaults?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.