Debian Codegraph @

templates/mirrorstats.html

raw
1 {{define "title"}}Mirrorstats{{end}}
2 {{define "headline"}}Mirrorstats{{end}}
3
4 {{define "head"}}
5 {{if not .LocalJSPath}}
6 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
7 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.4.1/MarkerCluster.css" />
8 <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
9 <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.4.1/leaflet.markercluster.js"></script>
10 {{else}}
11 <link rel="stylesheet" href="{{.LocalJSPath}}/leaflet/1.3.4/leaflet.css" />
12 <link rel="stylesheet" href="{{.LocalJSPath}}/leaflet.markercluster/1.4.1/MarkerCluster.css" />
13 <script src="{{.LocalJSPath}}/leaflet/1.3.4/leaflet.js"></script>
14 <script src="{{.LocalJSPath}}/leaflet.markercluster/1.4.1/leaflet.markercluster.js"></script>
15 {{end}}
16 <style type="text/css">
17 #map { }
18 .marker-cluster {
19 border-radius: 50%;
20 opacity: 0.6;
21 }
22 .marker-good {
23 background-color: green;
24 }
25 .marker-bad {
26 background-color: red;
27 }
28 .marker-mixed {
29 background-color: orange;
30 }
31 .marker-disabled {
32 background-color: black;
33 }
34 .popup-content {
35 font-size: 0.8em;
36 }
37 .tooltip {
38 position: relative;
39 display: inline-block;
40 opacity: 0.8;
41 }
42 .tooltip .tooltiptext {
43 visibility: hidden;
44 width: 120px;
45 background-color: black;
46 color: #fff;
47 text-align: center;
48 border-radius: 6px;
49 padding: 5px 0;
50 position: absolute;
51 z-index: 1;
52 top: -16px;
53 left: 110%;
54 }
55 .tooltip .tooltiptext::after {
56 content: "";
57 position: absolute;
58 top: 50%;
59 right: 100%;
60 margin-top: -5px;
61 border-width: 5px;
62 border-style: solid;
63 border-color: transparent black transparent transparent;
64 }
65 .tooltip:hover .tooltiptext {
66 visibility: visible;
67 }
68 .bar-download {
69 background-color: #4078C0;
70 height: 15px;
71 }
72 .bar-bytes {
73 background-color: #7CA2D3;
74 height: 15px;
75 }
76 </style>
77 {{end}}
78
79 {{define "body"}}
80 <div id="map" style="width: 100%; height: 512px;"></div>
81
82 <div id="chart">
83 <table class="alt">
84 <tr>
85 <th>Mirror</th>
86 <th>Since 00:00 UTC…</th>
87 <th>Last update</th>
88 {{if .HasTZAdjustement}}<th>Adjusted TZ</th>{{end}}
89 </tr>
90 {{range $i, $v := .List}}
91 <tr>
92 <td rowspan="2">{{$v.Name}}</td>
93 <td width="500" class="tooltip"><div class="bar-download" style="width: {{$v.PercentD}}%;"><span class="tooltiptext">{{$v.Downloads}}<br>downloads</span></div></td>
94 <td rowspan="2"><span style="color:{{if $v.SyncOffset.Valid}}{{if gt $v.SyncOffset.Value 720}}red{{else if gt $v.SyncOffset.Value 48}}orange{{else}}green{{end}}{{else}}black{{end}}">{{if $v.SyncOffset.Valid}}{{$v.SyncOffset.HumanReadable}}{{else}}unknown{{end}}</span></td>
95 {{if $.HasTZAdjustement}}<td rowspan="2">{{if ne $v.TZOffset 0}}{{$v.TZOffset}}{{end}}</td>{{end}}
96 </tr>
97 <tr>
98 <td width="500" class="tooltip"><div class="bar-bytes" style="width: {{$v.PercentB}}%;"><span class="tooltiptext">{{sizeof $v.Bytes}}<br>transferred</span></div></td>
99 </tr>
100 {{end}}
101 </table>
102 </div>
103
104 <script>
105 var map = L.map('map').setView([20,37], 2);
106 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
107 attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
108 }).addTo(map);
109
110
111 var mirrors = {
112 "rows" : [
113 {{range $i, $v := .MirrorList}}
114 {
115 "lat" : {{$v.Latitude}},
116 "lon" : {{$v.Longitude}},
117 "id" : "{{$v.Name}}",
118 "enabled": {{$v.Enabled}},
119 "URL" : "{{$v.HttpURL}}",
120 "httpUp" : {{$v.HttpUp}},
121 "httpsUp" : {{$v.HttpsUp}},
122 },
123 {{end}}
124 ]
125 };
126
127 MirrorMarker = L.Marker.extend({
128 options: {
129 enabled: false,
130 state: '',
131 mid: ''
132 }
133 });
134
135 function generateStatusRow(marker) {
136 var color = "red";
137 if (marker.options.enabled == false) {
138 color = "black";
139 } else if (marker.options.state == "up") {
140 color = "green";
141 } else if (marker.options.state == "degraded") {
142 color = "orange";
143 }
144 return '<tr><td style="background-color: ' + color + '"> &nbsp; </td><td>' + marker.options.mid + '</td></tr>';
145 }
146
147 var markers = new L.MarkerClusterGroup({
148 showCoverageOnHover: false,
149 zoomToBoundsOnClick: false,
150 spiderfyOnMaxZoom: false,
151 animateAddingMarkers: true,
152 iconCreateFunction: function (cluster) {
153 var radius = 6;
154 var childCount = cluster.getChildCount();
155 var area = (Math.PI * (radius * radius)) * childCount;
156 var size = Math.sqrt(area / Math.PI) * 2;
157
158 var hasUp = false;
159 var hasDown = false;
160 var hasDisabled = false;
161 for (var i = 0; i < cluster.getAllChildMarkers().length; i++) {
162 if (cluster.getAllChildMarkers()[i].options.enabled == false) {
163 hasDisabled = true;
164 continue
165 }
166 if (cluster.getAllChildMarkers()[i].options.state == "up") {
167 hasUp = true;
168 } else {
169 hasDown = true;
170 }
171 }
172
173 var cssClass;
174 if (!hasUp && !hasDown && hasDisabled) {
175 cssClass = "marker-disabled";
176 } else if (hasUp && !hasDown) {
177 cssClass = "marker-good";
178 } else if (!hasUp && hasDown) {
179 cssClass = "marker-bad";
180 } else {
181 cssClass = "marker-mixed";
182 }
183
184 return new L.divIcon({ html: '<div style="width:'+size+'px;height:'+size+'px;"></div>', className: 'marker-cluster ' + cssClass, iconSize: new L.Point(size, size) });
185 }
186 });
187
188 var radius = 6;
189 var mm = [];
190 for (i in mirrors.rows) {
191 var area = (Math.PI * (radius * radius));
192 var size = Math.sqrt(area / Math.PI) * 2;
193 var enabled = mirrors.rows[i].enabled;
194 var state = "down";
195
196 if (enabled) {
197 if (mirrors.rows[i].httpUp == mirrors.rows[i].httpsUp) {
198 state = mirrors.rows[i].httpUp ? "up" : "down";
199 } else if (mirrors.rows[i].URL.startsWith("http://")) {
200 state = mirrors.rows[i].httpUp ? "up" : "down";
201 } else if (mirrors.rows[i].URL.startsWith("https://")) {
202 state = mirrors.rows[i].httpsUp ? "up" : "down";
203 } else {
204 state = "degraded";
205 }
206 }
207
208 var cssClass;
209 if (!enabled) {
210 cssClass = "marker-disabled";
211 } else if (state == "up") {
212 cssClass = "marker-good";
213 } else if (state == "degraded") {
214 cssClass = "marker-mixed";
215 } else {
216 cssClass = "marker-bad";
217 }
218
219 var icon = new L.divIcon({ html: '<div style="width:'+size+'px;height:'+size+'px;"></div>', className: 'marker-cluster ' + cssClass, iconSize: new L.Point(size, size) });
220
221 var m = new MirrorMarker([mirrors.rows[i].lat, mirrors.rows[i].lon], {
222 icon: icon,
223 state: state,
224 enabled: enabled,
225 mid: mirrors.rows[i].id
226 });
227
228 mm.push(m);
229 }
230
231 markers.addLayers(mm);
232
233 markers.on('click', function(a) {
234 a.layer.bindPopup("<table class='popup-content'>" + generateStatusRow(a.layer) + "</table>").openPopup();
235 });
236
237 markers.on('clusterclick', function(a) {
238 var content = "";
239 for (var i = 0; i < a.layer.getAllChildMarkers().length; i++) {
240 content += generateStatusRow(a.layer.getAllChildMarkers()[i]);
241 }
242 a.layer.bindPopup("<table class='popup-content'>" + content + "</table>").openPopup();
243 });
244
245 map.addLayer(markers);
246 </script>
247 {{end}}