Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple proof of concept script for exporting urbackup status to prometheus, using prometheus_client and urbackup-server-web-api-wrapper packages
#!/usr/bin/env python3
import urbackup_api
def floatWithDefault(x, default=0.0):
try:
return float(x)
except ValueError:
return default
class UrbackupCollector(object):
def __init__(self, server, username, password):
self.api = urbackup_api.urbackup_server(server, username, password)
def collect(self):
commonLabelNames = [
"client_name",
"client_group",
"client_id",
"client_version",
"client_os_version"]
clientOnline = prometheus_client.core.GaugeMetricFamily(
"urbackup_client_online",
"Wether or not the client is answering the server",
labels=commonLabelNames)
clientStatus = prometheus_client.core.GaugeMetricFamily(
"urbackup_client_status",
"Status Numner, purpose unknown",
labels=commonLabelNames)
lastSeen = prometheus_client.core.GaugeMetricFamily(
"urbackup_client_lastseen",
"Timestamp the client was last seen online",
labels=commonLabelNames)
backupOk = prometheus_client.core.GaugeMetricFamily(
"urbackup_backup_ok",
"Wether or not the last backup was successful",
labels=commonLabelNames + ["backup_type",])
backupIssues = prometheus_client.core.GaugeMetricFamily(
"urbackup_backup_issues",
"Number of issues during the last backup",
labels=commonLabelNames + ["backup_type",])
lastBackup = prometheus_client.core.GaugeMetricFamily(
"urbackup_backup_lasttime",
"Timestamp of the last backup",
labels=commonLabelNames + ["backup_type",])
for client in self.api.get_status():
commonLabelValues = [client["name"],
client.get("groupname", "N/A"),
str(client["id"]),
client.get("client_version_string", "N/A"),
client.get("os_version_string", "N/A")]
clientOnline.add_metric(commonLabelValues, float(client["online"]))
clientStatus.add_metric(commonLabelValues, float(client["status"]))
lastSeen.add_metric(commonLabelValues, floatWithDefault(client["lastseen"], 0.0))
backupOk.add_metric(commonLabelValues + ["file",], float(client["file_ok"]))
backupOk.add_metric(commonLabelValues + ["image",], float(client["image_ok"]))
backupIssues.add_metric(commonLabelValues + ["file",], float(client.get("last_filebackup_issues", 0.0)))
#does not show up in my output
#backupIssues.add_metric(commonLabelValues + ["image",], float(client["last_imagebackup_issues"]))
lastBackup.add_metric(commonLabelValues + ["file",], floatWithDefault(client["lastbackup"], 0.0))
lastBackup.add_metric(commonLabelValues + ["image",], floatWithDefault(client["lastbackup_image"], 0.0))
yield clientOnline
yield clientStatus
yield lastSeen
yield backupOk
yield backupIssues
yield lastBackup
if __name__ == "__main__":
import prometheus_client, prometheus_client.core
import time
prometheus_client.core.REGISTRY.register(
UrbackupCollector("http://localhost:55414/x", "admin", "wagRx2tEaJfw"))
prometheus_client.start_http_server(1234)
while True:
time.sleep(1)
@h3po

This comment has been minimized.

Copy link
Owner Author

h3po commented Jul 20, 2017

oops its time to set a new password...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.