Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-96 Django monitoring app #15

Merged
merged 53 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
09a0b8c
Ensure Python3 compatibility.
Letizia97 Jan 6, 2023
abbe8c0
Make imports more explicit.
Letizia97 Jan 6, 2023
9bd9ec0
Add allowed hosts.
Letizia97 Jan 6, 2023
96e1b4a
Add static root to be able to run "manage.py collectstatic".
Letizia97 Jan 25, 2023
c8a79d8
Ensure Python3 compatibility for CloudSite view.
Letizia97 Jan 6, 2023
6681204
Ensure the grid site works when retrieving multiple records.
Letizia97 Jan 6, 2023
e9894a9
Add import for pymysql.
Letizia97 Jan 25, 2023
8eaf744
Add models for the sync page.
Letizia97 Jan 25, 2023
58417ca
Modify names to ensure consistency with the new models (GridSiteSync).
Letizia97 Jan 25, 2023
274dc73
Add serializer for gridsync site.
Letizia97 Jan 25, 2023
40fa972
Modify names to ensure consistency with modified models.
Letizia97 Jan 25, 2023
14788f3
Add view for the gridsync table, for both single site and all sites.
Letizia97 Jan 25, 2023
39f77d2
Update field names to ensure consistency with modified models and ser…
Letizia97 Jan 25, 2023
b55b90d
Add html templates for gridsync, both all sites page and single site …
Letizia97 Jan 25, 2023
3a231a8
Update field names to ensure consistency with modified views.
Letizia97 Jan 25, 2023
acecbd3
Add urls for gridsync pages.
Letizia97 Jan 25, 2023
fc13eb7
Add model for the table with submithosts.
Letizia97 Jan 25, 2023
2a2caea
Add serialiser for the table with submithosts.
Letizia97 Jan 25, 2023
2475093
Add view for the sync table showing submithosts.
Letizia97 Jan 25, 2023
6ebb2d1
Add hyperlink to table showing submithosts.
Letizia97 Jan 25, 2023
671b4ab
Add template for table showing submithosts.
Letizia97 Jan 25, 2023
b37dde2
Add url to the page showing submithosts.
Letizia97 Jan 25, 2023
7db5eba
Trim trailing whitespaces.
Letizia97 Feb 3, 2023
bc1a8ac
Add newline at end of file.
Letizia97 Feb 3, 2023
c611943
Remove whitespace(s) where not necessary or too many.
Letizia97 Feb 3, 2023
2dbb9cf
Add whitespace(s) around operators where necessary.
Letizia97 Feb 3, 2023
d55d6ab
Remove spaces around keyword / parameter equals.
Letizia97 Feb 3, 2023
964d498
Add space after punctuation where necessary.
Letizia97 Feb 3, 2023
581cd04
Remove unnecessary blank lines.
Letizia97 Feb 3, 2023
2d3f961
Move import to the top of file.
Letizia97 Feb 3, 2023
58af9a8
Rearrange/refactor imports to shorten lines.
Letizia97 Feb 3, 2023
0cc3f30
Rearrange/refactor serialiser fields to shorten lines.
Letizia97 Feb 3, 2023
0933fb8
Rearrange/refactor urlpatterns to shorten lines.
Letizia97 Feb 3, 2023
6982316
Rearrange dicts to shorten lines.
Letizia97 Feb 3, 2023
c10e9e9
Refactor parts to create/fill dicts, to reduce duplication and file l…
Letizia97 Feb 3, 2023
d8c409e
Bring functions outside class to avoid duplication.
Letizia97 Feb 3, 2023
0761c70
Refactor to reduce line length.
Letizia97 Feb 3, 2023
2ac7462
Merge if statements to ensure clarity.
Letizia97 Feb 3, 2023
22d1383
Rearrange SQL queries to reduce line length.
Letizia97 Feb 3, 2023
5ca8c66
Create separate function for sync_status to reduce duplication.
Letizia97 Feb 3, 2023
5799dbb
Create separate function foupdating stdout and returncode.
Letizia97 Feb 3, 2023
12b166e
Refactor to reduce length of lines.
Letizia97 Feb 7, 2023
b03791d
Add missing objects that weren't created/imported
tofu-rocketry Nov 22, 2023
ee92a54
Correct reference to grid database from settings
tofu-rocketry Nov 22, 2023
3b3453d
Automate venv activation
tofu-rocketry Nov 22, 2023
9d647a6
Tidy up settings
tofu-rocketry Nov 22, 2023
bd77d79
Change sync status to match old pages
tofu-rocketry Nov 22, 2023
4b2902c
Revert changes to availability app urls
tofu-rocketry Nov 22, 2023
afd03fa
Simplify availability app to just return "OK" 200
tofu-rocketry Jan 24, 2024
f933dd7
Remove year limitation on grid pub SQL query
tofu-rocketry Jan 24, 2024
0c39eac
Add basic HTML template for status page
tofu-rocketry Jan 24, 2024
4d9f151
Add availability app to installed apps
tofu-rocketry Jan 24, 2024
40a7c6d
Update cutoff date for cloud query
tofu-rocketry Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions monitoring/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import pymysql
pymysql.install_as_MySQLdb()
1 change: 1 addition & 0 deletions monitoring/availability/templates/status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html>{{ message }}</html>
2 changes: 1 addition & 1 deletion monitoring/availability/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import url

import views
from monitoring.availability import views

urlpatterns = [
url(r'^$', views.status),
Expand Down
7 changes: 1 addition & 6 deletions monitoring/availability/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import time

from rest_framework.decorators import api_view
from rest_framework.response import Response


@api_view()
def status(requst):
if int(time.time()) % 2:
return Response("Everything OK")
else:
return Response("Everything NOT ok.")
return Response({"message": "OK"}, status=200, template_name="status.html")
59 changes: 54 additions & 5 deletions monitoring/publishing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,60 @@

class GridSite(models.Model):
fetched = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=255, primary_key=True)
SiteName = models.CharField(max_length=255, primary_key=True)
tofu-rocketry marked this conversation as resolved.
Show resolved Hide resolved
updated = models.DateTimeField()


class VSuperSummaries(models.Model):
Site = models.CharField(max_length=255, primary_key=True)
LatestPublish = models.DateTimeField()
Month = models.IntegerField()
Year = models.IntegerField()
RecordStart = models.DateTimeField()
RecordEnd = models.DateTimeField()
RecordCountPublished = models.IntegerField()

class Meta:
managed = False
db_table = 'VSuperSummaries'


class GridSiteSync(models.Model):
fetched = models.DateTimeField(auto_now=True)
SiteName = models.CharField(max_length=255)
YearMonth = models.CharField(max_length=255)
Year = models.IntegerField()
Month = models.IntegerField()
RecordStart = models.DateTimeField()
RecordEnd = models.DateTimeField()
RecordCountPublished = models.IntegerField()
RecordCountInDb = models.IntegerField()
SyncStatus = models.CharField(max_length=255)

class Meta:
# Descending order of Year and Month to display latest data first
ordering = ('SiteName', '-Year', '-Month')
unique_together = ('SiteName', 'YearMonth')


class VSyncRecords(models.Model):
Site = models.CharField(max_length=255, primary_key=True)
RecordCountInDb = models.IntegerField()

class Meta:
managed = False
db_table = 'VSyncRecords'


class CloudSite(models.Model):
fetched = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=255, primary_key=True)
vms = models.IntegerField(default=0)
script = models.CharField(max_length=255)
SiteName = models.CharField(max_length=255, primary_key=True)
Vms = models.IntegerField(default=0)
Script = models.CharField(max_length=255)
updated = models.DateTimeField()

class Meta:
ordering = ('name',)
ordering = ('SiteName',)


class VAnonCloudRecord(models.Model):
Expand All @@ -46,3 +78,20 @@ def __str__(self):
self.CloudType,
self.UpdateTime,
self.VMs)


class GridSiteSyncSubmitH(models.Model):
fetched = models.DateTimeField(auto_now=True)
SiteName = models.CharField(max_length=255)
YearMonth = models.CharField(max_length=255)
Year = models.IntegerField()
Month = models.IntegerField()
RecordStart = models.DateTimeField()
RecordEnd = models.DateTimeField()
RecordCountPublished = models.IntegerField()
RecordCountInDb = models.IntegerField()
SubmitHost = models.CharField(max_length=255)

class Meta:
ordering = ('SiteName', '-Year', '-Month')
unique_together = ('SiteName', 'YearMonth', 'SubmitHost')
67 changes: 64 additions & 3 deletions monitoring/publishing/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from rest_framework import serializers

from models import CloudSite, GridSite
from monitoring.publishing.models import (
CloudSite,
GridSite,
GridSiteSync,
GridSiteSyncSubmitH
)


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

class Meta:
model = GridSite
fields = ('url', 'name', 'updated')
fields = (
'url',
'SiteName',
'updated'
)


class GridSiteSyncSerializer(serializers.HyperlinkedModelSerializer):
# Override default format with None so that Python datetime is used as
# ouput format. Encoding will be determined by the renderer and can be
# formatted by a template filter.

class Meta:
model = GridSiteSync
fields = (
'url',
'SiteName',
'YearMonth',
'RecordStart',
'RecordEnd',
'RecordCountPublished',
'RecordCountInDb',
'SyncStatus'
)

# Sitename substitutes pk
lookup_field = 'SiteName'
extra_kwargs = {
'url': {'lookup_field': 'SiteName'}
}
Comment on lines +44 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do? Are both lookup_field and extra_kwargs needed?



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

class Meta:
model = CloudSite
fields = ('url', 'name', 'vms', 'script', 'updated')
fields = (
'url',
'SiteName',
'Vms',
'Script',
'updated'
)


class GridSiteSyncSubmitHSerializer(serializers.HyperlinkedModelSerializer):
# Override default format with None so that Python datetime is used as
# ouput format. Encoding will be determined by the renderer and can be
# formatted by a template filter.

class Meta:
model = GridSiteSyncSubmitH
fields = (
'url',
'SiteName',
'YearMonth',
'RecordStart',
'RecordEnd',
'RecordCountPublished',
'RecordCountInDb',
'SubmitHost'
)

lookup_fields = ('SiteName', 'YearMonth')
6 changes: 3 additions & 3 deletions monitoring/publishing/templates/cloudsites.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ <h2>Sites publishing cloud accounting records from 2018-06-19 onwards</h2>
</tr>
{% for site in sites %}
<tr>
<td>{{ site.name }}</td>
<td>{{ site.vms }}</td>
<td>{{ site.script }}</td>
<td>{{ site.SiteName }}</td>
<td>{{ site.Vms }}</td>
<td>{{ site.Script }}</td>
<td>{{ site.updated|date:"Y-m-d H:i:s" }}</td>
</tr>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions monitoring/publishing/templates/gridsites.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ <h3>APEL Publication Test</h3>
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>

<table>
<tr><th colspan='5' class='tableheader'>{{ sites.0.name }}</td></tr>
<tr><th colspan='5' class='tableheader'>{{ sites.0.SiteName }}</td></tr>
<tr>
<th class='tableheader'>ExecutingSite</th>
<th class='tableheader'>MeasurementDate</th>
<th class='tableheader'>MeasurementTime</th>
<th class='tableheader'>Publication <br> Status</th>
</tr>
<tr>
<td align='middle' class='tabletext'>{{ sites.0.name }}</td>
<td align='middle' class='tabletext'>{{ sites.0.SiteName }}</td>
<td align='middle' class='tabletext'>{{ last_fetched|date:"Y-m-d" }}</td>
<td align='middle' class='tabletext'>{{ last_fetched|date:"G:i:s" }}</td>
<td align='middle' class='tabletext'>{{ stdout }}</td>
Expand Down
43 changes: 43 additions & 0 deletions monitoring/publishing/templates/gridsync.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>APEL Publication Summary </title>
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>APEL Synchronisation Test</h3>
<ul>
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
<li> Major differences are flagged with FAIL.
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
<li> Contact: apel-admins [at] stfc.ac.uk
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>

<table>
<tr><th colspan='7' class='tableheader'> All sites </td></tr>
<tr>
<th class='tableheader'>Site Name</th>
<th class='tableheader'>Month</th>
<th class='tableheader'>Record Start</th>
<th class='tableheader'>Record End</th>
<th class='tableheader'>Record Count <br/> In Your Database</th>
<th class='tableheader'>Record Count <br/> What You Published</th>
<th class='tableheader'>Synchronisation <br/> Status</th>
</tr>

{% for record in records %}
<tr>
<td><a href="{% url 'gridsync_singlesite' SiteName=record.SiteName %}">{{ record.SiteName }}</td>
<td>{{ record.YearMonth }}</a> </td>
<td>{{ record.RecordStart }}</td>
<td>{{ record.RecordEnd }}</td>
<td>{{ record.RecordCountPublished }}</td>
<td>{{ record.RecordCountInDb }}</td>
<td>{{ record.SyncStatus }}</td>

</tr>
{% endfor %}

</table>
41 changes: 41 additions & 0 deletions monitoring/publishing/templates/gridsync_singlesite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>APEL Publication Summary </title>
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>APEL Synchronisation Test</h3>
<ul>
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
<li> Major differences are flagged with FAIL.
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
<li> Contact: apel-admins [at] stfc.ac.uk
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>

<table>
<tr><th colspan='6' class='tableheader'> {{ records.0.SiteName }} </td></tr>
<tr>
<th class='tableheader'>Month</th>
<th class='tableheader'>Record Start</th>
<th class='tableheader'>Record End</th>
<th class='tableheader'>Record Count <br/> In Your Database</th>
<th class='tableheader'>Record Count <br/> What You Published</th>
<th class='tableheader'>Synchronisation <br/> Status</th>
</tr>

{% for record in records %}
<tr>
<td><a href="{% url 'gridsync_submithost' SiteName=record.SiteName YearMonth=record.YearMonth %}">{{ record.YearMonth }}</a> </td>
<td>{{ record.RecordStart }}</td>
<td>{{ record.RecordEnd }}</td>
<td>{{ record.RecordCountPublished }}</td>
<td>{{ record.RecordCountInDb }}</td>
<td>{{ record.SyncStatus }}</td>

</tr>
{% endfor %}

</table>
43 changes: 43 additions & 0 deletions monitoring/publishing/templates/gridsync_submithost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>APEL Publication Summary </title>
<link href="http://goc-accounting.grid-support.ac.uk/core/stylesheet.css" rel="stylesheet" type="text/css" />
<link href="http://goc-accounting.grid-support.ac.uk/core/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>APEL Synchronisation Test</h3>
<ul>
<li> A comparison is made between your local APEL database, and the data that you have published to the GOC.
<li> Major differences are flagged with FAIL.
<li> Information about APEL <a href='https://wiki.egi.eu/wiki/APEL'>APEL Wiki</a>
<li> Contact: apel-admins [at] stfc.ac.uk
<li>lastBuild : {{ last_fetched|date:"Y-m-d H:i:s.u"|slice:":22" }}</ul><hr>

<table>
<tr><th colspan='6' class='tableheader'> {{submisthosts.0.SiteName}}, {{submisthosts.0.YearMonth}} </td></tr>
<tr>
<th class='tableheader'>Month</th>
<th class='tableheader'>SubmitHost</th>
<th class='tableheader'>RecordStart</th>
<th class='tableheader'>RecordEnd</th>
<th class='tableheader'>Record Count <br/> In Your Database</th>
<th class='tableheader'>Record Count <br/> What You Published</th>
</tr>

{% for host in submisthosts %}
<tr>

<td>{{ host.YearMonth }} </td>
<td>{{ host.SubmitHost }}</td>
<td>{{ host.RecordStart }}</td>
<td>{{ host.RecordEnd }}</td>
<td>{{ host.RecordCountPublished }}</td>
<td>{{ host.RecordCountInDb }}</td>


</tr>
{% endfor %}

</table>
19 changes: 16 additions & 3 deletions monitoring/publishing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

from rest_framework import routers

import views
from monitoring.publishing import views
from django.urls import re_path

router = routers.SimpleRouter()
router.register(r'cloud', views.CloudSiteViewSet)
router.register(r'grid', views.GridSiteViewSet)

router.register(r'gridsync', views.GridSiteSyncViewSet)
router.register(r'gridsync', views.GridSiteSyncSubmitHViewSet)

urlpatterns = [
url(r'^', include(router.urls)),
re_path(
r'^gridsync/(?P<SiteName>[a-zA-Z0-9-]+)/$',
views.GridSiteSyncViewSet.as_view({'get': 'retrieve'}),
name='gridsync_singlesite'
),
re_path(
r'^gridsync/(?P<SiteName>[a-zA-Z0-9-]+)/(?P<YearMonth>[0-9-]+)/$',
views.GridSiteSyncSubmitHViewSet.as_view({'get': 'retrieve'}),
name='gridsync_submithost'
),
]

urlpatterns += router.urls
Loading