1 |
commit: 92ea4ca1710dd5eefbda4f97687ea76e34812d50 |
2 |
Author: Max Magorsch <arzano <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Apr 27 18:08:22 2020 +0000 |
4 |
Commit: Max Magorsch <arzano <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 27 18:08:22 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=92ea4ca1 |
7 |
|
8 |
Generate a json file containing the mirmon data |
9 |
|
10 |
The new generate-json.py script will parse the data |
11 |
generated by mirmon which is present in the state |
12 |
file and convert it to json. A json file called |
13 |
'state.json' will be created so that the mirmon |
14 |
data can be properly parsed. |
15 |
|
16 |
Signed-off-by: Max Magorsch <arzano <AT> gentoo.org> |
17 |
|
18 |
json/generate-json.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ |
19 |
mirmon-distfiles.sh | 4 +++- |
20 |
mirmon-rsync.sh | 4 +++- |
21 |
3 files changed, 53 insertions(+), 2 deletions(-) |
22 |
|
23 |
diff --git a/json/generate-json.py b/json/generate-json.py |
24 |
new file mode 100755 |
25 |
index 0000000..1786bf9 |
26 |
--- /dev/null |
27 |
+++ b/json/generate-json.py |
28 |
@@ -0,0 +1,47 @@ |
29 |
+#!/usr/bin/python |
30 |
+ |
31 |
+# |
32 |
+# Convert a mirmon.state file to json |
33 |
+# |
34 |
+# This script will parse a mirmon state file, convert the content |
35 |
+# to json and print the json to stdout. |
36 |
+# |
37 |
+# Usage: |
38 |
+# $ generate-json.py path_to_mirmon_state_file |
39 |
+# |
40 |
+# The json will be printed to stdout. In case of an error, the |
41 |
+# exception will be printed to stderr. |
42 |
+# |
43 |
+ |
44 |
+import json |
45 |
+import sys |
46 |
+ |
47 |
+try: |
48 |
+ with open(str(sys.argv[1])) as file_in: |
49 |
+ mirrors = {} |
50 |
+ for raw_line in file_in: |
51 |
+ |
52 |
+ line = raw_line.split(" ") |
53 |
+ protocol = line[0].split("://")[0] |
54 |
+ url = line[0].split("://")[1] |
55 |
+ |
56 |
+ state = { |
57 |
+ "Protocol" : protocol, |
58 |
+ "Url" : url, |
59 |
+ "Age" : line[1], |
60 |
+ "StatusLastProbe" : line[2], |
61 |
+ "TimeLastSuccessfulProbe" : line[3], |
62 |
+ "ProbeHistory" : line[4], |
63 |
+ "StateHistory" : line[5], |
64 |
+ "LastProbe" : line[6].strip(), |
65 |
+ } |
66 |
+ |
67 |
+ if url not in mirrors: |
68 |
+ mirrors[url] = [] |
69 |
+ |
70 |
+ mirrors[url].append(state) |
71 |
+ |
72 |
+ print(json.dumps(mirrors)) |
73 |
+ |
74 |
+except Exception as e: |
75 |
+ print("Could not convert mirmon state file to json: " + str(e), file=sys.stderr) |
76 |
|
77 |
diff --git a/mirmon-distfiles.sh b/mirmon-distfiles.sh |
78 |
index f8012cc..3e14e87 100755 |
79 |
--- a/mirmon-distfiles.sh |
80 |
+++ b/mirmon-distfiles.sh |
81 |
@@ -13,4 +13,6 @@ cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors |
82 |
sed \ |
83 |
-e 's#mirrors</H2>#<a href="http://www.gentoo.org/main/en/mirrors2.xml">mirrors</a></H2>#' \ |
84 |
>../../htdocs/distfiles/index.html <../../htdocs/distfiles/index-wip.html |
85 |
- |
86 |
+# Generate a json file containing the state of each mirror |
87 |
+../json/generate-json.py /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/distfiles_mirrors/var/mirmon.state \ |
88 |
+ > ../../htdocs/distfiles/state.json |
89 |
|
90 |
diff --git a/mirmon-rsync.sh b/mirmon-rsync.sh |
91 |
index 5df1c73..900832d 100755 |
92 |
--- a/mirmon-rsync.sh |
93 |
+++ b/mirmon-rsync.sh |
94 |
@@ -28,4 +28,6 @@ echo "gentoo rsync://35.190.132.250" >> ./var/g.mirrors |
95 |
sed \ |
96 |
-e 's#mirrors</H2>#<a href="http://www.gentoo.org/main/en/mirrors-rsync.xml">mirrors</a></H2>#' \ |
97 |
>../../htdocs/rsync/index.html <../../htdocs/rsync/index-wip.html |
98 |
- |
99 |
+# Generate a json file containing the state of each mirror |
100 |
+../json/generate-json.py /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/rsync_mirrors/var/mirmon.state \ |
101 |
+ > ../../htdocs/rsync/state.json |