mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
在首页上实时 CPU 和内存占用
This commit is contained in:
@@ -12,6 +12,8 @@ ITEM_IN_RESOURCES_LIST = 3600 * 1000 / config.plugins.linux.monitor_cycle
|
||||
last_plist = []
|
||||
passwd_cache = {}
|
||||
|
||||
exports.resources_usage = {}
|
||||
|
||||
exports.run = ->
|
||||
exports.monitoring()
|
||||
setInterval exports.monitoring, config.plugins.linux.monitor_cycle
|
||||
@@ -107,7 +109,9 @@ exports.monitoring = ->
|
||||
addAccountUsage account_name, 'memory', memory_usage
|
||||
|
||||
for account_name, usage of account_usage
|
||||
usage.memory = usage.memory / (resources_usage_list.length * config.plugins.linux.monitor_cycle * 1000)
|
||||
usage.memory = usage.memory / resources_usage_list.length / config.plugins.linux.monitor_cycle * 1000
|
||||
|
||||
exports.resources_usage = account_usage
|
||||
|
||||
app.redis.setex REDIS_OVERVIEW, 60, JSON.stringify(account_usage), ->
|
||||
async.each _.keys(account_usage), (account_name, callback) ->
|
||||
@@ -147,7 +151,7 @@ exports.monitoringCpu = (plist, callback) ->
|
||||
|
||||
for item in exist_process
|
||||
last_process = findLastProcess item
|
||||
addTime item.user, last_process.time - item.time
|
||||
addTime item.user, item.time - last_process.time
|
||||
|
||||
for item in new_process
|
||||
addTime item.user, item.time
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
jade = require 'jade'
|
||||
path = require 'path'
|
||||
monitor = require './monitor'
|
||||
|
||||
module.exports =
|
||||
enable: (account, callback) ->
|
||||
@@ -9,7 +10,11 @@ module.exports =
|
||||
callback()
|
||||
|
||||
widget: (account, callback) ->
|
||||
jade.renderFile path.join(__dirname, 'view/widget.jade'), {}, (err, html) ->
|
||||
jade.renderFile path.join(__dirname, 'view/widget.jade'),
|
||||
account: account
|
||||
resources_usage: monitor.resources_usage[account.username] ? {cpu: 0, memory: 0}
|
||||
, (err, html) ->
|
||||
throw err if err
|
||||
callback html
|
||||
|
||||
preview: (callback) ->
|
||||
|
||||
@@ -5,19 +5,23 @@ table.table.table-hover
|
||||
td(style='width: 200px;') 一小时 CPU 时间
|
||||
td
|
||||
.progress
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='20', aria-valuemin='0', aria-valuemax='100', style='width: 20%;') 58 / 144 s
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='#{(resources_usage.cpu / account.attribute.resources_limit.cpu * 100).toFixed()}', aria-valuemin='0', aria-valuemax='100', style='width: #{(resources_usage.cpu / account.attribute.resources_limit.cpu * 100).toFixed()}%;')
|
||||
span #{resources_usage.cpu.toFixed(1)} / #{account.attribute.resources_limit.cpu} s
|
||||
tr
|
||||
td 一小时内存占用
|
||||
td
|
||||
.progress
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='85', aria-valuemin='0', aria-valuemax='100', style='width: 85%;') 23 / 27 M
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='#{(resources_usage.memory / account.attribute.resources_limit.memory * 100).toFixed()}', aria-valuemin='0', aria-valuemax='100', style='min-width: 30px; width: #{(resources_usage.memory / account.attribute.resources_limit.memory * 100).toFixed()}%;')
|
||||
span #{resources_usage.memory.toFixed(1)} / #{account.attribute.resources_limit.memory} M
|
||||
tr
|
||||
td 储存空间
|
||||
td
|
||||
.progress
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='10', aria-valuemin='0', aria-valuemax='100', style='width: 10%;') 52 / 520 M
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='0', aria-valuemin='0', aria-valuemax='100', style='width: 0%;')
|
||||
span 0 / #{account.attribute.resources_limit.storage} M
|
||||
tr
|
||||
td 月流量
|
||||
td
|
||||
.progress
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='10', aria-valuemin='0', aria-valuemax='100', style='width: 10%;') 4 / 39G
|
||||
.progress-bar.progress-bar-success(role='progressbar', aria-valuenow='0', aria-valuemin='0', aria-valuemax='100', style='width: 0%;')
|
||||
span 0 / #{account.attribute.resources_limit.transfer} G
|
||||
|
||||
Reference in New Issue
Block a user