monitor-promdiscovery


Namemonitor-promdiscovery JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/opsdis/monitor-promdiscovery
SummaryA Prometheus file based service discovery for Icinga2 and OP5 Monitor
upload_time2024-01-20 08:19:28
maintainer
docs_urlNone
authorthenodon
requires_python>=3.6
licenseGPLv3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/monitor-promdiscovery.svg)](https://badge.fury.io/py/monitor-promdiscovery)

monitor-promdiscovery
------------------------

# Overview
The *monitor-promdiscovery* tool generate file-based service discovery files for Prometheus, for the 
[monitor-exporter](https://github.com/opsdis/monitor-exporter) and [icinga2-exporter](https://github.com/opsdis/icinga2-exporter).
The tool is typically run from cron or equivalent tool to check OP5 Monitor or Icinga2 for hosts service that should be 
scraped for performance metrics by the exporters.  
For a host to be detected, it must be a part of hostgroup(s) or servicegroup(s) that is defined in the configuration 
file. For a servicegroup(s) configuration all hosts that has at least on service in the configured servicegroup(s) will
be added.
> Servicegroups configuration is not supported for icinga2

# Flow

![Flow overview](https://github.com/opsdis/monitor-promdiscovery/raw/master/doc/overview.png)

 1. *monitor-promdiscovery* is executed at regular intervals, e.g. every minute, by cron.
 2. *monitor-promdiscovery* performs a filter query against the configured Monitor instance for all hosts that are part of a specific hostgroup. All hosts in the hostgroup(s) will be scraped for all their services' performance data
 *monitor-exporter* or *icinga2-exporter*. 
 3. *monitor-promdiscovery* checks against the configured file-based discovery if any host from the above call is new or not existing anymore.
 4. Only if there is not a match the file-based discovery file will be updated
 5. If the file is updated, Prometheus will reload the configuration file.

# Running
## Only use configuration file 

	python -m monitor_promdiscovery -f ./config.yml

## Override system property in the configuration file 

	python -m monitor_promdiscovery -f ./config.yml -s <system>
	
> Where *<system>* can be either icinga2 or monitor
	
# Installing
1. Check out / clone the git repo.
2. Install dependencies
    
    `pip install -r requirements.txt`
     
3. Build a distribution 

    `python setup.py sdist`

4. Install locally
 
    `pip install dist/monitor-promdiscovery-X.Y.Z.tar.gz`
     


# Configuration
The *monitor-promdiscovery* configuration file should be rather self-explanatory. 

>NB! Only icinga2 or op5monitor has to be configured. If both are used, use the -s switch instead of configure
>system in the property file. Using the below config executing without specifiying -s <system>, the icinga2 entry will be used.

```yaml
# The system can be either op5monitor or icinga2 
system: icinga2

op5monitor:  
  url: https://monitor.local  
  user: monitor  
  passwd: monitor  
  # Connection timeout - default 5
  # timeout: 5
  # Verify ssl - default False
  # verify: False

  # The hostgroup(s) used to select hosts as targets  
  hostgroup: 
    - prometheus
  # The servicegroup(s) used to select hosts as targets
  # Will include all hosts that has at least on service in the configured servicegroup(s)
  servicegroup:
    - servicepoint
  prometheus:  
    # path where to create the file-based discovery file - must be set  
    sd_file: <sd_directory>/monitor_sd.yml  
    # Additional labels to tag metrics with - optional
    labels:  
      source: monitor  
      env: prod

icinga2:
  url: https://127.0.0.1:5665
  user: root
  passwd: cf593406ffcfd2ef
  # Connection timeout - default 5
  # timeout: 5
  # Verify ssl - default False
  # verify: False

  # The hostgroup used to select hosts as targets
  hostgroup: 
    - prometheus
    - linux_servers
  prometheus:
    # path where to create the file-based discovery file - must be set
    sd_file: /home/andersh/programs/prometheus/sd/icinga2_sd.yml
    # Additional labels to tag metrics with - optional
    labels:
      source: icinga2
      env: prod

logger:
  # Path and name for the log file. If not set sent to stdout
  logfile: monitor-promdiscovery.log
  # Format if day will have current day as post fix
  # format: day
  # Log level
  #level: INFO

``` 

> The hostgroup property can be both a single value or a list of different hostgroups as shown above.

## Prometheus configuration
The Prometheus configuration file would typical have the following job configuration in the scrape_configs section for the *monitor-exporter*:  
```yaml

  - job_name: 'op5'
    scrape_interval: 2m
    metrics_path: /metrics
    file_sd_configs:
    - files:
      - 'sd/monitor_sd.yml'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        # The address for the monitor-exporter
        replacement: localhost:5000

```
And the format for icinga2 is almost the same:
```yaml
  - job_name: 'icinga2'
    scrape_interval: 2m
    metrics_path: /metrics
    file_sd_configs:
    - files:
      - 'sd/icinga2_sd.yml'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        # The address for the monitor-exporter
        replacement: localhost:5000
```

> The `file_sd_configs` must have the same filename as created by the tool, as defined in the configuration file. 

# System requirement
Python 3.6

For required packages, please review `requirements.txt`



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/opsdis/monitor-promdiscovery",
    "name": "monitor-promdiscovery",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "thenodon",
    "author_email": "anders@opsdis.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/6f/61666b1b9c94b66effbd325ddfa57957b53e380ea859f5e86ce9c2dcd73b/monitor-promdiscovery-0.2.1.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/monitor-promdiscovery.svg)](https://badge.fury.io/py/monitor-promdiscovery)\n\nmonitor-promdiscovery\n------------------------\n\n# Overview\nThe *monitor-promdiscovery* tool generate file-based service discovery files for Prometheus, for the \n[monitor-exporter](https://github.com/opsdis/monitor-exporter) and [icinga2-exporter](https://github.com/opsdis/icinga2-exporter).\nThe tool is typically run from cron or equivalent tool to check OP5 Monitor or Icinga2 for hosts service that should be \nscraped for performance metrics by the exporters.  \nFor a host to be detected, it must be a part of hostgroup(s) or servicegroup(s) that is defined in the configuration \nfile. For a servicegroup(s) configuration all hosts that has at least on service in the configured servicegroup(s) will\nbe added.\n> Servicegroups configuration is not supported for icinga2\n\n# Flow\n\n![Flow overview](https://github.com/opsdis/monitor-promdiscovery/raw/master/doc/overview.png)\n\n 1. *monitor-promdiscovery* is executed at regular intervals, e.g. every minute, by cron.\n 2. *monitor-promdiscovery* performs a filter query against the configured Monitor instance for all hosts that are part of a specific hostgroup. All hosts in the hostgroup(s) will be scraped for all their services' performance data\n *monitor-exporter* or *icinga2-exporter*. \n 3. *monitor-promdiscovery* checks against the configured file-based discovery if any host from the above call is new or not existing anymore.\n 4. Only if there is not a match the file-based discovery file will be updated\n 5. If the file is updated, Prometheus will reload the configuration file.\n\n# Running\n## Only use configuration file \n\n\tpython -m monitor_promdiscovery -f ./config.yml\n\n## Override system property in the configuration file \n\n\tpython -m monitor_promdiscovery -f ./config.yml -s <system>\n\t\n> Where *<system>* can be either icinga2 or monitor\n\t\n# Installing\n1. Check out / clone the git repo.\n2. Install dependencies\n    \n    `pip install -r requirements.txt`\n     \n3. Build a distribution \n\n    `python setup.py sdist`\n\n4. Install locally\n \n    `pip install dist/monitor-promdiscovery-X.Y.Z.tar.gz`\n     \n\n\n# Configuration\nThe *monitor-promdiscovery* configuration file should be rather self-explanatory. \n\n>NB! Only icinga2 or op5monitor has to be configured. If both are used, use the -s switch instead of configure\n>system in the property file. Using the below config executing without specifiying -s <system>, the icinga2 entry will be used.\n\n```yaml\n# The system can be either op5monitor or icinga2 \nsystem: icinga2\n\nop5monitor:  \n  url: https://monitor.local  \n  user: monitor  \n  passwd: monitor  \n  # Connection timeout - default 5\n  # timeout: 5\n  # Verify ssl - default False\n  # verify: False\n\n  # The hostgroup(s) used to select hosts as targets  \n  hostgroup: \n    - prometheus\n  # The servicegroup(s) used to select hosts as targets\n  # Will include all hosts that has at least on service in the configured servicegroup(s)\n  servicegroup:\n    - servicepoint\n  prometheus:  \n    # path where to create the file-based discovery file - must be set  \n    sd_file: <sd_directory>/monitor_sd.yml  \n    # Additional labels to tag metrics with - optional\n    labels:  \n      source: monitor  \n      env: prod\n\nicinga2:\n  url: https://127.0.0.1:5665\n  user: root\n  passwd: cf593406ffcfd2ef\n  # Connection timeout - default 5\n  # timeout: 5\n  # Verify ssl - default False\n  # verify: False\n\n  # The hostgroup used to select hosts as targets\n  hostgroup: \n    - prometheus\n    - linux_servers\n  prometheus:\n    # path where to create the file-based discovery file - must be set\n    sd_file: /home/andersh/programs/prometheus/sd/icinga2_sd.yml\n    # Additional labels to tag metrics with - optional\n    labels:\n      source: icinga2\n      env: prod\n\nlogger:\n  # Path and name for the log file. If not set sent to stdout\n  logfile: monitor-promdiscovery.log\n  # Format if day will have current day as post fix\n  # format: day\n  # Log level\n  #level: INFO\n\n``` \n\n> The hostgroup property can be both a single value or a list of different hostgroups as shown above.\n\n## Prometheus configuration\nThe Prometheus configuration file would typical have the following job configuration in the scrape_configs section for the *monitor-exporter*:  \n```yaml\n\n  - job_name: 'op5'\n    scrape_interval: 2m\n    metrics_path: /metrics\n    file_sd_configs:\n    - files:\n      - 'sd/monitor_sd.yml'\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        # The address for the monitor-exporter\n        replacement: localhost:5000\n\n```\nAnd the format for icinga2 is almost the same:\n```yaml\n  - job_name: 'icinga2'\n    scrape_interval: 2m\n    metrics_path: /metrics\n    file_sd_configs:\n    - files:\n      - 'sd/icinga2_sd.yml'\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        # The address for the monitor-exporter\n        replacement: localhost:5000\n```\n\n> The `file_sd_configs` must have the same filename as created by the tool, as defined in the configuration file. \n\n# System requirement\nPython 3.6\n\nFor required packages, please review `requirements.txt`\n\n\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "A Prometheus file based service discovery for Icinga2 and OP5 Monitor",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/opsdis/monitor-promdiscovery"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58d6ef594559e0d2277efa548669b766a71888554d615a090ed5c18ba23be260",
                "md5": "d55845101caf3a2b693a2fcaec4c46c9",
                "sha256": "eace8d9b6506ba4ae42fdbe207dbdca1e702faef28f9d2487e061631cde56cb3"
            },
            "downloads": -1,
            "filename": "monitor_promdiscovery-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d55845101caf3a2b693a2fcaec4c46c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 38734,
            "upload_time": "2024-01-20T08:19:27",
            "upload_time_iso_8601": "2024-01-20T08:19:27.242864Z",
            "url": "https://files.pythonhosted.org/packages/58/d6/ef594559e0d2277efa548669b766a71888554d615a090ed5c18ba23be260/monitor_promdiscovery-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c06f61666b1b9c94b66effbd325ddfa57957b53e380ea859f5e86ce9c2dcd73b",
                "md5": "517a0672151145eb1eb12858e1368938",
                "sha256": "94d72a6e10489349d15d1f1a01c7af9b809ff609fb1b411df4fac2c28b361f5e"
            },
            "downloads": -1,
            "filename": "monitor-promdiscovery-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "517a0672151145eb1eb12858e1368938",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 33748,
            "upload_time": "2024-01-20T08:19:28",
            "upload_time_iso_8601": "2024-01-20T08:19:28.518670Z",
            "url": "https://files.pythonhosted.org/packages/c0/6f/61666b1b9c94b66effbd325ddfa57957b53e380ea859f5e86ce9c2dcd73b/monitor-promdiscovery-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-20 08:19:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opsdis",
    "github_project": "monitor-promdiscovery",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "monitor-promdiscovery"
}
        
Elapsed time: 0.50010s