Git Product home page Git Product logo

prometheus-barman-exporter's Introduction

Barman exporter for Prometheus

The barman exporter runs barman shell command with experimental JSON output. I am the author of JSON output in Barman so it should work fine until somebody else changes output format which may happen in the future.

By default barman-exporter runs as a service and binds to 127.0.0.1:9780. Metrics are cached and refreshed every hour.

You can run barman-exporter from cron using -f argument to output results to a textfile:

/usr/local/bin/barman-exporter -f /var/lib/prometheus/node_exporter/barman.prom

In such case the node_exporter must point to this path with --collector.textfile.directory option.

Grafana dashboard

You can find basic grafana dashboard in grafana-dashboard.json. It is open for improvements.

Grafana screenshot

Usage

usage: barman-exporter [-h] [-u USER] [-g GROUP] [-m MODE] [-c SECONDS] [-v] [-f TEXTFILE_PATH | -l HOST:PORT | -d]
                       [servers [servers ...]]

Barman exporter

positional arguments:
  servers               Space separated list of servers to check (default: ['all'])

optional arguments:
  -h, --help            show this help message and exit
  -u USER, --user USER  Textfile owner (default: prometheus)
  -g GROUP, --group GROUP
                        Textfile group (default: prometheus)
  -m MODE, --mode MODE  Textfile mode (default: 0644)
  -c SECONDS, --cache-time SECONDS
                        Number of seconds to cache barman output for (default: 3600)
  -v, --version         Show barman exporter version (default: False)
  -f TEXTFILE_PATH, --file TEXTFILE_PATH
                        Save output to textfile (default: None)
  -l HOST:PORT, --listen-address HOST:PORT
                        Address to listen on (default: 127.0.0.1:9780)
  -d, --debug           Print output to stdout (default: False)

Examples:

  • $ /usr/local/bin/barman-exporter postgres-01
  • $ /usr/local/bin/barman-exporter postgres-01 postgres-02
  • $ /usr/local/bin/barman-exporter all
  • $ /usr/local/bin/barman-exporter -l 10.10.10.10:9780 -c 900
  • $ /usr/local/bin/barman-exporter -f /var/lib/prometheus/node_exporter/barman.prom -u prometheus -g prometheus -m 0640 all

Requirements

Python3 and following modules are required to run it:

  • prometheus_client
  • sh

All dependencies will be installed automatically with pip command (see Installation).

Installation

pip3 install barman-exporter

Systemd service file to run barman-exporter as a service

[Unit]
Description=Barman Exporter
After=network-online.target

[Service]
Type=simple
User=barman
Group=barman
ExecStart=/usr/local/bin/barman-exporter -l 10.10.10.10:9780 -c 3600
SyslogIdentifier=barman_exporter
Restart=always

[Install]
WantedBy=multi-user.target

Cron job to run barman-exporter with textfile output

If you don't want to use barman exporter as a service you can run it with -f argument from the cron job. To run it every hour:

0 * * * * /usr/local/bin/barman-exporter -f /var/lib/prometheus/node_exporter/barman.prom

In this mode barman exporter does not require any Prometheus configuration because it uses node-exporter to parse the metrics from a textfile. Remember to use --collector.textfile.directory in node-exporter to define a directory with textfiles.

Prometheus configuration

Please note that barman-exporter is listing all backups which is quite heavy operation to perform and it takes some time. Barman exporter caches its results because execution every 5 seconds would be impossible.

scrape_configs:
  - job_name: barman
    static_configs:
      - targets:
        - 10.10.10.10:9780'

Metrics

  • number=1 label indicates the newest backup
  • barman_backups_size and barman_backup_wal_size show successful backups only. Failed backups will not be listed here.
  • barman_backups_total includes failed backups
  • barman_backups_failedexposes the number of failed backups.
  • barman_last_backup_copy_time shows how long it takes to make a backup
  • barman_up shows all checks from barman check SERVER_NAME command. Output OK is 1.0, FAILED is 0.0.
  • barman_metrics_update shows a timestamp when barman metrics has been last updated

With barman_last_backup and barman_first_backup you can easily calculate when the latest backup was completed:

time() - barman_last_backup{instance="$instance", server="$server"}

Raw metrics

# HELP barman_backup_size Size of available backups
# TYPE barman_backup_size gauge
barman_backup_size{number="1",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="2",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="3",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="4",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="5",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="6",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="7",server="postgres-01"} 1.429365116108e+012
barman_backup_size{number="8",server="postgres-01"} 1.429365116108e+012

# HELP barman_backup_wal_size WAL size of available backups
# TYPE barman_backup_wal_size gauge
barman_backup_wal_size{number="1",server="postgres-01"} 1.94347270144e+011
barman_backup_wal_size{number="2",server="postgres-01"} 3.06553290752e+011
barman_backup_wal_size{number="3",server="postgres-01"} 3.05479548928e+011
barman_backup_wal_size{number="4",server="postgres-01"} 4.79318350233e+011
barman_backup_wal_size{number="5",server="postgres-01"} 2.87333312102e+011
barman_backup_wal_size{number="6",server="postgres-01"} 2.73267294208e+011
barman_backup_wal_size{number="7",server="postgres-01"} 3.65501716889e+011
barman_backup_wal_size{number="8",server="postgres-01"} 2.34075717632e+011

# HELP barman_backups_total Total number of backups
# TYPE barman_backups_total gauge
barman_backups_total{server="postgres-01"} 9.0

# HELP barman_backups_failed Number of failed backups
# TYPE barman_backups_failed gauge
barman_backups_failed{server="postgres-01"} 1.0

# HELP barman_last_backup Last successful backup timestamp
# TYPE barman_last_backup gauge
barman_last_backup{server="postgres-01"} 1.562537102e+09

# HELP barman_last_backup_copy_time Last successful backup copy time
# TYPE barman_last_backup_copy_time gauge
barman_last_backup_copy_time{server="postgres-01"} 18706.918297

# HELP barman_first_backup First successful backup timestamp
# TYPE barman_first_backup gauge
barman_first_backup{server="postgres-01"} 1.561154701e+09

# HELP barman_up Barman status checks
# TYPE barman_up gauge
barman_up{check="archiver_errors",server="postgres-01"} 1.0
barman_up{check="backup_maximum_age",server="postgres-01"} 1.0
barman_up{check="compression_settings",server="postgres-01"} 1.0
barman_up{check="directories",server="postgres-01"} 1.0
barman_up{check="failed_backups",server="postgres-01"} 1.0
barman_up{check="is_superuser",server="postgres-01"} 1.0
barman_up{check="minimum_redundancy_requirements",server="postgres-01"} 1.0
barman_up{check="pg_basebackup",server="postgres-01"} 1.0
barman_up{check="pg_basebackup_compatible",server="postgres-01"} 1.0
barman_up{check="pg_basebackup_supports_tablespaces_mapping",server="postgres-01"} 1.0
barman_up{check="pg_receivexlog",server="postgres-01"} 1.0
barman_up{check="pg_receivexlog_compatible",server="postgres-01"} 1.0
barman_up{check="postgresql",server="postgres-01"} 1.0
barman_up{check="postgresql_streaming",server="postgres-01"} 1.0
barman_up{check="receive_wal_running",server="postgres-01"} 1.0
barman_up{check="replication_slot",server="postgres-01"} 1.0
barman_up{check="retention_policy_settings",server="postgres-01"} 1.0
barman_up{check="systemid_coherence",server="postgres-01"} 1.0
barman_up{check="wal_level",server="postgres-01"} 1.0

# HELP barman_metrics_update Barman metrics update timestamp
# TYPE barman_metrics_update gauge
barman_metrics_update{server="autouncle"} 1.580485601e+09

Development

Upload to PyPi:

source venv/bin/activate
rm -f dist/*
python3 setup.py sdist
twine upload dist/*

prometheus-barman-exporter's People

Contributors

albix avatar eriknayan avatar marcinhlybin avatar thomaspoty avatar valumar 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

prometheus-barman-exporter's Issues

barman cannot start | return version[0] IndexError: list index out of range

hi Team,
I getting error when run #barman-exporter -f ./test.prom -u postgres

root@postgres:~# barman-exporter -f ./test.prom -u postgres
Traceback (most recent call last):
  File "/usr/local/bin/barman-exporter", line 9, in <module>
    load_entry_point('barman-exporter==1.0.7', 'console_scripts', 'barman-exporter')()
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 220, in main
    write_metrics_to_file(args)
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 258, in write_metrics_to_file
    registry = BarmanCollector(Barman(), args.servers)
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 22, in __init__
    self.check_barman_version()
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 25, in check_barman_version
    barman_version = tuple(int(v) for v in self.version().split('.'))
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 37, in version
    return version[0]
IndexError: list index out of range
root@postgres:~# barman -v
2.3

please help me, how to fix the issue
Thanks in advance

Error : too many values to unpack

Hi,
When I manually launch barman-exporter, I got this error :

Traceback (most recent call last):
  File "/usr/local/bin/barman_exporter.py", line 41, in list_backup
    server_name_and_ts, date, size, wal_size = backup_line.split("-")
ValueError: too many values to unpack (expected 4)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/barman_exporter.py", line 154, in <module>
    core.REGISTRY.register(BarmanCollector(args.servers))
  File "/usr/lib/python3.4/site-packages/prometheus_client/registry.py", line 24, in register
    names = self._get_names(collector)
  File "/usr/lib/python3.4/site-packages/prometheus_client/registry.py", line 64, in _get_names
    for metric in desc_func():
  File "/usr/local/bin/barman_exporter.py", line 122, in collect
    backups_done, backups_failed = barman.list_backup(server_name)
  File "/usr/local/bin/barman_exporter.py", line 48, in list_backup
    server_name_and_ts, status = backup_line.split("-")
ValueError: too many values to unpack (expected 2)

barman version is 2.8
Python version is Python 3.4.5

Error running the exporter when installed from pip

I get error

ModuleNotFoundError: No module named 'barman_exporter.barman_exporter'; 'barman_exporter' is not a package

Once I modify the bin wrapper from:

from barman_exporter.barman_exporter import main

to

from barman_exporter import main

it works

I assume the issue is from

'console_scripts': ['barman-exporter=barman_exporter.barman_exporter:main'],

There are two processes after long time running and barman_metrics_update is stuck

After a long time running, barman_metrics_update keeps to be the old value.

   56     1 root     S    23432   1%   1   0% python3 /barman_exporter.py -l 0.0.0.0:9780 -c 15
19844    56 root     S    23440   1%   0   0% python3 /barman_exporter.py -l 0.0.0.0:9780 -c 15

If I use -c 3600 it will work as normal. So I guess it's because in the case of a short cache_time, barman_exporter.py spawns another subprocess and confuses the prometheus scraper.

update readme to show usage with barman json output

It looks like your pull request for barman #234 was accepted and merged. I can run this on my systems that have barman 2.9 deployed.

barman -f json list-backup server01 | jq .

Might be time to re-word the readme, to explain how to use it with the json output in the readme.md

Increment package version

Hello.

You recently accepted a pull request #12.

Could you increment package version please?

In repository we can see version 1.0.7

But in pip3 repos I see 1.0.8 version

pip3 search barman_exporter
barman_exporter (1.0.8)  - Barman exporter for Prometheus

But version 1.0.8 also does not contain changes from this MR.

Python module based exporter does not update metric values

I'm using the Python module based exporter with Barman 2.9 and Python 3.6 on SmartOS (Solaris derivative) and the values of the metrics don't get updated. The values of the metrics are set a single time when the script is started and then they stay the same forever.

This could be due to the fact that I'm running my setup on a somewhat more exotic setup (SmartOS) but I don't really see how this could have such an effect. I did a quick search in barman's source to see if it uses some platform specific things like inotify but I can't find anything of the sort.

I suspect this might be more likely caused by barman 2.9 which was released a couple of weeks ago. Can anyone confirm if they have a working setup with barman 2.9?

Error when no backups for a server

Hello, I get this error if there is a server in the list with no backups yet

ValueError: time data 'None' does not match format '%Y%m%dT%H%M%S'

The program exits after that error, so the remaining servers are not considered, and also a temp file is left

As a workaround I currently do like this:

for s in $(barman list-server); do /usr/local/bin/barman-exporter -f /tmp/barman-$s.prom -u node-exp -g node-exp $s && mv -f /tmp/barman-$s.prom /var/lib/node_exporter; done 2>&1 | systemd-cat -t barman-exporter

/Steffen

barman-exporter service dont start

Hello,

the barman-exporter service has crashed and is not starting. We installed pgbouncer on the server and changed the default port for postgresql and reconfigured barman.

barman check backup and backups show OK, But the exporter does not start.

The error is this:

Traceback (most recent call last):
  File "/opt/prometheus/exporters/barman_exporter/barman_exporter", line 175, in <module>
    core.REGISTRY.register(BarmanCollector(args.servers))
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/registry.py", line 24, in register
    names = self._get_names(collector)
  File "/usr/local/lib/python3.6/site-packages/prometheus_client/registry.py", line 64, in _get_names
    for metric in desc_func():
  File "/opt/prometheus/exporters/barman_exporter/barman_exporter", line 127, in collect
    backups_done, backups_failed = barman.list_backup(server_name)
  File "/opt/prometheus/exporters/barman_exporter/barman_exporter", line 43, in list_backup
    backup['wal_size'] = wal_size.split(":")[1].strip()
IndexError: list index out of range

prevent crash when no-backup is yet available on server

Hello,
first of all. Nice software, keep up the good work!

consider prevent a crash by adding:
if (barman_server.status['first_backup'] and barman_server.status['first_backup'] != "None"):
... to collect_first_backup and collect_last_backup

/best regards

barman-exporter not compatible with prometheus-client 0.15.0

Installation of the barman-exporter package via pip3 resolves the prometheus-client dependency and install version 0.15.0, which causes the following failure when you run / start the service:

$ /usr/local/bin/barman-exporter
Traceback (most recent call last):
  File "/usr/local/bin/barman-exporter", line 7, in <module>
    from barman_exporter.barman_exporter import main
  File "/usr/local/lib/python3.5/dist-packages/barman_exporter/barman_exporter.py", line 8, in <module>
    import prometheus_client
  File "/usr/local/lib/python3.5/dist-packages/prometheus_client/__init__.py", line 3, in <module>
    from . import (
  File "/usr/local/lib/python3.5/dist-packages/prometheus_client/exposition.py", line 194
    timestamp = f' {int(float(line.timestamp) * 1000):d}'

I had to downgrade to prometheus-client 0.9.0 to clear.

barman_backups_total not updated for inactive server

I appreciate that this might be related to barman not listing backups etc. for inactive servers but I had a server that had 5 backups, it correctly shows this in the barman exporter.

I have now deleted the backups and made that server inactive but barman exporter still shows a count of 5.

It seems like either it should not show the metric at all for inactive servers or it should be the correct number (which barman might not tell you!)

Thanks

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.