FullStack: Add metrics API

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-02-02 17:03:11 +00:00
parent 20dbac3ebc
commit ebcf6a1c62
3 changed files with 43 additions and 2 deletions

View File

@ -1,6 +1,6 @@
const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services')
const corpus = require('../services/corpus.services');
const os = require('os')
async function getStations(){
var out = await db.query("stations")
@ -15,8 +15,11 @@ async function getCorpus(){
}
async function hits(){
var out = await db.query("meta");
var dat = await db.query("meta", {target: "ext_api"});
log.out(`listServices.meta: fetched server meta`)
let out = {}
out.host = os.hostname()
out.dat = dat
return out;
}

20
static/js/stat.js Normal file
View File

@ -0,0 +1,20 @@
init();
async function init() {
display(await get())
}
async function get() {
var url = `${window.location.origin}/api/v1/list/hits`;
var resp = await fetch(url);
return await resp.json();
}
async function display(data) {
document.getElementById('server_host').textContent = `HOST: ${data.host}`;
let dat = data.dat[0]
console.log(JSON.stringify(dat))
document.getElementById('time').textContent = `COUNTER START TIME: ${dat.since}`;
document.getElementById('ldbws').textContent = dat.ldbws || "0";
document.getElementById('ldbsvws').textContent = dat.ldbsvws || "0";
}

18
static/stat.html Normal file
View File

@ -0,0 +1,18 @@
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OwlBoard - STATS</title>
<script src="./js/stat.js"></script>
</head>
<body>
<h1>OwlBoard Server Stats</h1>
<h2 id="server_host"></h2>
<p id="time"></p>
<h3>LDBWS API Hits: <span id="ldbws"></span></h3>
<h3>LDBSVWS API Hits: <span id="ldbsvws"></span></h3>
<br><br>
<p>Multiple servers can be attached to one database. All servers sharing this servers DB are represented in these statistics,
responses that do not lead to an upstream API hit are not counted.
</p>
</body>
</html>