From e2ad549ed12edc7b21d75fe7ccf55a5283fd5dbd Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Mon, 13 Nov 2023 16:26:03 +0300 Subject: [PATCH] progress --- controllers/app.controller.js | 43 +++++++++++-- data.db | Bin 20480 -> 20480 bytes public/index.html | 115 +++++++++++++++++----------------- routes/api/app.router.js | 9 +-- 4 files changed, 98 insertions(+), 69 deletions(-) diff --git a/controllers/app.controller.js b/controllers/app.controller.js index a389e63..6035e37 100644 --- a/controllers/app.controller.js +++ b/controllers/app.controller.js @@ -1,4 +1,5 @@ import db from "#root/config/database.config.js"; +import cp from 'child_process' /** * Services @@ -14,7 +15,7 @@ export const appController = { */ async getConfig(req, res, next) { try { - const data = await appService.getConfig(db); + const data = await appService.getConfig(); if (!data) return res.status(200).json({ config: null }); return res.status(200).json({ config: data }); } catch (error) { @@ -30,7 +31,7 @@ export const appController = { */ async updateConfig(req, res, next) { try { - const config = await appService.getConfig(db); + const config = await appService.getConfig(); const payload = req.body; if (!config) await db.run(`INSERT INTO "app_config" (id) VALUES (?)`, [0]); @@ -81,7 +82,7 @@ export const appController = { */ async isConfigured(req, res, next) { try { - const config = await appService.getConfig(db); + const config = await appService.getConfig(); if (!config) return res.status(200).json({ is_configured: false }); for (const colPrefix of ['mb_tcp', 'mb_rtu']) { @@ -98,5 +99,39 @@ export const appController = { } catch (error) { next(error); } - } + }, + + /** + * Application memory usage + * @param {import('express').Request} req + * @param {import('express').Response} res + * @param {import('express').NextFunction} next + */ + memoryUsage(req, res, next) { + const memoryUsage = process.memoryUsage(); + const bytesToMB = (bytes) => bytes / 10**6; + Object.keys(memoryUsage).forEach(k => (memoryUsage[k] = `${bytesToMB(memoryUsage[k])}MB`)); + return res.status(200).json({ data: memoryUsage }); + }, + + /** + * Ping + * @param {import('express').Request} req + * @param {import('express').Response} res + * @param {import('express').NextFunction} next + */ + ping(req, res, next) { + return res.status(200).send('pong'); + }, + + /** + * Send info about latest commit hash + * @param {import('express').Request} req + * @param {import('express').Response} res + * @param {import('express').NextFunction} next + */ + commitHash(req, res, next) { + const hash = cp.execSync('git rev-parse HEAD').toString().trim(); + return res.status(200).json({ hash }) + } } \ No newline at end of file diff --git a/data.db b/data.db index 97fe14e1856d8e22cc50d570a25a59cca7226d12..1b85cb7b614eca155a8ae5c5dfe7c6d9d2d63467 100644 GIT binary patch delta 192 zcmZozz}T>Wae_4CiitALj4L)KER$!s!N7lGv!KFh{y+u>1~mq524Q(7Q6^DFPNop& z07D~lJp&*#Wc=pr?`x>qke8pA%EA1C7pRtx?-T?7TmB3DYxt+~H}U83NAkPy>+?(T zv+;f6yUTZqZ!6H)Nqq96qKu4!qQNe~F21ZDL2d!YMuL3o41yrRfG{Tc&DZU$7#UN5 jYCZWUNBeV%1C17!1WNK3r+}cmXHcl8p;^e}YX4RMVJRWae_2s_e2?I#_o*?%j8+^F!0~mEU0jte_{Z)ml6XvgRndkFOw)ECsT-X zfT5AOo&gXVGJaES$ji@5ssJLD6Cm5c3QQ^#p1a17aaTkZ?+h;^ymiR*Z~!K*gT?lcW7P c#eIRY3=ATo9D+cKR}{o4PAN{AT
- Devices: + Устройства: - No devices added. + Устройства не добавлены.
- +
- +
- +
*Адрес регистра:
*Тип регистра:
@@ -214,21 +214,21 @@
Edit + href="#">Редактировать - Delete + Удалить
@@ -241,16 +241,16 @@
Value: Значение: - Register: Format: Формат регистра: Register type: Тип регистра:

@@ -275,12 +275,12 @@ />
-

Loading...

+

Загрузка...

-

Display values

+

Мониторинг значений