-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked home page and added server statistics api resource
Signed-off-by: Alexis Jeandet <[email protected]>
- Loading branch information
Showing
10 changed files
with
403 additions
and
194 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
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,13 @@ | ||
from fastapi.responses import JSONResponse | ||
from .routes import router | ||
from fastapi.encoders import jsonable_encoder | ||
import logging | ||
from speasy_proxy.backend import statistics | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@router.get('/get_statistics', description='Get cache statistics', response_class=JSONResponse) | ||
async def get_statistics(): | ||
log.debug(f'Client asking for statistics') | ||
return JSONResponse(content=jsonable_encoder(statistics())) |
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,32 @@ | ||
from speasy.core.cache import _cache | ||
from speasy_proxy.index import up_since | ||
from speasy_proxy import __version__ | ||
from speasy_proxy.backend.inventory_updater import ensure_update_inventory, last_update | ||
from datetime import datetime, UTC | ||
import speasy as spz | ||
|
||
|
||
def statistics(): | ||
"""Return statistics about the backend.""" | ||
_up_since = up_since.value() | ||
up_time = datetime.now(UTC) - _up_since | ||
|
||
with _cache.transact(): | ||
cache_stats = _cache.stats() | ||
cache_len = len(_cache) | ||
cache_disk = _cache.disk_size() | ||
return { | ||
'entries': cache_len, | ||
'cache_disk_size': cache_disk, | ||
'up_since': _up_since.isoformat(), | ||
'up_duration': up_time.total_seconds(), | ||
'cache_hits': cache_stats['hit'], | ||
'cache_misses': cache_stats['misses'], | ||
'inventory_update': last_update.value().isoformat(), | ||
'inventory_size': str( | ||
sum(map(lambda p: len(p.parameters), | ||
set(spz.inventories.flat_inventories.__dict__.values())))), | ||
'docs': 'https://speasyproxy.readthedocs.io/en/latest/', | ||
'speasy_version': spz.__version__, | ||
'version': __version__ | ||
} |
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
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,65 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Speasy Cache Server</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="static/theme.css" type="text/css"> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script> | ||
<script src="static/status.js"></script> | ||
<script> | ||
$(document).ready(function () { | ||
update_status(); | ||
setInterval(update_status, 10000); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<header> | ||
<div class="container" style="display: flex; align-items: center; justify-content: center;"> | ||
<div class="logo"> | ||
<img src="static/logo_speasy.svg" alt="Speasy logo" height="80px"> | ||
</div> | ||
<div class="title"> | ||
<h1>Speasy Cache Server</h1> | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<div class="container" style="height: 90%; text-align: center; justify-content: center;"> | ||
<section class="container" style="height: 100%"> | ||
<p> This the shared cache server for the Speasy project. It allows to share Speasy requests results between | ||
users across the world. | ||
</p> | ||
<p>You can access and experiment with the API <a href="/docs">here</a>.</p> | ||
<p>The source code is available on <a href="https://github.com/SciQLop/speasy_proxy">GitHub</a>. | ||
</p> | ||
</section> | ||
|
||
<div class="container"> | ||
<h2>Cache Status</h2> | ||
<div class="container" style="text-align: center;"> | ||
<ul class="container" id="status-container" style="height: 100%; text-align: left; display: inline-block;"> | ||
<li class="last-updated">Last updated: 2024-01-11 18:31 CET</li> | ||
<li class="version"></li> | ||
<li class="up-since"></li> | ||
<li class="cache-size"></li> | ||
<li class="cache-entries"></li> | ||
<li class="cache-hits"></li> | ||
<li class="cache-misses"></li> | ||
<li class="uptime"></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container" style="position: fixed; bottom: 2.5rem; right:0; width: 40%; height: 2.5rem;"> | ||
<img src="static/logo_LPP.png" alt="Speasy logo" height="80px"> | ||
<img src="static/logo_CDPP.jpg" alt="Speasy logo" height="80px"> | ||
</div> | ||
<footer style="position: absolute; bottom: 0; width: 40%; height: 2.5rem"> | ||
Copyright © 2024 Laboratory of Plasma Physics | ||
</footer> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.