Dashboard stats graph

This commit is contained in:
softsimon
2022-07-01 16:50:53 +02:00
parent 3152effba5
commit 24631116c4
10 changed files with 522 additions and 14 deletions

View File

@@ -2,12 +2,14 @@ import config from '../../config';
import { Express, Request, Response } from 'express';
import nodesApi from './nodes.api';
import channelsApi from './channels.api';
import statisticsApi from './statistics.api';
class GeneralRoutes {
constructor() { }
public initRoutes(app: Express) {
app
.get(config.MEMPOOL.API_URL_PREFIX + 'search', this.$searchNodesAndChannels)
.get(config.MEMPOOL.API_URL_PREFIX + 'statistics', this.$getStatistics)
;
}
@@ -27,6 +29,15 @@ class GeneralRoutes {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
private async $getStatistics(req: Request, res: Response) {
try {
const statistics = await statisticsApi.$getStatistics();
res.json(statistics);
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
}
export default new GeneralRoutes();

View File

@@ -0,0 +1,17 @@
import logger from '../../logger';
import DB from '../../database';
class StatisticsApi {
public async $getStatistics(): Promise<any> {
try {
const query = `SELECT UNIX_TIMESTAMP(added) AS added, channel_count, node_count, total_capacity FROM statistics ORDER BY id DESC`;
const [rows]: any = await DB.query(query);
return rows;
} catch (e) {
logger.err('$getStatistics error: ' + (e instanceof Error ? e.message : e));
throw e;
}
}
}
export default new StatisticsApi();