-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
17,113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.pyc | ||
__pycache__/ | ||
.idea/ | ||
|
||
keys/ | ||
/monitor/module/path.py | ||
|
||
|
||
./db.sqlite3 | ||
db.sqlite3 | ||
TODO.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# hbp-hpc-monitor | ||
Real time HPC systems status monitor with user's details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'monitor.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from django.db import models | ||
from django.utils.timezone import now | ||
|
||
|
||
class User(models.Model): | ||
id = models.IntegerField(primary_key=True) | ||
username = models.TextField(max_length=32) | ||
first_name = models.TextField(max_length=32) | ||
last_name = models.TextField(max_length=32) | ||
institution = models.TextField(blank=True, max_length=32) | ||
email = models.CharField(unique=True, blank=True, max_length=32) | ||
|
||
def __str__(self): | ||
return '(id=%s, username=%s)' % (self.id, self.username) | ||
|
||
def save(self, *args, **kwargs): | ||
print('Creating new user: %s' % self) | ||
super(User, self).save(*args, **kwargs) | ||
|
||
class Meta: | ||
ordering = ['id', 'first_name', 'last_name', 'email', 'institution'] | ||
|
||
|
||
class Visit(models.Model): | ||
user = models.ForeignKey(User, on_delete=models.DO_NOTHING) | ||
date = models.DateTimeField(auto_now_add=True, blank=True) | ||
# session = models.CharField(max_length=32) | ||
|
||
def __str__(self): | ||
return '(user=%s, date=%s)' % (self.user, self.date) | ||
|
||
def save(self, *args, **kwargs): | ||
if self.date == None: | ||
self.date = now() | ||
try: | ||
last_visit = list(Visit.objects.filter(user=self.user))[-1] | ||
if ((self.date - last_visit.date).seconds / 60) < 1.0: | ||
print('Session already recorded') | ||
return | ||
except IndexError: | ||
pass | ||
print('Recording session...') | ||
super(Visit, self).save(*args, **kwargs) | ||
|
||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
""" | ||
Django settings for monitor project. | ||
Generated by 'django-admin startproject' using Django 2.2.1. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/2.2/ref/settings/ | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
from monitor.module.path import * | ||
sys.path.append(KEYS_PATH) | ||
sys.path.append(DB_CONF_PATH) | ||
|
||
from production_key import SECRET_KEY | ||
from database_conf import * | ||
|
||
|
||
HBP_MY_USER_URL = 'https://services.humanbrainproject.eu/idm/v1/api/user/me' | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ | ||
|
||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'monitor', | ||
'sslserver', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'monitor.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [os.path.join(BASE_DIR, 'templates'),], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'monitor.wsgi.application' | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': DB_ENGINE, | ||
'NAME': DB_NAME, | ||
'USER': DB_USER, | ||
'PASSWORD': DB_USER_PASSWD, | ||
'HOST': DB_HOST, | ||
'PORT': DB_PORT | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/2.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/2.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
STATICFILES_DIRS = ( | ||
os.path.join(BASE_DIR, 'static/'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""monitor URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/2.2/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
|
||
from django.contrib import admin | ||
from django.urls import path | ||
from monitor import views | ||
|
||
|
||
urlpatterns = [ | ||
|
||
path('', views.index, name='index'), | ||
|
||
path('user', views.get_user, name='user'), | ||
path('status', views.get_status, name='status'), | ||
|
||
path('pizdaint', views.get_hpc_info, name='pizdaint'), | ||
path('pizdaint/projects', views.get_hpc_info, name='pizdaint-projects'), | ||
path('pizdaint/check', views.check_job_submission, name='pizdaint-check-job-submission'), | ||
path('marconi', views.get_hpc_info, name='marconi'), | ||
path('marconi/projects', views.get_hpc_info, name='marconi-projects'), | ||
path('marconi/check', views.check_job_submission, name='marconi-check-job-submission') | ||
|
||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# HPC System enabled | ||
|
||
HPC_SYSTEMS = { | ||
|
||
'0': { | ||
'name': 'JURECA (JSC)', | ||
'id': 'JURECA', | ||
'root_url': 'https://hbp-unic.fz-juelich.de:7112/HBP_JURECA/rest/core', | ||
'submit_url': 'https://hbp-unic.fz-juelich.de:7112/HBP_JURECA/rest/core/jobs', | ||
'quota_url': 'https://hbp-unic.fz-juelich.de:7112/HBP_JURECA/rest/core/factories/default_target_system_factory', | ||
'system': 'UNICORE', | ||
'job': { | ||
'on_system': "{'Executable': '/bin/date', 'Resources': {'Runtime': '60'}}", | ||
'on_service_account': "none" | ||
} | ||
}, | ||
|
||
'1': { | ||
'name': 'PIZDAINT (CSCS)', | ||
'id': 'PIZDAINT', | ||
'root_url': 'https://bspmonitors.cineca.it/pizdaint', | ||
'submit_url': 'https://unicoregw.cscs.ch:8080/DAINT-CSCS/rest/core/jobs', | ||
'quota_url': 'https://bspmonitors.cineca.it/pizdaint/projects', | ||
'system': 'UNICORE', | ||
'job': { | ||
'on_system': "{'Executable': '/bin/date', 'Resources': {'Runtime': '60', 'NodeConstraints': 'mc'}}", | ||
'on_service_account': { | ||
'is_link': True, | ||
'value': 'https://bspsa.cineca.it/jobs/pizdaint/' | ||
} | ||
} | ||
}, | ||
|
||
'2': { | ||
'name': 'NSG', | ||
'id': 'NSG', | ||
'root_url': 'https://nsgr.sdsc.edu:8443/cipresrest/v1', | ||
'system': 'UNKNOWN', | ||
'job': { | ||
'on_system': 'none', | ||
'on_service_account': { | ||
'is_link': True, | ||
'value': 'https://bspsa.cineca.it/jobs/nsg/' | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from django.shortcuts import render | ||
from django.http import HttpResponse | ||
|
||
from monitor.settings import HBP_MY_USER_URL as USER_URL | ||
from monitor.utils.hpc import HPC_SYSTEMS | ||
from monitor.models import * | ||
|
||
import requests | ||
import json | ||
|
||
|
||
def index(request): | ||
data = {"hpc": json.dumps(HPC_SYSTEMS)} | ||
return render(request, 'monitor/monitor.html', data) | ||
|
||
|
||
def get_status(request): | ||
if request.method == 'GET': | ||
content = {'bsp-hpc-monitor-status': 1} | ||
return HttpResponse(json.dumps(content), content_type='application/json') | ||
|
||
|
||
def get_user(request): | ||
headers = { | ||
'Authorization': request.META['HTTP_AUTHORIZATION'], | ||
'Content-Type': 'application/json' | ||
} | ||
r = requests.get(url=USER_URL, headers=headers) | ||
if r.status_code == 200: | ||
user = r.json() | ||
institution = '' | ||
email = '' | ||
if len(user['institutions']) >= 1: | ||
institutions = user['institutions'] | ||
for i in institutions: | ||
if i['primary']: | ||
institution = i['name'] | ||
if len(user['emails']) >= 1: | ||
emails = user['emails'] | ||
for e in emails: | ||
if e['primary']: | ||
email = e['value'] | ||
new_user = User( | ||
id=int(user['id']), | ||
username=user['username'], | ||
first_name=user['givenName'], | ||
last_name=user['familyName'], | ||
institution=institution, | ||
email=email | ||
) | ||
new_user.save() | ||
Visit(user=new_user).save() | ||
response = HttpResponse() | ||
response.status_code = r.status_code | ||
response.content = r.content | ||
return response | ||
|
||
|
||
def get_hpc_info(request): | ||
url = '' | ||
headers = { | ||
'Authorization': request.META['HTTP_AUTHORIZATION'], | ||
'Content-Type': 'application/json' | ||
} | ||
if 'HTTP_X_UNICORE_USER_PREFERENCES' in request.META: | ||
headers['HTTP_X_UNICORE_USER_PREFERENCES'] = request.META['HTTP_X_UNICORE_USER_PREFERENCES'] | ||
|
||
if request.path == '/pizdaint': | ||
url = 'https://brissago.cscs.ch:8080/DAINT-CSCS/rest/core' | ||
elif request.path == '/pizdaint/projects': | ||
url = 'https://brissago.cscs.ch:8080/DAINT-CSCS/rest/core/factories/default_target_system_factory' | ||
r = requests.get(url=url, headers=headers, verify=False) | ||
return HttpResponse(status=r.status_code, content=r.content) | ||
|
||
|
||
def check_job_submission(request): | ||
hpc = None | ||
if request.path == '/pizdaint/check': | ||
hpc = HPC_SYSTEMS['1'] | ||
|
||
job = hpc['job']['on_system'] | ||
headers = { | ||
'Authorization': request.META['HTTP_AUTHORIZATION'], | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
r = requests.post(url=hpc['submit_url'], headers=headers, data=job, verify=False) | ||
return HttpResponse(status=r.status_code, content=r.content) |
Oops, something went wrong.