From c6fe79809286ca4a886a2a8e01efb4201bb5a2c1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 3 Jan 2021 22:38:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E3=83=BC=E6=83=85?= =?UTF-8?q?=E5=A0=B1=E3=82=A6=E3=82=A3=E3=82=B8=E3=82=A7=E3=83=83=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 1 + src/client/components/drive.file.vue | 2 +- src/client/widgets/index.ts | 2 + src/client/widgets/server-metric/cpu-mem.vue | 174 +++++++++++++++++++ src/client/widgets/server-metric/cpu.vue | 78 +++++++++ src/client/widgets/server-metric/disk.vue | 72 ++++++++ src/client/widgets/server-metric/index.vue | 84 +++++++++ src/client/widgets/server-metric/mem.vue | 87 ++++++++++ src/client/widgets/server-metric/net.vue | 148 ++++++++++++++++ src/client/widgets/server-metric/pie.vue | 65 +++++++ src/daemons/server-stats.ts | 17 +- src/server/api/endpoints/server-info.ts | 35 ++++ 12 files changed, 757 insertions(+), 8 deletions(-) create mode 100644 src/client/widgets/server-metric/cpu-mem.vue create mode 100644 src/client/widgets/server-metric/cpu.vue create mode 100644 src/client/widgets/server-metric/disk.vue create mode 100644 src/client/widgets/server-metric/index.vue create mode 100644 src/client/widgets/server-metric/mem.vue create mode 100644 src/client/widgets/server-metric/net.vue create mode 100644 src/client/widgets/server-metric/pie.vue create mode 100644 src/server/api/endpoints/server-info.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 9135cfda8..51f8672ba 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1030,6 +1030,7 @@ _widgets: slideshow: "スライドショー" button: "ボタン" onlineUsers: "オンラインユーザー" + serverMetric: "サーバーメトリクス" _cw: hide: "隠す" diff --git a/src/client/components/drive.file.vue b/src/client/components/drive.file.vue index ddee81261..d2b8b95f7 100644 --- a/src/client/components/drive.file.vue +++ b/src/client/components/drive.file.vue @@ -36,7 +36,7 @@ import { faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons'; import { faDownload, faLink, faICursor, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import copyToClipboard from '@/scripts/copy-to-clipboard'; import MkDriveFileThumbnail from './drive-file-thumbnail.vue'; -import bytes from '../filters/bytes'; +import bytes from '@/filters/bytes'; import * as os from '@/os'; export default defineComponent({ diff --git a/src/client/widgets/index.ts b/src/client/widgets/index.ts index 2c99a7307..8e9232cd9 100644 --- a/src/client/widgets/index.ts +++ b/src/client/widgets/index.ts @@ -14,6 +14,7 @@ export default function(app: App) { app.component('MkwFederation', defineAsyncComponent(() => import('./federation.vue'))); app.component('MkwPostForm', defineAsyncComponent(() => import('./post-form.vue'))); app.component('MkwSlideshow', defineAsyncComponent(() => import('./slideshow.vue'))); + app.component('MkwServerMetric', defineAsyncComponent(() => import('./server-metric/index.vue'))); app.component('MkwOnlineUsers', defineAsyncComponent(() => import('./online-users.vue'))); app.component('MkwButton', defineAsyncComponent(() => import('./button.vue'))); } @@ -32,6 +33,7 @@ export const widgets = [ 'federation', 'postForm', 'slideshow', + 'serverMetric', 'onlineUsers', 'button', ]; diff --git a/src/client/widgets/server-metric/cpu-mem.vue b/src/client/widgets/server-metric/cpu-mem.vue new file mode 100644 index 000000000..f1c31d7cd --- /dev/null +++ b/src/client/widgets/server-metric/cpu-mem.vue @@ -0,0 +1,174 @@ + + + + + diff --git a/src/client/widgets/server-metric/cpu.vue b/src/client/widgets/server-metric/cpu.vue new file mode 100644 index 000000000..f1574522c --- /dev/null +++ b/src/client/widgets/server-metric/cpu.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/client/widgets/server-metric/disk.vue b/src/client/widgets/server-metric/disk.vue new file mode 100644 index 000000000..41f967d29 --- /dev/null +++ b/src/client/widgets/server-metric/disk.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/client/widgets/server-metric/index.vue b/src/client/widgets/server-metric/index.vue new file mode 100644 index 000000000..2ce87ba41 --- /dev/null +++ b/src/client/widgets/server-metric/index.vue @@ -0,0 +1,84 @@ + + + diff --git a/src/client/widgets/server-metric/mem.vue b/src/client/widgets/server-metric/mem.vue new file mode 100644 index 000000000..eab23c1be --- /dev/null +++ b/src/client/widgets/server-metric/mem.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/src/client/widgets/server-metric/net.vue b/src/client/widgets/server-metric/net.vue new file mode 100644 index 000000000..23c148eeb --- /dev/null +++ b/src/client/widgets/server-metric/net.vue @@ -0,0 +1,148 @@ + + + + + diff --git a/src/client/widgets/server-metric/pie.vue b/src/client/widgets/server-metric/pie.vue new file mode 100644 index 000000000..38dcf6fcd --- /dev/null +++ b/src/client/widgets/server-metric/pie.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index 88df421ba..57691fbc0 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -6,6 +6,9 @@ const ev = new Xev(); const interval = 2000; +const roundCpu = (num: number) => Math.round(num * 1000) / 1000; +const round = (num: number) => Math.round(num * 10) / 10; + /** * Report server stats regularly */ @@ -23,18 +26,18 @@ export default function() { const fsStats = await fs(); const stats = { - cpu: cpu, + cpu: roundCpu(cpu), mem: { - used: memStats.used, - active: memStats.active, + used: round(memStats.used), + active: round(memStats.active), }, net: { - rx: Math.max(0, netStats.rx_sec), - tx: Math.max(0, netStats.tx_sec), + rx: round(Math.max(0, netStats.rx_sec)), + tx: round(Math.max(0, netStats.tx_sec)), }, fs: { - r: Math.max(0, fsStats.rIO_sec), - w: Math.max(0, fsStats.wIO_sec), + r: round(Math.max(0, fsStats.rIO_sec)), + w: round(Math.max(0, fsStats.wIO_sec)), } }; ev.emit('serverStats', stats); diff --git a/src/server/api/endpoints/server-info.ts b/src/server/api/endpoints/server-info.ts new file mode 100644 index 000000000..4e636d331 --- /dev/null +++ b/src/server/api/endpoints/server-info.ts @@ -0,0 +1,35 @@ +import * as os from 'os'; +import * as si from 'systeminformation'; +import define from '../define'; + +export const meta = { + requireCredential: false as const, + + desc: { + }, + + tags: ['meta'], + + params: { + }, +}; + +export default define(meta, async () => { + const memStats = await si.mem(); + const fsStats = await si.fsSize(); + + return { + machine: os.hostname(), + cpu: { + model: os.cpus()[0].model, + cores: os.cpus().length + }, + mem: { + total: memStats.total + }, + fs: { + total: fsStats[0].size, + used: fsStats[0].used, + }, + }; +});