-
Notifications
You must be signed in to change notification settings - Fork 0
/
statware.js
66 lines (57 loc) · 1.64 KB
/
statware.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
module.exports = statware
var Stats = require("./stats")
var os = require("os")
function statware(initial) {
var stats = new Stats(initial)
stats.installSystemInfo = function () {
var sumSpeed = function (p, c) {
return p + c.speed
}
stats.registerHelper(function (status, next) {
var sys = status.system_info
if (sys == null) {
sys = {}
}
sys.freemem = os.freemem()
sys.totalmem = os.totalmem()
sys.arch = process.arch
sys.platform = process.platform
sys.uptime = os.uptime()
var load = os.loadavg()
sys.loadavg = {}
sys.loadavg["1m"] = load[0]
sys.loadavg["5m"] = load[1]
sys.loadavg["15m"] = load[2]
var cpuinfo = os.cpus()
sys.cores = cpuinfo.length
sys.cpu_model = cpuinfo[0].model
sys.cpu_speed = cpuinfo.reduce(sumSpeed, 0) / cpuinfo.length
sys.hostname = os.hostname()
status.system_info = sys
next()
})
return stats
}
stats.installProcessInfo = function () {
stats.registerHelper(function (status, next) {
var proc = status.process_info
if (proc == null) {
proc = {}
}
proc.uptime = process.uptime()
proc.memory = process.memoryUsage()
proc.active_requests = process._getActiveRequests().length
proc.active_handles = process._getActiveHandles().length
proc.versions = process.versions
proc.node_env = process.env.NODE_ENV || ""
proc.pid = process.pid
proc.title = process.title
proc.user = process.env.USER
status.process_info = proc
next()
})
return stats
}
return stats
}