Skip to content

Commit 82f263e

Browse files
committed
Add script to convert Tirex tilestat JSON to Icinga/Nagios perf data
1 parent 1ee9617 commit 82f263e

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#! /usr/bin/env python3
2+
3+
"""Fetch daily generated data from tirex-tiledir-check.
4+
"""
5+
6+
import argparse
7+
from enum import Enum
8+
import json
9+
import os
10+
import sys
11+
12+
13+
class ServiceStatus(Enum):
14+
OK = 0
15+
WARNING = 1
16+
CRITICAL = 2
17+
UNKNOWN = 3
18+
19+
20+
def respond(status, message, measurements):
21+
if not measurements:
22+
line = "{}: {}\n".format(status.name, message)
23+
else:
24+
line = "{}: {} | {}\n".format(status.name, message, measurements)
25+
print(line)
26+
sys.exit(status.value)
27+
28+
29+
def get_data(path):
30+
with open(path, "r") as f:
31+
json_data = json.load(f)
32+
return json_data
33+
34+
35+
def format_measurement(k, v):
36+
return "'{}'={}".format(k, v)
37+
38+
39+
def join_values(measurements):
40+
parts = []
41+
for m in measurements:
42+
parts.append(format_measurement(m[0], m[1]))
43+
return " ".join(parts)
44+
45+
46+
parser = argparse.ArgumentParser(description="Monitoring plugin for tirex-tiledir-check results. This plugin reads the generated stats and supplies them to Icinga. It does not validate or check the retrieved numbers.")
47+
parser.add_argument("-s", "--style", type=str, help="Style", required=True)
48+
parser.add_argument("-d", "--dir", type=str, help="Path where the JOSN files generated by the nightly job are located.")
49+
args = parser.parse_args()
50+
51+
json_path = os.path.join(args.dir, "tiles-{}.stats".format(args.style))
52+
data = get_data(json_path)
53+
result = []
54+
try:
55+
for style, style_data in data.items():
56+
if style != args.style:
57+
respond(ServiceStatus.UNKNOWN, "Wrong style {} found in {}".format(style, json_path))
58+
for zoom in range(len(style_data)):
59+
result.append(("{}_{:02d}_count".format(style, zoom), style_data[zoom]["count"]))
60+
result.append(("{}_{:02d}_sumsize".format(style, zoom), style_data[zoom]["sumsize"]))
61+
respond(ServiceStatus.OK, "Tirex tile cache stats for style {}".format(args.style), join_values(result))
62+
except KeyError as e:
63+
respond(ServiceStatus.UNKNOWN, "Could not parse JSON data: {}".format(e))

ansible/roles/tileserver_step2/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
loop:
381381
- 'monitoring/mod-tile/check_mod_tile.py'
382382
- 'monitoring/tirex/check_tirex.py'
383+
- 'monitoring/tirex/check_tirex_tilestats.py'
383384

384385
- debug: # noqa unnamed-task
385386
msg: 'Tirex is ready to render tiles now. Please start bulk-rendering of tiles on zoom levels 0 to 12 using the following command:\ntirex-batch --prio 15 map=standard,maxspeed,signals z=0-12 bbox=-180,-80,180,80'

0 commit comments

Comments
 (0)