Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
c79eb8f
Add "grid" db details and rename other to 'cloud'
tofu-rocketry Apr 30, 2019
f798f30
Change ModelViewSet to ReadOnly version
tofu-rocketry Apr 30, 2019
58c79dd
Add basic single site retrieve view method
tofu-rocketry Apr 30, 2019
71268e2
Add placeholder Nagios style result to site output
tofu-rocketry Apr 30, 2019
13415a8
Add VMsInLastUpdate to cloud output
tofu-rocketry May 1, 2019
6708537
Change schema that grid db setting uses
tofu-rocketry May 1, 2019
0ac742e
Clean up
tofu-rocketry May 1, 2019
c256acf
Initial work on grid monitoring
tofu-rocketry May 1, 2019
6a4c786
Add basic grid data retrieval
tofu-rocketry May 1, 2019
c2a0a23
Add HTML template for grid
tofu-rocketry May 1, 2019
71d66a9
Tweak datetime filter
tofu-rocketry May 1, 2019
bad274e
Update Django version
tofu-rocketry Jun 11, 2019
ea841a3
Bump django from 1.11.21 to 1.11.22
dependabot[bot] Jul 3, 2019
31cf23d
Bump django from 1.11.22 to 1.11.23
dependabot[bot] Aug 6, 2019
2e8a5b9
Update requirements
tofu-rocketry Nov 22, 2019
77c200f
Update mysqlclient requirement
tofu-rocketry Nov 22, 2019
18b838f
Fix formatting of datetime in cloud HTML
tofu-rocketry Nov 22, 2019
9f9dc46
Correct model used for grid serializer
tofu-rocketry Nov 22, 2019
4cd87e9
Add header to cloud HTML
tofu-rocketry Nov 22, 2019
fb4d50f
Fix datetime fields for grid
tofu-rocketry Nov 22, 2019
0879c13
Change what's shown in grid status column
tofu-rocketry Nov 22, 2019
63c08d2
Change which field is used for measurement
tofu-rocketry Nov 22, 2019
c7fe6ca
Add basic checking of publishing time
tofu-rocketry Nov 22, 2019
24cc4dd
Bump django from 1.11.26 to 1.11.28
dependabot[bot] Feb 27, 2020
3719da0
Bump django from 1.11.28 to 1.11.29
dependabot[bot] Jun 5, 2020
c6949f3
Bump djangorestframework from 3.9.4 to 3.11.2
dependabot[bot] Mar 19, 2021
c15c99d
Bump django from 1.11.29 to 2.2.24
dependabot[bot] Jun 10, 2021
184a691
Bump django from 2.2.24 to 2.2.27
dependabot[bot] Feb 10, 2022
2cf7ebe
Merge pull request #10 from apel/dependabot/pip/django-2.2.27
jrha Feb 11, 2022
4093e61
Bump django from 2.2.27 to 2.2.28 (#11)
dependabot[bot] Apr 27, 2022
b6d23f1
Add file explaining how to get the app working on an aq machine.
Letizia97 Feb 22, 2023
282dc43
Add file explaining how to access pages of the monitoring app.
Letizia97 Feb 22, 2023
d94b4dc
Add file listing packages installed by Quattor.
Letizia97 Feb 22, 2023
7422c4b
Add reminder about modifying security groups.
Letizia97 Feb 23, 2023
be3e742
Improve clarity of content.
Letizia97 Feb 23, 2023
ef2932d
Remove whitespaces and unnecessary blank lines.
Letizia97 Feb 23, 2023
b751833
Apply suggestions from code review
tofu-rocketry Jan 18, 2024
f90e503
Merge pull request #17 from Letizia97/django_app_docs
tofu-rocketry Jan 18, 2024
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
03f8758
Merge pull request #15 from Letizia97/django_experiments_3
tofu-rocketry Feb 28, 2024
20857e5
Add configuration file
Oct 28, 2024
f42d9a6
Update code to have try and catch block and address comments
Oct 29, 2024
ac19a35
Rename section headers and fix the file path
Oct 29, 2024
b8f88b0
Apply suggestions from code review
Sae126V Nov 13, 2024
730c582
Merge pull request #21 from Sae126V/GT-293-Add-common-configuration-file
tofu-rocketry Nov 13, 2024
e1299ae
Update packages to work with py3.6 (#23)
Sae126V Nov 14, 2024
e244961
Add styles sheets and fix references to them
tofu-rocketry Feb 28, 2024
7f8ee86
Add pre-commit config
tofu-rocketry Nov 14, 2024
5d7228e
Tidy whitespace, line endings and file endings
tofu-rocketry Nov 14, 2024
a92afbb
Merge pull request #24 from tofu-rocketry/pre-commit
tofu-rocketry Nov 15, 2024
420075a
Change DEBUG to False
tofu-rocketry Dec 4, 2024
64d7871
Move SECRET_KEY to settings.ini for config man
tofu-rocketry Dec 4, 2024
2572081
Merge pull request #28 from tofu-rocketry/prod-config
tofu-rocketry Dec 4, 2024
525e17f
Fix issue with ConfigParser interpolation by disabling
Feb 12, 2025
ab0697f
Remove unused imports in url.py
Sae126V Feb 26, 2025
92b6e55
Update code to allow dot(s) in regex pattern
Sae126V Feb 26, 2025
3b20da7
Update code to use SiteName as a lookup_field
Sae126V Feb 26, 2025
e336bcd
Update code to make gridsync URL work with the sitename(s)
Sae126V Feb 26, 2025
dcf6013
Update code to make gridsync work with sitename and yearmonth
Sae126V Feb 27, 2025
cb63154
Fix codeclimate issues
Sae126V Feb 27, 2025
62edf14
Move MultipleFieldLookup class outside
Sae126V Feb 27, 2025
a1821cf
Update code to allow underscore in an regex pattern
Sae126V Mar 19, 2025
2d278b1
Update code to fix grammer for the comments
Sae126V Apr 14, 2025
3b5c92f
Remove lookup_field as it is been overridden
Sae126V Apr 29, 2025
b7fd803
Update code to make html queryparams work
Sae126V Apr 30, 2025
674682b
Merge pull request #33 from Sae126V/fix-issues-with-url
tofu-rocketry May 6, 2025
047d59b
Initial commit to work around slow SQL queries
Sae126V Apr 29, 2025
3d0cec1
Add pagination to gridsync records
Sae126V May 2, 2025
69f4b74
Improve styling and comments, and reuse functions
Sae126V May 8, 2025
1a81643
Add log separators and move function to script
Sae126V May 16, 2025
b5b64f3
Merge pull request #37 from Sae126V/dv-improve-performance
tofu-rocketry May 19, 2025
ed2c9c2
Set HTML as a default renderer and remove admin renderer
Sae126V Jun 13, 2025
02062b5
Update version number to 0.2
tofu-rocketry Jun 17, 2025
946ee5a
Update reqs to last versions that support Py3.6
tofu-rocketry Jun 17, 2025
323ee1e
Set app names to dotted paths relative to base dir
tofu-rocketry Jun 17, 2025
5b23760
Update version numbers and formatting in docs
tofu-rocketry Jun 18, 2025
233e638
Merge pull request #41 from tofu-rocketry/update-reqs
tofu-rocketry Jun 18, 2025
0170e95
Update version number for v0.3
tofu-rocketry Jun 19, 2025
f5d5590
Filter all db update queries to last 3 years
tofu-rocketry Jun 19, 2025
3005e4c
Update version to v0.4
tofu-rocketry Jun 19, 2025
f51396e
Pin numpy version for Py3.6 compatibility
tofu-rocketry Jun 23, 2025
7583b39
Reduce time filters
tofu-rocketry Jun 23, 2025
82e175d
Move db_update_sqlite file to app level
Sae126V Aug 14, 2025
34631fb
Add benchmarks app
garaimanoj Aug 12, 2025
5e36e49
Update app name
garaimanoj Aug 12, 2025
c1e7bad
Add extra_kwargs
garaimanoj Aug 12, 2025
9272d9b
Update view name
garaimanoj Aug 12, 2025
8e9703a
Rename view
garaimanoj Aug 12, 2025
07d9191
Update url
garaimanoj Aug 12, 2025
d3c0a1c
Rename template
garaimanoj Aug 12, 2025
76ad09e
Refresh benchmarks data
garaimanoj Aug 12, 2025
43f18bb
Fetch data from VSummaries
garaimanoj Aug 13, 2025
0ccdf75
Use grid database
garaimanoj Aug 14, 2025
281993a
Fix the datatype
garaimanoj Aug 14, 2025
b70d9fb
Update variable name
garaimanoj Aug 14, 2025
31e4996
Update variable name
garaimanoj Aug 14, 2025
1f380d5
Fetch data from two tables
garaimanoj Aug 15, 2025
736261f
Refactoring
garaimanoj Aug 15, 2025
85a493b
Update select query for VNormalisedSummaries
garaimanoj Aug 15, 2025
6798431
Refactoring
garaimanoj Aug 18, 2025
d6d0c94
Refresh benchmarks data
garaimanoj Aug 12, 2025
2c51440
Fetch data from VSummaries
garaimanoj Aug 13, 2025
d3bff63
Use grid database
garaimanoj Aug 14, 2025
3917a31
Fetch data from two tables
garaimanoj Aug 15, 2025
eb5e1b0
Refactoring
garaimanoj Aug 15, 2025
a477d2b
Update select query for VNormalisedSummaries
garaimanoj Aug 15, 2025
f8cd8e9
Add verbose_name
garaimanoj Aug 18, 2025
9516de8
Fix the url
garaimanoj Aug 18, 2025
a5389c3
Update query for VJobRecords
garaimanoj Aug 19, 2025
34886bd
Import models
garaimanoj Aug 19, 2025
9e99240
Update header
garaimanoj Aug 19, 2025
3173166
Rename columns and add new line
garaimanoj Aug 19, 2025
3671d89
Trim trailing whitespace
garaimanoj Aug 20, 2025
5a00011
Make the site sorting case insensitive
garaimanoj Aug 20, 2025
e7ddcf4
Rename columns
garaimanoj Aug 21, 2025
41440a2
Remove annotate
garaimanoj Aug 21, 2025
18c209d
Remove trailing whitespace in update script
tofu-rocketry Aug 21, 2025
7607093
Merge pull request #52 from garaimanoj/gt1044
tofu-rocketry Aug 21, 2025
af41d31
Add site counts by record type
garaimanoj Aug 21, 2025
8f8efa6
Add new line
garaimanoj Aug 21, 2025
1592408
Trim trailing whitespace
garaimanoj Aug 21, 2025
a694281
Merge pull request #55 from garaimanoj/gt1046
tofu-rocketry Aug 22, 2025
d8c3114
Improve HTML template for cloud page
tofu-rocketry Aug 21, 2025
502ba90
Tidy HTML and improve text
tofu-rocketry Aug 21, 2025
f50e8ed
Add missing semi-colon to stylesheet
tofu-rocketry Aug 21, 2025
84fe876
Fix cloud page <head> tag(s)
tofu-rocketry Aug 21, 2025
bbe9f1a
Fix misplaced link </a> tag
tofu-rocketry Aug 21, 2025
4e1c338
Increase font size to match other text
tofu-rocketry Aug 21, 2025
84668d2
Add missing style to table contents
tofu-rocketry Aug 21, 2025
370657f
Add humanised formatting to the large numbers
tofu-rocketry Aug 21, 2025
48b8a4b
Update site base urls to use newer path() function
tofu-rocketry Aug 21, 2025
5212531
Add basic home page
tofu-rocketry Aug 21, 2025
d085961
Fix template dir path
tofu-rocketry Aug 21, 2025
27a0437
Add names to project urls for later referencing
tofu-rocketry Aug 21, 2025
eb21d6a
Add list of hyperlinked pages to home page
tofu-rocketry Aug 21, 2025
0ed1f1d
Reorganise URL naming
tofu-rocketry Aug 21, 2025
5f8bf50
Use correct URL name
tofu-rocketry Aug 21, 2025
b2917ab
Remove availability link as not for human parsing
tofu-rocketry Aug 21, 2025
11246cc
Add more detail and examples
tofu-rocketry Aug 21, 2025
754ef75
Remove repitition
tofu-rocketry Aug 27, 2025
f4141ef
Merge pull request #56 from tofu-rocketry/user-info-improvements
tofu-rocketry Aug 27, 2025
8c97355
Convert remaining url() to path() (#58)
tofu-rocketry Aug 28, 2025
896bb3a
Add sorting by update time (#59)
garaimanoj Sep 3, 2025
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
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://pre-commit.com for more information
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 # Python 3.6 compatible
hooks:
# Python related checks
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: name-tests-test
name: Check unit tests start with 'test_'
args: ['--django']
files: 'test/.*'
# Other checks
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
name: Force line endings to LF
args: ['--fix=lf']
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations

# Pre-commit CI config, see https://pre-commit.ci/
ci:
autofix_prs: false
autoupdate_schedule: quarterly
27 changes: 27 additions & 0 deletions docs/setting_up_VM_with_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Steps to follow to get a VM with monitoring app running on Apache

To get a 'prototype' of the monitoring app running with Apache, follow these steps:
- create a cloud VM of the type: scientific-linux-7-aq
- continue by selecting sandbox 'testing_personality_2', archetype 'ral-tier1', personality 'apel-data-validation-test'

Allow 15 minutes after the machine is created, then remember to edit security groups from OpenStack to allow Apache to work.
Then follow these steps from within the machine:
- quattor-fetch && quattor-configure --all
- cd /usr/share/DJANGO_MONITORING_APP/monitoring
- modify the file settings.py, specifically the dict called DATABASES, to include the right credentials and database names
- cd ..
- source venv/bin/activate
- systemctl restart httpd
- sudo chown apache .

At this point the app should be working, so just get the ip address by writing "hostname -I" within the machine and the app should be already running at that address.


## What to do if the app seems to stop working after closing the VM
If the VM is shut down, next time we try to open the app, Apache might give the error message "Unable to open the database file".
If this happens, just follow these steps on the machine:
1. cd /usr/share/DJANGO_MONITORING_APP
2. source venv/bin/activate
3. sudo chown apache .

Note that step 2 is necessary for step 3 to work and the error message to disappear.
23 changes: 23 additions & 0 deletions docs/what_gets_installed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
For Django to work with apache, it is common to have a venv within the app, where django and djangorestframework get installed. Other packages needed for the app to work are installed by Aquilon outside the venv.

## Packages installed by Aquilon outside the venv
Following the config file that Aquilon uses, the following are the packages installed:
- `httpd`
- `python3-mod_wsgi` (for apache to work with django)
- `python3-devel`
- `gcc` (needed for dependencies)
- `mariadb`
- `tar`

## Packages installed within the venv
Within venv, the following are installed through pip:
- `djangorestframework` (3.15.1)
- `pymysql` (1.0.2) (needed for mariadb to work)
- `pandas` (1.1.5) (needed by the app)
- `django` (3.2.25)
- `pytz` (2025.2)

Note that when the version of the packages is specified, the app would not work with a different version (due to dependencies conflicts).

Is is also important to note that different types of OS require different packages to be installed.
The above are the packages that allow the app to work on a Rocky8.
22 changes: 22 additions & 0 deletions docs/what_pages_can_be_accessed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Pages that can be accessed through the app

The following urls are the ones that can be accessed without passing any parameter:
- http://ip-address/publishing/cloud/
- http://ip-address/publishing/gridsync/

These pages show info for a number of sites, so do not require a site name to be specified within the url.

The url http://ip-address/publishing/grid/ , instead, should be used together with the name of the site we are looking for.
For example: http://ip-address/publishing/grid/BelGrid-UCL/
It is not supposed to be used without passing the name of the site.

The url http://ip-address/publishing/gridsync/ shows a sync table, and it's probably the most important bit of the personality 'apel-data-validation'.
This table contains data related to many sites, specifically number of jobs being published vs in the db, and this number is shown for every (available) month of each site.

Clicking on any name in the first column (containing site names) allows to access a similar table which only shows the data relative to that site.
This more specific table is such that the first columns shows the months for which we have data (for that site).
Clicking on the month allows to open another table that shows data for that month and site only, divided by submithost.

The pages accessed through the links can of course be accessed by typing directly the url. For example, if we want data related to the site 'CSCS-LCG2' and month '2013-11', we would type :
http://ip-address/publishing/gridsync/CSCS-LCG2/2013-11/
However, in this case if there is no data for the month we are looking for, we would get an error.
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()
2 changes: 1 addition & 1 deletion monitoring/availability/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@


class AvailabilityConfig(AppConfig):
name = 'availability'
name = 'monitoring.availability'
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>
6 changes: 3 additions & 3 deletions monitoring/availability/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import url
from django.urls import path

import views
from monitoring.availability import views

urlpatterns = [
url(r'^$', views.status),
path('', views.status, name='availability'),
]
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")
Empty file.
3 changes: 3 additions & 0 deletions monitoring/benchmarks/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions monitoring/benchmarks/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BenchmarksConfig(AppConfig):
name = 'monitoring.benchmarks'
Empty file.
54 changes: 54 additions & 0 deletions monitoring/benchmarks/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.db import models


class BenchmarksBySubmithost(models.Model):
fetched = models.DateTimeField(auto_now=True)
SiteName = models.CharField(max_length=255)
SubmitHost = models.CharField(max_length=255)
BenchmarkType = models.CharField(max_length=50)
BenchmarkValue = models.DecimalField(max_digits=10, decimal_places=3)
RecordType = models.CharField(max_length=50)
UpdateTime = models.DateTimeField()

class Meta:
ordering = ('SiteName',)


class VJobRecords(models.Model):
Site = models.CharField(max_length=255, primary_key=True)
SubmitHost = models.CharField(max_length=255)
ServiceLevelType = models.CharField(max_length=50)
ServiceLevel = models.DecimalField(max_digits=10, decimal_places=3)
UpdateTime = models.DateTimeField()
EndTime = models.DateTimeField()

class Meta:
managed = False
db_table = 'VJobRecords'
verbose_name = 'Job Record'


class VSummaries(models.Model):
Site = models.CharField(max_length=255, primary_key=True)
SubmitHost = models.CharField(max_length=255)
ServiceLevelType = models.CharField(max_length=50)
ServiceLevel = models.DecimalField(max_digits=10, decimal_places=3)
UpdateTime = models.DateTimeField()

class Meta:
managed = False
db_table = 'VSummaries'
verbose_name = 'Summary'


class VNormalisedSummaries(models.Model):
Site = models.CharField(max_length=255, primary_key=True)
SubmitHost = models.CharField(max_length=255)
ServiceLevelType = models.CharField(max_length=50)
ServiceLevel = models.DecimalField(max_digits=10, decimal_places=3)
UpdateTime = models.DateTimeField()

class Meta:
managed = False
db_table = 'VNormalisedSummaries'
verbose_name = 'Normalised Summary'
21 changes: 21 additions & 0 deletions monitoring/benchmarks/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework import serializers

from monitoring.benchmarks.models import BenchmarksBySubmithost


class BenchmarksBySubmithostSerializer(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.
UpdateTime = serializers.DateTimeField(format=None)

class Meta:
model = BenchmarksBySubmithost
fields = (
'SiteName',
'SubmitHost',
'BenchmarkType',
'BenchmarkValue',
'RecordType',
'UpdateTime',
)
49 changes: 49 additions & 0 deletions monitoring/benchmarks/templates/benchmarks_by_submithost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<title>Sites publishing benchmark records</title>
</head>

<body>
<h2>Sites publishing benchmark records in last 3 months</h2>
<p>Page last updated: {{ last_fetched|date:"Y-m-d H:i:s.u" }}</p>
<table border="1">
<tr>
<th>Record type</th>
<th>Number of Sites</th>
</tr>
{% for item in site_counts_by_record_type %}
<tr>
<td>{{ item.RecordType }}</td>
<td>{{ item.site_count }}</td>
</tr>
{% endfor %}
</table>

<br/>

<table border="1">
<tr>
<th>Site</th>
<th>Submit host</th>
<th>Benchmark type</th>
<th>Benchmark value</th>
<th>Record type</th>
<th>Last updated</th>
</tr>
{% for benchmark in benchmarks %}
<tr>
<td>{{ benchmark.SiteName }}</td>
<td>{{ benchmark.SubmitHost }}</td>
<td>{{ benchmark.BenchmarkType }}</td>
<td>{{ benchmark.BenchmarkValue }}</td>
<td>{{ benchmark.RecordType }}</td>
<td>{{ benchmark.UpdateTime|date:"Y-m-d H:i:s" }}</td>
</tr>
{% endfor %}
</table>
</body>

</html>
3 changes: 3 additions & 0 deletions monitoring/benchmarks/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions monitoring/benchmarks/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import routers

from monitoring.benchmarks import views

router = routers.SimpleRouter()
router.register('', views.BenchmarksViewSet)

urlpatterns = router.urls
45 changes: 45 additions & 0 deletions monitoring/benchmarks/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.shortcuts import render
from datetime import datetime, timedelta

from django.db.models import Max, Count
from django.db.models.functions import Lower

from rest_framework import viewsets
from rest_framework.renderers import TemplateHTMLRenderer


from monitoring.benchmarks.models import BenchmarksBySubmithost

from monitoring.benchmarks.serializers import BenchmarksBySubmithostSerializer

class BenchmarksViewSet(viewsets.ReadOnlyModelViewSet):
# Lower('SiteName'): sorts sites alphabetically, case-insensitively.
# '-UpdateTime': sorts records within each site by UpdateTime in descending order (latest first).
queryset = BenchmarksBySubmithost.objects.all().order_by(Lower('SiteName'), '-UpdateTime')

serializer_class = BenchmarksBySubmithostSerializer
template_name = 'benchmarks_by_submithost.html'

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

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

# Count number of distinct sites per RecordType
site_counts_by_record_type = (
BenchmarksBySubmithost.objects
.values('RecordType')
.annotate(site_count=Count('SiteName', distinct=True))
.order_by('RecordType')
)

if type(request.accepted_renderer) is TemplateHTMLRenderer:
response.data = {
'benchmarks': response.data,
'last_fetched': last_fetched,
'site_counts_by_record_type': site_counts_by_record_type
}

return response
Loading