Skip to content

Commit 4f17c53

Browse files
Merge pull request #73 from tofu-rocketry/various-fixes
Various fixes
2 parents d15c734 + c75aadb commit 4f17c53

File tree

8 files changed

+107
-106
lines changed

8 files changed

+107
-106
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# monitoring
2-
Monitoring system for APEL servers
1+
# APEL Data Validation System
2+
Monitoring system for APEL servers. Built using Django and Django REST framework.

monitoring/benchmarks/templates/benchmarks_by_submithost.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</head>
1212

1313
<body>
14-
<h2>Sites publishing benchmark records in last 3 months</h2>
14+
<h2>Sites publishing benchmark records in the last two months</h2>
1515
<p>Page last updated: {{ last_fetched|date:"Y-m-d H:i O" }}</p>
1616
<table>
1717
<tr>

monitoring/benchmarks/views.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class BenchmarksViewSet(viewsets.ReadOnlyModelViewSet):
2222

2323
def list(self, request):
2424
last_fetched = BenchmarksBySubmithost.objects.aggregate(Max('fetched'))['fetched__max']
25-
if last_fetched is not None:
26-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
2725

2826
response = super(BenchmarksViewSet, self).list(request)
2927

monitoring/db_update_sqlite.py

Lines changed: 87 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def refresh_gridsite():
156156
Site,
157157
max(LatestEndTime) AS LatestPublish
158158
FROM VSuperSummaries
159-
WHERE LatestEndTime > DATE_SUB(NOW(), INTERVAL 1 YEAR)
159+
WHERE LatestEndTime >= NOW() - INTERVAL 1 YEAR
160160
GROUP BY 1;
161161
"""
162162
fetchset = VSuperSummaries.objects.using('grid').raw(sql_query)
@@ -176,31 +176,30 @@ def refresh_gridsite():
176176
def refresh_cloudsite():
177177
try:
178178
sql_query = """
179-
SELECT
180-
b.SiteName,
181-
COUNT(DISTINCT VMUUID) as VMs,
182-
CloudType,
183-
b.UpdateTime
184-
FROM(
179+
WITH ranked AS (
185180
SELECT
186181
SiteName,
187-
MAX(UpdateTime) AS latest
182+
CloudType,
183+
UpdateTime,
184+
ROW_NUMBER() OVER (
185+
PARTITION BY SiteName
186+
ORDER BY UpdateTime DESC
187+
) AS rn
188188
FROM VAnonCloudRecords
189-
WHERE UpdateTime > DATE_SUB(NOW(), INTERVAL 1 YEAR)
190-
GROUP BY SiteName
189+
WHERE UpdateTime >= NOW() - INTERVAL 6 MONTH
191190
)
192-
AS a
193-
INNER JOIN VAnonCloudRecords
194-
AS b
195-
ON b.SiteName = a.SiteName AND b.UpdateTime = a.latest
196-
GROUP BY SiteName;
191+
SELECT
192+
SiteName,
193+
CloudType,
194+
UpdateTime
195+
FROM ranked
196+
WHERE rn = 1;
197197
"""
198198
fetchset = VAnonCloudRecord.objects.using('cloud').raw(sql_query)
199199

200200
for f in fetchset:
201201
CloudSite.objects.update_or_create(
202202
defaults={
203-
'Vms': f.VMs,
204203
'Script': f.CloudType,
205204
'updated': f.UpdateTime
206205
},
@@ -305,53 +304,82 @@ def refresh_BenchmarksBySubmitHost_from_view(view_name):
305304
try:
306305
if view_name == 'VSummaries':
307306
sql_query = f"""
308-
SELECT DISTINCT v.Site, v.SubmitHost, v.ServiceLevelType, v.ServiceLevel, v.UpdateTime AS LatestPublish
309-
FROM {view_name} AS v
310-
JOIN (
311-
SELECT Site, SubmitHost, MAX(UpdateTime) AS LatestPublish
312-
FROM {view_name}
313-
WHERE UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
314-
GROUP BY Site, SubmitHost, ServiceLevelType, ServiceLevel
315-
) AS latest
316-
ON v.Site = latest.Site
317-
AND v.SubmitHost = latest.SubmitHost
318-
AND v.UpdateTime = latest.LatestPublish
319-
WHERE v.UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH);
320-
"""
307+
WITH latest AS (
308+
SELECT
309+
Site,
310+
SubmitHost,
311+
ServiceLevelType,
312+
ServiceLevel,
313+
UpdateTime,
314+
ROW_NUMBER() OVER (
315+
PARTITION BY Site, SubmitHost
316+
ORDER BY Year DESC, Month DESC, UpdateTime DESC
317+
) AS rn
318+
FROM VSummaries
319+
WHERE UpdateTime >= NOW() - INTERVAL 2 MONTH
320+
)
321+
SELECT
322+
Site,
323+
SubmitHost,
324+
ServiceLevelType,
325+
ServiceLevel,
326+
UpdateTime AS LatestPublish
327+
FROM latest
328+
WHERE rn = 1;
329+
"""
321330
elif view_name == 'VJobRecords':
322331
sql_query = f"""
323-
SELECT DISTINCT v.Site, v.SubmitHost, v.ServiceLevelType, v.ServiceLevel, v.UpdateTime AS LatestPublish
324-
FROM {view_name} AS v
325-
JOIN (
326-
SELECT Site, SubmitHost, MAX(UpdateTime) AS LatestPublish
327-
FROM {view_name}
328-
WHERE EndTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
329-
AND UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
330-
GROUP BY Site, SubmitHost, ServiceLevelType, ServiceLevel
331-
) AS latest
332-
ON v.Site = latest.Site
333-
AND v.SubmitHost = latest.SubmitHost
334-
AND v.UpdateTime = latest.LatestPublish
335-
WHERE v.EndTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
336-
AND v.UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH);
337-
"""
332+
WITH latest AS (
333+
SELECT
334+
Site,
335+
SubmitHost,
336+
ServiceLevelType,
337+
ServiceLevel,
338+
UpdateTime,
339+
ROW_NUMBER() OVER (
340+
PARTITION BY Site, SubmitHost
341+
ORDER BY EndTime DESC, UpdateTime DESC
342+
) AS rn
343+
FROM VJobRecords
344+
WHERE EndTime >= NOW() - INTERVAL 2 MONTH
345+
AND UpdateTime >= NOW() - INTERVAL 2 MONTH
346+
)
347+
SELECT
348+
Site,
349+
SubmitHost,
350+
ServiceLevelType,
351+
ServiceLevel,
352+
UpdateTime AS LatestPublish
353+
FROM latest
354+
WHERE rn = 1;
355+
"""
338356
elif view_name == 'VNormalisedSummaries':
339357
sql_query = f"""
340-
SELECT DISTINCT v.Site, v.SubmitHost, v.ServiceLevelType, ROUND(v.NormalisedWallDuration / v.WallDuration, 3) AS ServiceLevel, v.UpdateTime AS LatestPublish
341-
FROM {view_name} AS v
342-
JOIN (
343-
SELECT Site, SubmitHost, MAX(UpdateTime) AS LatestPublish, ROUND(NormalisedWallDuration / WallDuration, 3) AS ServiceLevel
344-
FROM {view_name}
345-
WHERE UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
346-
AND WallDuration > 0
347-
GROUP BY Site, SubmitHost, ServiceLevelType, ServiceLevel
348-
) AS latest
349-
ON v.Site = latest.Site
350-
AND v.SubmitHost = latest.SubmitHost
351-
AND v.UpdateTime = latest.LatestPublish
352-
WHERE v.UpdateTime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
353-
AND v.WallDuration > 0;
354-
"""
358+
WITH latest AS (
359+
SELECT
360+
Site,
361+
SubmitHost,
362+
ServiceLevelType,
363+
NormalisedWallDuration,
364+
WallDuration,
365+
UpdateTime,
366+
ROW_NUMBER() OVER (
367+
PARTITION BY Site, SubmitHost
368+
ORDER BY Year DESC, Month DESC, UpdateTime DESC
369+
) AS rn
370+
FROM VNormalisedSummaries
371+
WHERE UpdateTime >= NOW() - INTERVAL 2 MONTH
372+
AND WallDuration > 0
373+
)
374+
SELECT
375+
Site,
376+
SubmitHost,
377+
ServiceLevelType,
378+
ROUND(NormalisedWallDuration / WallDuration, 3) AS ServiceLevel,
379+
UpdateTime AS LatestPublish
380+
FROM latest
381+
WHERE rn = 1;
382+
"""
355383
else:
356384
log.warning(f"Unknown view name: {view_name}")
357385
return

monitoring/iris/templates/iris_cloud_and_grid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</head>
1212

1313
<body>
14-
<h2>Sites publishing cloud and grid accounting records to IRIS Accounting in the last year</h2>
14+
<h2>Sites publishing cloud and grid accounting records to IRIS Accounting in the last six months</h2>
1515
<p>Page last updated: {{ last_fetched|date:"Y-m-d H:i O" }}</p>
1616

1717
<br/>

monitoring/iris_db_update_sqlite.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def refresh_iris_cloud_and_grid():
6565
Site,
6666
max(LatestEndTime) AS LatestPublish
6767
FROM VSuperSummaries
68-
WHERE LatestEndTime > DATE_SUB(NOW(), INTERVAL 1 YEAR)
68+
WHERE LatestEndTime >= NOW() - INTERVAL 6 MONTH
6969
AND (Site LIKE 'UK%%' OR Site LIKE 'RAL-LCG2')
7070
GROUP BY 1;
7171
"""
@@ -81,20 +81,10 @@ def refresh_iris_cloud_and_grid():
8181

8282
sql_query = """
8383
SELECT
84-
b.SiteName,
85-
b.UpdateTime AS LatestPublish
86-
FROM(
87-
SELECT
88-
SiteName,
89-
MAX(UpdateTime) AS latest
90-
FROM VAnonCloudRecords
91-
WHERE UpdateTime > DATE_SUB(NOW(), INTERVAL 1 YEAR)
92-
GROUP BY SiteName
93-
)
94-
AS a
95-
INNER JOIN VAnonCloudRecords
96-
AS b
97-
ON b.SiteName = a.SiteName AND b.UpdateTime = a.latest
84+
SiteName,
85+
MAX(UpdateTime) AS LatestPublish
86+
FROM VAnonCloudRecords
87+
WHERE UpdateTime >= NOW() - INTERVAL 6 MONTH
9888
GROUP BY SiteName;
9989
"""
10090
fetchset = VAnonCloudRecords.objects.using('iris_cloud').raw(sql_query)

monitoring/publishing/templates/cloudsites.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@
1010
</head>
1111

1212
<body>
13-
<h2>Sites publishing cloud accounting records in the last year</h2>
13+
<h2>Sites publishing cloud accounting records in the last six months</h2>
1414
<p>Data last fetched: {{ last_fetched|date:"Y-m-d H:i O" }}</p>
1515
<table>
1616
<tr>
1717
<th class='tableheader'>Site</th>
18-
<th class='tableheader'>VMsInLastUpdate</th>
1918
<th class='tableheader'>CloudType</th>
2019
<th class='tableheader'>LastUpdated</th>
2120
<th class='tableheader'>Publication Status</th>
2221
</tr>
2322
{% for site in sites %}
2423
<tr onmouseover="this.className='highlight-row'" onmouseout="this.className='tabletext'" class="tabletext">
2524
<td>{{ site.SiteName }}</td>
26-
<td>{{ site.Vms }}</td>
2725
<td>{{ site.Script }}</td>
2826
<td>{{ site.updated|date:"Y-m-d H:i:s" }}</td>
2927
<td>{{ site.stdout }}</td>

monitoring/publishing/views.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
GridSiteSyncSubmitHSerializer
2727
)
2828

29-
def update_dict_stdout_and_returncode(single_dict, date, days=7):
29+
def update_dict_stdout_and_returncode(single_dict, date, warn_days=7, crit_days=31):
3030
today = datetime.today()
3131

32-
# Handle future dates
33-
if date > today:
32+
# Handle null values
33+
if date is None:
3434
single_dict.update({
3535
'returncode': 3,
3636
'stdout': "UNKNOWN"
@@ -40,12 +40,15 @@ def update_dict_stdout_and_returncode(single_dict, date, days=7):
4040
diff_days = (today - date).days
4141
formatted_date = date.strftime("%Y-%m-%d")
4242

43-
if diff_days <= days:
44-
status = "OK"
45-
returncode = 0
46-
else:
43+
if diff_days > crit_days:
44+
status = "CRITICAL"
45+
returncode = 2
46+
elif diff_days > warn_days:
4747
status = "WARNING"
4848
returncode = 1
49+
else:
50+
status = "OK"
51+
returncode = 0
4952

5053
single_dict.update({
5154
'returncode': returncode,
@@ -63,8 +66,6 @@ class GridSiteViewSet(viewsets.ReadOnlyModelViewSet):
6366

6467
def list(self, request):
6568
last_fetched = GridSite.objects.aggregate(Max('fetched'))['fetched__max']
66-
if last_fetched is not None:
67-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
6869

6970
final_response = []
7071
response = super(GridSiteViewSet, self).list(request)
@@ -85,8 +86,6 @@ def list(self, request):
8586
def retrieve(self, request, SiteName=None):
8687
last_fetched = GridSite.objects.aggregate(Max('fetched'))['fetched__max']
8788
# If there's no data then last_fetched is None.
88-
if last_fetched is not None:
89-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
9089

9190
response = super(GridSiteViewSet, self).retrieve(request)
9291
date = response.data['updated'].replace(tzinfo=None)
@@ -124,9 +123,6 @@ def get_template_names(self):
124123
def list(self, request):
125124
last_fetched = GridSiteSync.objects.aggregate(Max('fetched'))['fetched__max']
126125

127-
if last_fetched is not None:
128-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
129-
130126
response = super(GridSiteSyncViewSet, self).list(request)
131127
response.data = {
132128
'records': response.data,
@@ -137,9 +133,6 @@ def list(self, request):
137133
def retrieve(self, request, SiteName=None):
138134
last_fetched = GridSiteSync.objects.aggregate(Max('fetched'))['fetched__max']
139135

140-
if last_fetched is not None:
141-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
142-
143136
sites_list_qs = GridSiteSync.objects.filter(SiteName=SiteName)
144137
sites_list_serializer = self.get_serializer(sites_list_qs, many=True)
145138

@@ -186,9 +179,6 @@ def list(self, request):
186179
def retrieve(self, request, SiteName=None, YearMonth=None):
187180
last_fetched = GridSiteSyncSubmitH.objects.aggregate(Max('fetched'))['fetched__max']
188181

189-
if last_fetched is not None:
190-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
191-
192182
site_and_year_queryset = GridSiteSyncSubmitH.objects.filter(
193183
SiteName=SiteName,
194184
YearMonth=YearMonth
@@ -212,8 +202,6 @@ class CloudSiteViewSet(viewsets.ReadOnlyModelViewSet):
212202

213203
def list(self, request):
214204
last_fetched = CloudSite.objects.aggregate(Max('fetched'))['fetched__max']
215-
if last_fetched is not None:
216-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
217205

218206
final_response = []
219207
response = super(CloudSiteViewSet, self).list(request)
@@ -233,7 +221,6 @@ def list(self, request):
233221

234222
def retrieve(self, request, SiteName=None):
235223
last_fetched = CloudSite.objects.aggregate(Max('fetched'))['fetched__max']
236-
print(last_fetched.replace(tzinfo=None), datetime.today() - timedelta(hours=1, seconds=20))
237224

238225
response = super(CloudSiteViewSet, self).retrieve(request)
239226
# Wrap data in a dict so that it can display in template.

0 commit comments

Comments
 (0)