|
4 | 4 |
|
5 | 5 | """ |
6 | 6 |
|
7 | | -from __future__ import print_function |
8 | | - |
9 | 7 | import datetime |
10 | 8 | import glob |
11 | 9 | import json |
|
14 | 12 | import sys |
15 | 13 | from optparse import OptionParser |
16 | 14 |
|
| 15 | +import statsd |
| 16 | + |
17 | 17 | from blitzortung.convert import value_to_string |
18 | 18 |
|
19 | 19 | logger = logging.getLogger(__name__) |
|
23 | 23 | import geoip2.database |
24 | 24 |
|
25 | 25 |
|
| 26 | + |
26 | 27 | def main(): |
27 | 28 | reader = geoip2.database.Reader('/var/lib/GeoIP/GeoLite2-City.mmdb') |
| 29 | + statsd_client = statsd.StatsClient('localhost', 8125, prefix='org.blitzortung.service') |
28 | 30 |
|
29 | 31 | parser = OptionParser() |
30 | 32 |
|
@@ -111,12 +113,32 @@ def main(): |
111 | 113 | data_area if data_area is not None else '-', |
112 | 114 | ]) |
113 | 115 |
|
114 | | - with open(os.path.join(base_dir, "servicelog_" + global_timestamp.strftime("%Y-%m-%d")), 'a+') as output_file: |
| 116 | + tags = { |
| 117 | + "version": version if version is not None else '-', |
| 118 | + "region": region, |
| 119 | + "minutes": minute_length, |
| 120 | + "offset": minute_offset, |
| 121 | + "grid": grid_baselength |
| 122 | + } |
| 123 | + if local_x and local_y and data_area: |
| 124 | + tags["data_area"] = f"{local_x}x{local_y}-{data_area}" |
| 125 | + if country_code: |
| 126 | + tags["country"] = country_code |
| 127 | + #if city: |
| 128 | + # tags["city"] = city |
| 129 | + |
| 130 | + tag_values = ",".join([f"{key}={value}" for key, value in tags.items()]) |
| 131 | + |
| 132 | + statsd_client.incr(f'access,{tag_values}') |
| 133 | + |
| 134 | + with open(os.path.join(base_dir, "servicelog_" + global_timestamp.strftime("%Y-%m-%d")), |
| 135 | + 'a+') as output_file: |
115 | 136 | for result in results: |
116 | 137 | line = "\t".join([value_to_string(value) for value in result]) |
117 | 138 | output_file.write(line + "\n") |
118 | 139 |
|
119 | 140 | os.unlink(json_file_name) |
120 | 141 |
|
| 142 | + |
121 | 143 | if __name__ == "__main__": |
122 | 144 | main() |
0 commit comments