pdnsbackup 0.12.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pdnsbackup-0.12.0/pdnsbackup.egg-info → pdnsbackup-1.0.2}/PKG-INFO +1 -1
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup/export.py +17 -13
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2/pdnsbackup.egg-info}/PKG-INFO +1 -1
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/setup.py +1 -1
- pdnsbackup-1.0.2/tests/test_export_metrics.py +84 -0
- pdnsbackup-0.12.0/tests/test_export_metrics.py +0 -31
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/LICENSE +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/MANIFEST.in +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/README.md +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup/__init__.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup/backend.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup/config.yml +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup/parser.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup.egg-info/SOURCES.txt +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup.egg-info/dependency_links.txt +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup.egg-info/entry_points.txt +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup.egg-info/requires.txt +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/pdnsbackup.egg-info/top_level.txt +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/setup.cfg +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/tests/test_config.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/tests/test_export_file.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/tests/test_import.py +0 -0
- {pdnsbackup-0.12.0 → pdnsbackup-1.0.2}/tests/test_parser.py +0 -0
|
@@ -154,33 +154,37 @@ def export_metrics(cfg: dict, zones: dict, status: bool):
|
|
|
154
154
|
metric_status = prometheus_client.Gauge(
|
|
155
155
|
'pdnsbackup_status',
|
|
156
156
|
'status of the backup',
|
|
157
|
-
['date', 'error'],
|
|
157
|
+
['date', 'database', 'error'],
|
|
158
158
|
registry=registry)
|
|
159
159
|
metric_zones = prometheus_client.Gauge(
|
|
160
160
|
'pdnsbackup_zones_total',
|
|
161
|
-
'total number of zones',
|
|
161
|
+
'total number of zones',
|
|
162
|
+
['database'],
|
|
162
163
|
registry=registry)
|
|
163
164
|
metric_zones_empty = prometheus_client.Gauge(
|
|
164
165
|
'pdnsbackup_zones_empty_total',
|
|
165
|
-
'total number of empty zones',
|
|
166
|
+
'total number of empty zones',
|
|
167
|
+
['database'],
|
|
166
168
|
registry=registry)
|
|
167
169
|
metrics_records = prometheus_client.Gauge(
|
|
168
170
|
'pdnsbackup_records_total',
|
|
169
171
|
'total number of records per zone',
|
|
170
|
-
['zone'],
|
|
172
|
+
['zone', 'database'],
|
|
171
173
|
registry=registry)
|
|
172
174
|
metrics_wildcards = prometheus_client.Gauge(
|
|
173
175
|
'pdnsbackup_wildcards_total',
|
|
174
176
|
'total number of wildcards',
|
|
177
|
+
['database'],
|
|
175
178
|
registry=registry)
|
|
176
179
|
metrics_delegations = prometheus_client.Gauge(
|
|
177
180
|
'pdnsbackup_delegations_total',
|
|
178
181
|
'total number of delegations',
|
|
182
|
+
['database'],
|
|
179
183
|
registry=registry)
|
|
180
184
|
metrics_rrtypes = prometheus_client.Gauge(
|
|
181
185
|
'pdnsbackup_rrtypes_total',
|
|
182
186
|
'total number of records per rrtypes',
|
|
183
|
-
['rrtype'],
|
|
187
|
+
['rrtype', 'database'],
|
|
184
188
|
registry=registry)
|
|
185
189
|
try:
|
|
186
190
|
logger.debug("write metrics to file (%s)" % cfg["metrics-prom-file"])
|
|
@@ -188,16 +192,16 @@ def export_metrics(cfg: dict, zones: dict, status: bool):
|
|
|
188
192
|
# update metrics
|
|
189
193
|
for name, zone in zones.items():
|
|
190
194
|
# number of empty zones
|
|
191
|
-
if zone["stats"]["records"] == 0: metric_zones_empty.inc(1)
|
|
192
|
-
metrics_wildcards.inc(zone["stats"]["wilcards"])
|
|
193
|
-
metrics_delegations.inc(zone["stats"]["delegations"])
|
|
194
|
-
metric_zones.inc(1)
|
|
195
|
-
metrics_records.labels(zone="").inc(zone["stats"]["records"])
|
|
196
|
-
metrics_records.labels(zone=name).set(zone["stats"]["records"])
|
|
195
|
+
if zone["stats"]["records"] == 0: metric_zones_empty.labels(database=cfg["gmysql-dbname"]).inc(1)
|
|
196
|
+
metrics_wildcards.labels(database=cfg["gmysql-dbname"]).inc(zone["stats"]["wilcards"])
|
|
197
|
+
metrics_delegations.labels(database=cfg["gmysql-dbname"]).inc(zone["stats"]["delegations"])
|
|
198
|
+
metric_zones.labels(database=cfg["gmysql-dbname"]).inc(1)
|
|
199
|
+
metrics_records.labels(zone=cfg["gmysql-dbname"], database="").inc(zone["stats"]["records"])
|
|
200
|
+
metrics_records.labels(zone=name, database=cfg["gmysql-dbname"]).set(zone["stats"]["records"])
|
|
197
201
|
for k,v in zone["stats"]["rrtypes"].items():
|
|
198
|
-
metrics_rrtypes.labels(rrtype=k.upper()).inc(v)
|
|
202
|
+
metrics_rrtypes.labels(rrtype=k.upper(), database=cfg["gmysql-dbname"]).inc(v)
|
|
199
203
|
|
|
200
|
-
metric_status.labels(date=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), error= int(not status)).set(1.0)
|
|
204
|
+
metric_status.labels(date=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), database=cfg["gmysql-dbname"], error= int(not status)).set(1.0)
|
|
201
205
|
|
|
202
206
|
prometheus_client.write_to_textfile(cfg["metrics-prom-file"], registry)
|
|
203
207
|
logger.info("export metrics - success")
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
from prometheus_client.parser import text_string_to_metric_families
|
|
5
|
+
|
|
6
|
+
import pdnsbackup
|
|
7
|
+
from pdnsbackup import export
|
|
8
|
+
|
|
9
|
+
class args:
|
|
10
|
+
e = None
|
|
11
|
+
c = None
|
|
12
|
+
v = False
|
|
13
|
+
|
|
14
|
+
zone_direct = { 'example.com': {
|
|
15
|
+
'stats': {
|
|
16
|
+
"records": 10, "wilcards": 2, "delegations": 0,
|
|
17
|
+
"rrtypes": { "a": 1, "aaaa": 0, "txt": 0, "ptr": 0, "cname": 0,
|
|
18
|
+
"srv": 0, "mx": 0, "ns": 2, "others": 4},
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class TestExportMetrics(unittest.TestCase):
|
|
24
|
+
def test_export_metrics(self):
|
|
25
|
+
cfg = pdnsbackup.setup_config(args, ignore_env=True)
|
|
26
|
+
cfg["file-enabled"] = False
|
|
27
|
+
cfg["metrics-enabled"] = True
|
|
28
|
+
|
|
29
|
+
success = export.backup(cfg, zone_direct)
|
|
30
|
+
self.assertTrue(success)
|
|
31
|
+
|
|
32
|
+
self.assertTrue(os.path.exists(cfg["metrics-prom-file"]))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TestMetricsContent(unittest.TestCase):
|
|
36
|
+
def test_export_metrics_content(self):
|
|
37
|
+
try:
|
|
38
|
+
cfg = pdnsbackup.setup_config(args, ignore_env=True)
|
|
39
|
+
cfg["file-enabled"] = False
|
|
40
|
+
cfg["metrics-enabled"] = True
|
|
41
|
+
|
|
42
|
+
success = export.backup(cfg, zone_direct)
|
|
43
|
+
self.assertTrue(success)
|
|
44
|
+
|
|
45
|
+
# Parse and validate metrics content
|
|
46
|
+
with open(cfg["metrics-prom-file"], "r") as f:
|
|
47
|
+
metrics_data = f.read()
|
|
48
|
+
|
|
49
|
+
metrics = {
|
|
50
|
+
metric.name: metric for family in text_string_to_metric_families(metrics_data) for metric in family.samples
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Validate specific metrics
|
|
54
|
+
self.assertIn("pdnsbackup_status", metrics)
|
|
55
|
+
self.assertIn("pdnsbackup_zones_total", metrics)
|
|
56
|
+
self.assertIn("pdnsbackup_records_total", metrics)
|
|
57
|
+
self.assertIn("pdnsbackup_rrtypes_total", metrics)
|
|
58
|
+
self.assertIn("pdnsbackup_wildcards_total", metrics)
|
|
59
|
+
self.assertIn("pdnsbackup_delegations_total", metrics)
|
|
60
|
+
|
|
61
|
+
self.assertEqual(metrics["pdnsbackup_status"].value, 1.0)
|
|
62
|
+
self.assertEqual(metrics["pdnsbackup_status"].labels["database"], "pdns")
|
|
63
|
+
|
|
64
|
+
self.assertEqual(metrics["pdnsbackup_zones_total"].value, 1.0)
|
|
65
|
+
self.assertEqual(metrics["pdnsbackup_zones_total"].labels["database"], "pdns")
|
|
66
|
+
|
|
67
|
+
self.assertEqual(metrics["pdnsbackup_records_total"].value, 10.0)
|
|
68
|
+
self.assertEqual(metrics["pdnsbackup_records_total"].labels["database"], "pdns")
|
|
69
|
+
|
|
70
|
+
self.assertEqual(metrics["pdnsbackup_wildcards_total"].value, 2.0)
|
|
71
|
+
self.assertEqual(metrics["pdnsbackup_wildcards_total"].labels["database"], "pdns")
|
|
72
|
+
|
|
73
|
+
self.assertEqual(metrics["pdnsbackup_delegations_total"].value, 0.0)
|
|
74
|
+
self.assertEqual(metrics["pdnsbackup_delegations_total"].labels["database"], "pdns")
|
|
75
|
+
|
|
76
|
+
# Check the label "zone" exists and has the correct value
|
|
77
|
+
record_metric = metrics["pdnsbackup_records_total"]
|
|
78
|
+
self.assertEqual(record_metric.labels["zone"], "example.com")
|
|
79
|
+
self.assertEqual(record_metric.labels["database"], "pdns")
|
|
80
|
+
self.assertEqual(record_metric.value, 10.0)
|
|
81
|
+
finally:
|
|
82
|
+
# Cleanup temporary file
|
|
83
|
+
if os.path.exists(cfg["metrics-prom-file"]):
|
|
84
|
+
os.remove(cfg["metrics-prom-file"])
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
import pdnsbackup
|
|
5
|
-
from pdnsbackup import export
|
|
6
|
-
|
|
7
|
-
class args:
|
|
8
|
-
e = None
|
|
9
|
-
c = None
|
|
10
|
-
v = False
|
|
11
|
-
|
|
12
|
-
zone_direct = { 'example.com': {
|
|
13
|
-
'stats': {
|
|
14
|
-
"records": 10, "wilcards": 2, "delegations": 0,
|
|
15
|
-
"rrtypes": { "a": 1, "aaaa": 0, "txt": 0, "ptr": 0, "cname": 0,
|
|
16
|
-
"srv": 0, "mx": 0, "ns": 2, "others": 4},
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class TestExportMetrics(unittest.TestCase):
|
|
22
|
-
def test_export_metrics(self):
|
|
23
|
-
cfg = pdnsbackup.setup_config(args, ignore_env=True)
|
|
24
|
-
cfg["file-enabled"] = False
|
|
25
|
-
cfg["metrics-enabled"] = True
|
|
26
|
-
|
|
27
|
-
success = export.backup(cfg, zone_direct)
|
|
28
|
-
self.assertTrue(success)
|
|
29
|
-
|
|
30
|
-
self.assertTrue(os.path.exists(cfg["metrics-prom-file"]))
|
|
31
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|