{"id":19109968,"url":"https://github.com/coopdevs/monitoring-role","last_synced_at":"2026-02-08T19:04:00.286Z","repository":{"id":37095484,"uuid":"217354772","full_name":"coopdevs/monitoring-role","owner":"coopdevs","description":"Ansible role to install exporter tools to monitor hosts remotely","archived":false,"fork":false,"pushed_at":"2024-09-10T15:30:24.000Z","size":77,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-29T07:43:19.396Z","etag":null,"topics":["ansible","ansible-role","grafana","monitoring","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Jinja","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coopdevs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-24T17:24:30.000Z","updated_at":"2024-09-10T15:28:36.000Z","dependencies_parsed_at":"2024-09-10T16:37:30.933Z","dependency_job_id":"05a91e2c-747a-48b0-8192-037cb908f20f","html_url":"https://github.com/coopdevs/monitoring-role","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/coopdevs/monitoring-role","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coopdevs%2Fmonitoring-role","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coopdevs%2Fmonitoring-role/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coopdevs%2Fmonitoring-role/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coopdevs%2Fmonitoring-role/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coopdevs","download_url":"https://codeload.github.com/coopdevs/monitoring-role/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coopdevs%2Fmonitoring-role/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265716306,"owners_count":23816354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-role","grafana","monitoring","prometheus"],"created_at":"2024-11-09T04:23:02.784Z","updated_at":"2026-02-08T19:03:55.267Z","avatar_url":"https://github.com/coopdevs.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Monitoring Role [![Ansible Role](https://img.shields.io/ansible/role/44192)](https://galaxy.ansible.com/coopdevs/monitoring_role)\n\nAn Ansible role for maintaining monitoring tools of the Grafana ecosystem.\n\nUses docker to install Prometheus and Loki exporters:\n* `nodeexporter`: prometheus exporter that collects general data about the state of a host.\n* `postgresexporter`: prometheus exporter that monitors the state of Postgreql server\n* `promtail`: the main exporter for Loki, a logs server similar to Prometheus and compatible with Grafana.\n\nThis role supports some applications with their default logging format:\n* [Odoo12](https://github.com/coopdevs/odoo-role)\n* [Coopdevs backups](https://github.com/coopdevs/backups-role/)\n* [`auth.log`](templates/promtail-config-apps/auth.j2)\n\nBesides, it supports a [custom exporter](https://github.com/stfsy/prometheus-what-active-users-exporter) that exposes the active users in the system.\n\n## Using this role\n\n### Public variables\n\n**NodeExporter**\n```yaml\n# defaults/main.yaml\nmonitoring_nexporter_enabled: true\nmonitoring_nexporter_host: 127.0.0.1\nmonitoring_nexporter_port: 9100\nmonitoring_nexporter_docker_bind: \"127.0.0.1:127.0.0.1:9100\"\nmonitoring_nexporter_container_name: nexporter\nmonitoring_nexporter_image_version: latest\n```\n\n**PostgresqlExporter**\n```yaml\nmonitoring_postgres_exporter_enabled: true\nmonitoring_postgres_exporter_pg_user: \"monitor_user\"\n```\n\n**Promtail**\n```yaml\n# defaults/main.yaml\nmonitoring_promtail_enabled: true\nmonitoring_promtail_host: 127.0.0.1\nmonitoring_promtail_port: 9080\nmonitoring_promtail_docker_bind: \"127.0.0.1:127.0.0.1:9080\"\nmonitoring_promtail_container_name: promtail\nmonitoring_promtail_image_version: latest\n\nmonitoring_promtail_modules_enabled:\n  - \"app2\"\n\nmonitoring_promtail_modules_available:\n  app1:\n    log_path: \"/var/log/app1/error.log\"\n    template: \"app1.j2\"\n  app2:\n    log_path: \"/opt/app2/log/app2.log\"\n    template: \"app2.j2\"\n\nmonitoring_promtail_config_dir: \"/etc/promtail\"\nmonitoring_promtail_config_filename: \"config.yml\"\n```\n\n**Active users**\n```yaml\nmonitoring_users_enabled: true\nmonitoring_users_host: 127.0.0.1\nmonitoring_users_port: 9839\nmonitoring_users_endpoint: \"/metrics\"\nmonitoring_users_prefix: \"what\"\nmonitoring_users_with_timestamp: false\nmonitoring_users_scrape_interval: 5000\n```\n\n### Secret variables\n\n**Promtail**\n```yaml\nmonitoring_loki_user: \"1234\"\nmonitoring_loki_key: \"eyJrIjoiM2VlZmM2NmQ4ZTQ4ZmE3MDRmZDBmMGE0YzNlNTE1MzRjZDdjNDY0N2YiLCJuIjoieW91ciBncmFmYW5hIGNsb3VkIGtleSIsImlkIjoxMjM0NTZ9\"\nmonitoring_loki_hostname: \"logs-somewhere.grafana.net\"\n```\n\n**PostgresqlExporter**\n```yaml\nmonitoring_postgres_exporter_pg_password: \"3%hyZ\u0026toNZ#Xn74\"\nmonitoring_postgres_exporter_pg_port: \"3456\"\n```\n### Example playbooks\n\n**Odoo with promtail**\n```yaml\n# playbooks/odoo-promtail.yml\n---\n- name: Install Odoo with logs monitoring\n  hosts: servers\n  become: yes\n  roles:\n    - role: coopdevs.odoo_role\n    - role: coopdevs.monitoring_role\n      vars:\n        monitoring_nexporter_enabled: false\n        monitoring_promtail_enabled: true\n        monitoring_promtail_modules_enabled: [ \"odoo\" ]\n        monitoring_loki_user: \"1234\"\n        monitoring_loki_key: \"eyJrIjoiM2VlZmM2NmQ4ZTQ4ZmE3MDRmZDBmMGE0YzNlNTE1MzRjZDdjNDY0N2YiLCJuIjoieW91ciBncmFmYW5hIGNsb3VkIGtleSIsImlkIjoxMjM0NTZ9\"\n        monitoring_loki_hostname: \"logs-somewhere.grafana.net\"\n```\n\n**PostgreSQL with system metrics**\n```yaml\n# playbooks/postgres-nexporter.yml\n---\n- name: Install a database server with exposed system metrics\n  hosts: servers\n  become: yes\n  roles:\n    - role: geerlingguy.postgresql\n    - role: coopdevs.monitoring_role\n      vars:\n        monitoring_nexporter_enabled: true\n        monitoring_promtail_enabled: false\n```\n\n## Security\n\nThis role exposes through an HTTP server lots of data that can be potentially exploited. By default, it listens to a loopback adress, not public from the internet.\n\nHowever, you probably want an external Prometheus server to fetch this data periodically. To this end, and to protect the data, some sort of authentication from the Prometheus server against the host is needed.\n\nOne approach is to leave the exporters binding to localhost and then set up a reverse proxy before them with Basic Authentication, using Nginx. The management of this set up and of the keys implied are out of the scope of this role.\n\n## Extension\n\n### A prometheus exporter\n\nTo add a new prometheus exporter:\n1. Copy the `defaults/main.yml` section from Node Exporter at the same file and change all `nexporter` terms for yours, for instance, `someexporter`\n2. Copy the `templates/monitoring-docker-compose.yml.j2` section of Node Exporter and again, rename and adapt to your needs.\n3. Adapt `meta/main.yml`: add a tag, change description if needed.\n4. Update `README.md`\n\n### A promtail module for a new app\n\nTo add compatibility for an app that is not supported yet, do:\n1. Declare it at `monitoring_promtail_modules_available`. Log path depends on the app, the template name you decide it here.\n2. Copy the `templates/promtail-config-apps/odoo-role.j2` to the same dir but with filename `new-app.j2`\n3. Edit template accordingly to your app. Check the [official docs](https://github.com/grafana/loki/tree/master/docs/clients/promtail).\n  * You can test the regex at [regexr](https://regexr.com/) in \"server mode\" or [regex101.com](https://regex101.com)\n    Include a comment with a couple of log entries for sake of clarity, it will help future regex readers.\n  * Set the `labels` stage to define which labels are exported to Loki, among all of the collected ones.\n  * Set the `timestamp` stage to timestamp the log line with the real one instead of the time that promtail scraped it.\n      * Include milliseconds only if possible. Golang only understands fullstop '.' as decimal separator. If your app uses ',' it doesn't.\n        See golang's issue [#6189](https://github.com/golang/go/issues/6189)\n      * Include timezone either through the parsing as in `backups-role.j2` or manually as in `odoo-role.j2`\n  * Optionally include a `match` stage if you want to drop entries that do not match your regex\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoopdevs%2Fmonitoring-role","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoopdevs%2Fmonitoring-role","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoopdevs%2Fmonitoring-role/lists"}