Skip to content

Commit 03f8758

Browse files
Merge pull request #15 from Letizia97/django_experiments_3
GT-96 Django monitoring app
2 parents f90e503 + 40a7c6d commit 03f8758

15 files changed

+854
-60
lines changed

monitoring/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import pymysql
2+
pymysql.install_as_MySQLdb()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html>{{ message }}</html>

monitoring/availability/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.conf.urls import url
22

3-
import views
3+
from monitoring.availability import views
44

55
urlpatterns = [
66
url(r'^$', views.status),

monitoring/availability/views.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4-
import time
5-
64
from rest_framework.decorators import api_view
75
from rest_framework.response import Response
86

97

108
@api_view()
119
def status(requst):
12-
if int(time.time()) % 2:
13-
return Response("Everything OK")
14-
else:
15-
return Response("Everything NOT ok.")
10+
return Response({"message": "OK"}, status=200, template_name="status.html")

monitoring/publishing/models.py

+54-5
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,60 @@
66

77
class GridSite(models.Model):
88
fetched = models.DateTimeField(auto_now=True)
9-
name = models.CharField(max_length=255, primary_key=True)
9+
SiteName = models.CharField(max_length=255, primary_key=True)
1010
updated = models.DateTimeField()
1111

1212

1313
class VSuperSummaries(models.Model):
1414
Site = models.CharField(max_length=255, primary_key=True)
1515
LatestPublish = models.DateTimeField()
16+
Month = models.IntegerField()
17+
Year = models.IntegerField()
18+
RecordStart = models.DateTimeField()
19+
RecordEnd = models.DateTimeField()
20+
RecordCountPublished = models.IntegerField()
1621

1722
class Meta:
1823
managed = False
1924
db_table = 'VSuperSummaries'
2025

2126

27+
class GridSiteSync(models.Model):
28+
fetched = models.DateTimeField(auto_now=True)
29+
SiteName = models.CharField(max_length=255)
30+
YearMonth = models.CharField(max_length=255)
31+
Year = models.IntegerField()
32+
Month = models.IntegerField()
33+
RecordStart = models.DateTimeField()
34+
RecordEnd = models.DateTimeField()
35+
RecordCountPublished = models.IntegerField()
36+
RecordCountInDb = models.IntegerField()
37+
SyncStatus = models.CharField(max_length=255)
38+
39+
class Meta:
40+
# Descending order of Year and Month to display latest data first
41+
ordering = ('SiteName', '-Year', '-Month')
42+
unique_together = ('SiteName', 'YearMonth')
43+
44+
45+
class VSyncRecords(models.Model):
46+
Site = models.CharField(max_length=255, primary_key=True)
47+
RecordCountInDb = models.IntegerField()
48+
49+
class Meta:
50+
managed = False
51+
db_table = 'VSyncRecords'
52+
53+
2254
class CloudSite(models.Model):
2355
fetched = models.DateTimeField(auto_now=True)
24-
name = models.CharField(max_length=255, primary_key=True)
25-
vms = models.IntegerField(default=0)
26-
script = models.CharField(max_length=255)
56+
SiteName = models.CharField(max_length=255, primary_key=True)
57+
Vms = models.IntegerField(default=0)
58+
Script = models.CharField(max_length=255)
2759
updated = models.DateTimeField()
2860

2961
class Meta:
30-
ordering = ('name',)
62+
ordering = ('SiteName',)
3163

3264

3365
class VAnonCloudRecord(models.Model):
@@ -46,3 +78,20 @@ def __str__(self):
4678
self.CloudType,
4779
self.UpdateTime,
4880
self.VMs)
81+
82+
83+
class GridSiteSyncSubmitH(models.Model):
84+
fetched = models.DateTimeField(auto_now=True)
85+
SiteName = models.CharField(max_length=255)
86+
YearMonth = models.CharField(max_length=255)
87+
Year = models.IntegerField()
88+
Month = models.IntegerField()
89+
RecordStart = models.DateTimeField()
90+
RecordEnd = models.DateTimeField()
91+
RecordCountPublished = models.IntegerField()
92+
RecordCountInDb = models.IntegerField()
93+
SubmitHost = models.CharField(max_length=255)
94+
95+
class Meta:
96+
ordering = ('SiteName', '-Year', '-Month')
97+
unique_together = ('SiteName', 'YearMonth', 'SubmitHost')

monitoring/publishing/serializers.py

+64-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from rest_framework import serializers
22

3-
from models import CloudSite, GridSite
3+
from monitoring.publishing.models import (
4+
CloudSite,
5+
GridSite,
6+
GridSiteSync,
7+
GridSiteSyncSubmitH
8+
)
49

510

611
class GridSiteSerializer(serializers.HyperlinkedModelSerializer):
@@ -11,7 +16,36 @@ class GridSiteSerializer(serializers.HyperlinkedModelSerializer):
1116

1217
class Meta:
1318
model = GridSite
14-
fields = ('url', 'name', 'updated')
19+
fields = (
20+
'url',
21+
'SiteName',
22+
'updated'
23+
)
24+
25+
26+
class GridSiteSyncSerializer(serializers.HyperlinkedModelSerializer):
27+
# Override default format with None so that Python datetime is used as
28+
# ouput format. Encoding will be determined by the renderer and can be
29+
# formatted by a template filter.
30+
31+
class Meta:
32+
model = GridSiteSync
33+
fields = (
34+
'url',
35+
'SiteName',
36+
'YearMonth',
37+
'RecordStart',
38+
'RecordEnd',
39+
'RecordCountPublished',
40+
'RecordCountInDb',
41+
'SyncStatus'
42+
)
43+
44+
# Sitename substitutes pk
45+
lookup_field = 'SiteName'
46+
extra_kwargs = {
47+
'url': {'lookup_field': 'SiteName'}
48+
}
1549

1650

1751
class CloudSiteSerializer(serializers.HyperlinkedModelSerializer):
@@ -22,4 +56,31 @@ class CloudSiteSerializer(serializers.HyperlinkedModelSerializer):
2256

2357
class Meta:
2458
model = CloudSite
25-
fields = ('url', 'name', 'vms', 'script', 'updated')
59+
fields = (
60+
'url',
61+
'SiteName',
62+
'Vms',
63+
'Script',
64+
'updated'
65+
)
66+
67+
68+
class GridSiteSyncSubmitHSerializer(serializers.HyperlinkedModelSerializer):
69+
# Override default format with None so that Python datetime is used as
70+
# ouput format. Encoding will be determined by the renderer and can be
71+
# formatted by a template filter.
72+
73+
class Meta:
74+
model = GridSiteSyncSubmitH
75+
fields = (
76+
'url',
77+
'SiteName',
78+
'YearMonth',
79+
'RecordStart',
80+
'RecordEnd',
81+
'RecordCountPublished',
82+
'RecordCountInDb',
83+
'SubmitHost'
84+
)
85+
86+
lookup_fields = ('SiteName', 'YearMonth')

monitoring/publishing/templates/cloudsites.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ <h2>Sites publishing cloud accounting records from 2018-06-19 onwards</h2>
1616
</tr>
1717
{% for site in sites %}
1818
<tr>
19-
<td>{{ site.name }}</td>
20-
<td>{{ site.vms }}</td>
21-
<td>{{ site.script }}</td>
19+
<td>{{ site.SiteName }}</td>
20+
<td>{{ site.Vms }}</td>
21+
<td>{{ site.Script }}</td>
2222
<td>{{ site.updated|date:"Y-m-d H:i:s" }}</td>
2323
</tr>
2424
{% endfor %}

monitoring/publishing/templates/gridsites.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ <h3>APEL Publication Test</h3>
1717
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>
1818

1919
<table>
20-
<tr><th colspan='5' class='tableheader'>{{ sites.0.name }}</td></tr>
20+
<tr><th colspan='5' class='tableheader'>{{ sites.0.SiteName }}</td></tr>
2121
<tr>
2222
<th class='tableheader'>ExecutingSite</th>
2323
<th class='tableheader'>MeasurementDate</th>
2424
<th class='tableheader'>MeasurementTime</th>
2525
<th class='tableheader'>Publication <br> Status</th>
2626
</tr>
2727
<tr>
28-
<td align='middle' class='tabletext'>{{ sites.0.name }}</td>
28+
<td align='middle' class='tabletext'>{{ sites.0.SiteName }}</td>
2929
<td align='middle' class='tabletext'>{{ last_fetched|date:"Y-m-d" }}</td>
3030
<td align='middle' class='tabletext'>{{ last_fetched|date:"G:i:s" }}</td>
3131
<td align='middle' class='tabletext'>{{ stdout }}</td>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5+
<title>APEL Publication Summary </title>
6+
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
7+
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
8+
</head>
9+
<body>
10+
<h3>APEL Synchronisation Test</h3>
11+
<ul>
12+
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
13+
<li> Major differences are flagged with FAIL.
14+
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
15+
<li> Contact: apel-admins [at] stfc.ac.uk
16+
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>
17+
18+
<table>
19+
<tr><th colspan='7' class='tableheader'> All sites </td></tr>
20+
<tr>
21+
<th class='tableheader'>Site Name</th>
22+
<th class='tableheader'>Month</th>
23+
<th class='tableheader'>Record Start</th>
24+
<th class='tableheader'>Record End</th>
25+
<th class='tableheader'>Record Count <br/> In Your Database</th>
26+
<th class='tableheader'>Record Count <br/> What You Published</th>
27+
<th class='tableheader'>Synchronisation <br/> Status</th>
28+
</tr>
29+
30+
{% for record in records %}
31+
<tr>
32+
<td><a href="{% url 'gridsync_singlesite' SiteName=record.SiteName %}">{{ record.SiteName }}</td>
33+
<td>{{ record.YearMonth }}</a> </td>
34+
<td>{{ record.RecordStart }}</td>
35+
<td>{{ record.RecordEnd }}</td>
36+
<td>{{ record.RecordCountPublished }}</td>
37+
<td>{{ record.RecordCountInDb }}</td>
38+
<td>{{ record.SyncStatus }}</td>
39+
40+
</tr>
41+
{% endfor %}
42+
43+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5+
<title>APEL Publication Summary </title>
6+
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
7+
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
8+
</head>
9+
<body>
10+
<h3>APEL Synchronisation Test</h3>
11+
<ul>
12+
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
13+
<li> Major differences are flagged with FAIL.
14+
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
15+
<li> Contact: apel-admins [at] stfc.ac.uk
16+
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>
17+
18+
<table>
19+
<tr><th colspan='6' class='tableheader'> {{ records.0.SiteName }} </td></tr>
20+
<tr>
21+
<th class='tableheader'>Month</th>
22+
<th class='tableheader'>Record Start</th>
23+
<th class='tableheader'>Record End</th>
24+
<th class='tableheader'>Record Count <br/> In Your Database</th>
25+
<th class='tableheader'>Record Count <br/> What You Published</th>
26+
<th class='tableheader'>Synchronisation <br/> Status</th>
27+
</tr>
28+
29+
{% for record in records %}
30+
<tr>
31+
<td><a href="{% url 'gridsync_submithost' SiteName=record.SiteName YearMonth=record.YearMonth %}">{{ record.YearMonth }}</a> </td>
32+
<td>{{ record.RecordStart }}</td>
33+
<td>{{ record.RecordEnd }}</td>
34+
<td>{{ record.RecordCountPublished }}</td>
35+
<td>{{ record.RecordCountInDb }}</td>
36+
<td>{{ record.SyncStatus }}</td>
37+
38+
</tr>
39+
{% endfor %}
40+
41+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5+
<title>APEL Publication Summary </title>
6+
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
7+
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
8+
</head>
9+
<body>
10+
<h3>APEL Synchronisation Test</h3>
11+
<ul>
12+
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
13+
<li> Major differences are flagged with FAIL.
14+
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
15+
<li> Contact: apel-admins [at] stfc.ac.uk
16+
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>
17+
18+
<table>
19+
<tr><th colspan='6' class='tableheader'> {{submisthosts.0.SiteName}}, {{submisthosts.0.YearMonth}} </td></tr>
20+
<tr>
21+
<th class='tableheader'>Month</th>
22+
<th class='tableheader'>SubmitHost</th>
23+
<th class='tableheader'>RecordStart</th>
24+
<th class='tableheader'>RecordEnd</th>
25+
<th class='tableheader'>Record Count <br/> In Your Database</th>
26+
<th class='tableheader'>Record Count <br/> What You Published</th>
27+
</tr>
28+
29+
{% for host in submisthosts %}
30+
<tr>
31+
32+
<td>{{ host.YearMonth }} </td>
33+
<td>{{ host.SubmitHost }}</td>
34+
<td>{{ host.RecordStart }}</td>
35+
<td>{{ host.RecordEnd }}</td>
36+
<td>{{ host.RecordCountPublished }}</td>
37+
<td>{{ host.RecordCountInDb }}</td>
38+
39+
40+
</tr>
41+
{% endfor %}
42+
43+
</table>

monitoring/publishing/urls.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
from rest_framework import routers
44

5-
import views
5+
from monitoring.publishing import views
6+
from django.urls import re_path
67

78
router = routers.SimpleRouter()
89
router.register(r'cloud', views.CloudSiteViewSet)
910
router.register(r'grid', views.GridSiteViewSet)
10-
11+
router.register(r'gridsync', views.GridSiteSyncViewSet)
12+
router.register(r'gridsync', views.GridSiteSyncSubmitHViewSet)
1113

1214
urlpatterns = [
13-
url(r'^', include(router.urls)),
15+
re_path(
16+
r'^gridsync/(?P<SiteName>[a-zA-Z0-9-]+)/$',
17+
views.GridSiteSyncViewSet.as_view({'get': 'retrieve'}),
18+
name='gridsync_singlesite'
19+
),
20+
re_path(
21+
r'^gridsync/(?P<SiteName>[a-zA-Z0-9-]+)/(?P<YearMonth>[0-9-]+)/$',
22+
views.GridSiteSyncSubmitHViewSet.as_view({'get': 'retrieve'}),
23+
name='gridsync_submithost'
24+
),
1425
]
26+
27+
urlpatterns += router.urls

0 commit comments

Comments
 (0)