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 @@ + + + + + + + + + + + + + + + + CPU {{ cpuP }}% + + + + + + + + + + + + + + + MEM {{ memP }}% + + + + + + + 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 @@ + + + + + CPU + {{ meta.cpu.cores }} Logical cores + {{ meta.cpu.model }} + + + + + + + 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 @@ + + + + + Disk + Total: {{ bytes(total, 1) }} + Free: {{ bytes(available, 1) }} + Used: {{ bytes(used, 1) }} + + + + + + + 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 @@ + + + {{ $ts._widgets.serverMetric }} + + + + + + + + + + + + + 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 @@ + + + + + RAM + Total: {{ bytes(total, 1) }} + Used: {{ bytes(used, 1) }} + Free: {{ bytes(free, 1) }} + + + + + + + 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 @@ + + + + + + + NET rx {{ bytes(inRecent) }} + + + + + + NET tx {{ bytes(outRecent) }} + + + + + + + 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 @@ + + + + + {{ (value * 100).toFixed(0) }}% + + + + + + 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, + }, + }; +});
CPU
{{ meta.cpu.cores }} Logical cores
{{ meta.cpu.model }}
Disk
Total: {{ bytes(total, 1) }}
Free: {{ bytes(available, 1) }}
Used: {{ bytes(used, 1) }}
RAM
Free: {{ bytes(free, 1) }}