Giter VIP home page Giter VIP logo

ernestas-poskus / ansible-prometheus Goto Github PK

View Code? Open in Web Editor NEW
92.0 6.0 41.0 500 KB

Ansible playbook for installing Prometheus monitoring system, exporters such as: node, snmp, blackbox, thus alert manager and push gateway

License: BSD 3-Clause "New" or "Revised" License

Ruby 72.50% Shell 1.83% HTML 25.67%
prometheus playbook systemd prometheus-exporter ansible alertmanager node-exporter pushgateway prometheus2 blackbox-exporter

ansible-prometheus's Introduction

ansible-prometheus

Build Status

Ansilbe playbook for installing Prometheus monitoring system.

Playbook installs and manages services using systemd. Currently supported:

  • Prometheus
  • Node Exporter (collects metrics of host machine)
  • Alert manager
  • Push gateway
  • SNMP exporter
  • Blackbox exporter

Playbook includes extensive configuration options check default/main.yml

Contribution

If you can't find exporter you need check these examples #47 or #50 and make pull request.

Installation

ansible-galaxy install ernestas-poskus.ansible-prometheus

Requirements

Systemd

Role Variables

---
# defaults file for ansible-prometheus

prometheus_install: true
prometheus_node_exporter_install: true
prometheus_alert_manager_install: true
prometheus_push_gateway_install: false
prometheus_snmp_exporter_install: false
prometheus_blackbox_exporter_install: false

prometheus_owner: 'prometheus'
prometheus_group: 'prometheus'

prometheus_install_dir: '/usr/local/opt'
prometheus_config_dir: '/etc/prometheus'
prometheus_lib_dir: '/var/lib/prometheus'
prometheus_rules_dir: "{{ prometheus_config_dir }}/rules"

prometheus_data_dir: "{{ prometheus_lib_dir }}/prometheus2"
prometheus_alert_manager_data_dir: "{{ prometheus_lib_dir }}/alertmanager"
prometheus_alert_manager_config_dir: "{{ prometheus_config_dir }}/alertmanager"
prometheus_alert_manager_templates_dir: "{{ prometheus_config_dir }}/alertmanager/templates"
prometheus_snmp_exporter_config_dir: "{{ prometheus_config_dir }}/snmpexporter"
prometheus_blackbox_exporter_config_dir: "{{ prometheus_config_dir }}/blackboxexporter"

# Prometheus
prometheus_version: '2.25.1'
prometheus_platform_architecture: 'linux-amd64'

# Number of open file allowed, value for LimitNOFILE
prometheus_service_limitnofile: infinity

# Node exporter
prometheus_node_exporter_version: '1.1.2'

# Alert manager
prometheus_alert_manager_version: '0.21.0'

# Pushgateway
prometheus_push_gateway_version: '1.4.0'

# SNMP exporter
prometheus_snmp_exporter_version: '0.20.0'

# Blackbox exporter
prometheus_blackbox_exporter_version: '0.18.0'

DOCS: Prometheus variables

DOCS: Node exporter variables

DOCS: Alert manager variables

DOCS: Pushgateway variables

DOCS: SNMP exporter variables

DOCS: Blackbox exporter variables

Dependencies

None.

Example Playbook

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- name: Installing Prometheus on hosted machine
  hosts: vagrant1
  sudo: yes
  roles:
    - role: ansible-prometheus
      prometheus_config_scrape_configs:
        - job_name: 'prometheus'
          honor_labels: true
          scrape_interval: '15s'
          scrape_timeout: '3s'
          metrics_path: '/metrics'
          scheme: 'http'
          static_configs:
            - targets:
                - 'localhost:9090' # Prometheus itself
                - 'localhost:9100' # Node exporter
        - job_name: 'consul-services'
          consul_sd_configs:
            - server: "localhost:8500"

License

Copyright (c) 2021, Ernestas Poskus All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of ansible-prometheus nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author Information

Twitter: @ernestas_poskus

ansible-prometheus's People

Contributors

drf avatar ernestas-poskus avatar madeinoz67 avatar madic- avatar shimulch 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  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  avatar  avatar  avatar

ansible-prometheus's Issues

Offer of adding WMI exporter for Windows support?

Hi - I use your excellent role to install the node_exporter to my Linux machines. Would you welcome PR(s) that add Windows (2016 Server) support?

That would look like:

  • generate a new user for the WMI exporter to run as
  • make that user a local administrator (because the permissions required are byzantine, see discussion inside prometheus-community/windows_exporter#233)
  • download a given version of the WMI exporter, unzip, configure
  • install NSSM to turn the WMI exporter into a service with a minimum of hassle
  • make the service log to a file
  • assert success by fetching from the local /metrics endpoint

ERROR! the role 'ansible-prometheus' was not found

I installed the collations with the command,

ansible-galaxy install ernestas-poskus.ansible-prometheus

ansible-galaxy list
/home/ubuntu/.ansible/roles
ernestas-poskus.ansible-prometheus, v4.18.0

I run the command as follows:
ansible-playbook -i hosts -l group1 playbook.yml --check

I got errors as follows:

ERROR! the role 'ansible-prometheus' was not found in /home/ubuntu/works/roles:/home/ubuntu/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/ubuntu/works

The error appears to be in '/home/ubuntu/works/playbook.yml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - role: ansible-prometheus
      ^ here

As follows is the playbook:

- name: Installing Prometheus on hosted machine
  hosts: group1
    #sudo: yes
  roles:
    - role: ansible-prometheus
      prometheus_config_scrape_configs:
        - job_name: 'prometheus'
          honor_labels: true
          scrape_interval: '15s'
          scrape_timeout: '3s'
          metrics_path: '/metrics'
          scheme: 'http'
          static_configs:
            - targets:
                - 'localhost:9090' # Prometheus itself
                - 'localhost:9100' # Node exporter
        - job_name: 'consul-services'
          consul_sd_configs:
            - server: "localhost:8500"

promtool syntax changes in prometheus version 2

I tried to use this playbook to install prometheus version 2, but it's failing because the right syntax in version 2 is promtool check rules instead of promtool check-rules.
It happens the same for promtool check config.

running in check mode fails for blackbox exporter

when a playbook is run in check mode its failing when trying to elevate permissions of the install directory.

It fails as it has not downloaded the relevant install file so directory does not yet exist

therefore the task that sets the elevated directory permissions needs when: not check_mode needs to be added to task name: Apply elevated privileges to blackbox_exporter for ICMP probe in https://github.com/ernestas-poskus/ansible-prometheus/blob/master/tasks/install-blackbox_exporter.yml

Ansible run fail on when use python 3 Ansible

//Added later
Hello!

During provisioning my Vagrant box with prometheus i have issue as below

Ansible 2.3.2.0 fails during installation of systemd service:
TASK [ernestas-poskus.ansible-prometheus : Install Prometheus systemd service] *** fatal: [default]: FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}

The issue probably occurs because python 3 don't have attribute iteritems, on Ansible with python 2 role works as intended

https://wiki.python.org/moin/Python3.0 (abotu changes between versions)

Kind regards

alert receiver config formatting

in my playbook I have the following var set to define my receivers

prometheus_alert_manager_config_receivers:
  - name: 'default'
    slack_configs:
      - channel: '#operations'
        send_resolved: true
    email_configs:
      - to: 'user@emailaddress'
        send_resolved: true

when the playbook is run the config gets generated like this:

receivers:
-   email_configs:
    -   send_resolved: true
        to: user@emailaddress
    name: default
    slack_configs:
    -   channel: '#operations'
        send_resolved: true

alertmanagers not being configured in prometheus.yml

I had a problem where the alert notification wasn't working, alerts we're showing up in prometheus, but not making it to alertmanager and hence the notification receivers were not working.

I've added the following manually to prometheus.yml and alert notifications is now working via alertmanager and receivers.

alerting:
  alertmanagers:
  - scheme: http
    static_configs:
    - targets:
      - "localhost:9093"

I've had a look at the role variables and can't seem to see any related variables to set these.

notifications Ranging over all received Alerts

Ok I'm not clear on how to define the slack receiver text and description as per https://prometheus.io/docs/alerting/notification_examples/#ranging-over-all-received-alerts for this role:

My config:

  - name: 'default'
    slack_configs:
      - channel: '#alerts'
        username: 'Alert-Manager'
        title: "[[ range $Alerts ]][[ $Annotations.summary ]]\n[[ end ]]"
        text: "[[ range $Alerts ]][[ $Annotations.description ]]\n[[ end ]]"
        send_resolved: true

What is being generated in prometheus.yml

    slack_configs:
    -   channel: '#alerts'
        send_resolved: true
        text: '[[ range $Alerts ]][[ $Annotations.description ]]

            [[ end ]]'
        title: '[[ range $Alerts ]][[ $Annotations.summary ]]

            [[ end ]]'

first it appears that the [[ ]] are not being converted to { } for the receiver fields

secondly I'm not sure if the I'm required to put the $ in front or leave as per the above link i.e. .Alerts and .Annotations.decription etc

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.