|
|
|
@ -4,12 +4,13 @@ from prometheus_client import start_http_server, Gauge
|
|
|
|
|
from time import sleep, mktime
|
|
|
|
|
from dateutil import parser
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
HTTP_PORT = 9401
|
|
|
|
|
BACKUP_DIRECTORY = '/tmp/backup'
|
|
|
|
|
BACKUP_DIRECTORY = '/srv/backup'
|
|
|
|
|
INTERVAL = 30 * 60 # seconds
|
|
|
|
|
|
|
|
|
|
total_chunks = Gauge('borg_repository_total_chunks', 'Number of chunks', ['name'])
|
|
|
|
@ -22,6 +23,13 @@ last_modified = Gauge('borg_repository_last_modified', 'Last modified UNIX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
|
BACKUP_DIRECTORY = sys.argv[1]
|
|
|
|
|
elif len(sys.argv) > 2:
|
|
|
|
|
sys.exit("Invalid number of arguments. Usage: ./prometheus-borgbackup-exporter [backup-directory]")
|
|
|
|
|
|
|
|
|
|
print("Backup directory is: {}".format(BACKUP_DIRECTORY))
|
|
|
|
|
|
|
|
|
|
# Serve metrics over HTTP.
|
|
|
|
|
print("Starting prometheus-orgbackup-exporter on port",
|
|
|
|
|
"{}...".format(HTTP_PORT), end='')
|
|
|
|
@ -41,13 +49,17 @@ if __name__ == '__main__':
|
|
|
|
|
for entry in entries:
|
|
|
|
|
if not entry.is_dir():
|
|
|
|
|
print(">> Ignoring {} since it is not a directory.".format(entry.name))
|
|
|
|
|
elif entry.name[0] == '.':
|
|
|
|
|
print(">> Ignoring {} since it is a dot directory.".format(entry.name))
|
|
|
|
|
else:
|
|
|
|
|
repository_name = entry.name
|
|
|
|
|
repository_path = entry.path
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
print(">> Querying borg for {}...".format(repository_name), end='')
|
|
|
|
|
raw_borg_json = subprocess.check_output(['borg', 'info', '--json', repository_path])
|
|
|
|
|
env = os.environ
|
|
|
|
|
env["BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK"] = "yes"
|
|
|
|
|
raw_borg_json = subprocess.check_output(['borg', 'info', '--json', repository_path], env=env)
|
|
|
|
|
info = json.loads(raw_borg_json)
|
|
|
|
|
|
|
|
|
|
stats = info['cache']['stats']
|
|
|
|
|