mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Show CPU and Memory usage
This commit is contained in:
committed by
Björn Dahlgren
parent
7b6d0c6425
commit
dddbb467f2
@ -1,10 +1,13 @@
|
||||
var _ = require('lodash')
|
||||
var events = require('events')
|
||||
var filesize = require('filesize')
|
||||
var Gamedig = require('gamedig')
|
||||
var usage = require('pidusage')
|
||||
var slugify = require('slugify')
|
||||
|
||||
var ArmaServer = require('arma-server')
|
||||
|
||||
var processesInterval = 2000
|
||||
var queryInterval = 5000
|
||||
var queryTypes = {
|
||||
arma1: 'arma',
|
||||
@ -66,6 +69,49 @@ Server.prototype.update = function (options) {
|
||||
this.port = parseInt(this.port, 10) // If port is a string then gamedig fails
|
||||
}
|
||||
|
||||
function processStats (stats) {
|
||||
return {
|
||||
cpu: stats.cpu,
|
||||
cpuFormatted: stats.cpu.toFixed(0) + ' %',
|
||||
memory: stats.memory,
|
||||
memoryFormatted: filesize(stats.memory)
|
||||
}
|
||||
}
|
||||
|
||||
Server.prototype.queryProcesses = function () {
|
||||
if (!this.instance) {
|
||||
return
|
||||
}
|
||||
|
||||
var self = this
|
||||
var headlessPids = this.headlessClientInstances.map(function (instance) {
|
||||
return instance.pid
|
||||
})
|
||||
var serverPid = self.instance.pid
|
||||
var pids = [serverPid].concat(headlessPids)
|
||||
usage(pids, function (err, stats) {
|
||||
if (!self.instance) {
|
||||
return
|
||||
}
|
||||
|
||||
if (err) {
|
||||
self.processes = null
|
||||
} else {
|
||||
self.processes = pids.map(function (pid, idx) {
|
||||
var pidStats = processStats(stats[pid])
|
||||
if (pid === serverPid) {
|
||||
pidStats.name = 'Server'
|
||||
} else {
|
||||
pidStats.name = 'Headless ' + idx // First headless at idx 1
|
||||
}
|
||||
return pidStats
|
||||
})
|
||||
}
|
||||
|
||||
self.emit('state')
|
||||
})
|
||||
}
|
||||
|
||||
Server.prototype.queryStatus = function () {
|
||||
if (!this.instance) {
|
||||
return
|
||||
@ -165,8 +211,10 @@ Server.prototype.start = function () {
|
||||
var self = this
|
||||
|
||||
instance.on('close', function (code) {
|
||||
clearInterval(self.queryProcessesInterval)
|
||||
clearInterval(self.queryStatusInterval)
|
||||
self.state = null
|
||||
self.processes = null
|
||||
self.pid = null
|
||||
self.instance = null
|
||||
|
||||
@ -178,6 +226,9 @@ Server.prototype.start = function () {
|
||||
this.pid = instance.pid
|
||||
this.instance = instance
|
||||
this.headlessClientInstances = []
|
||||
this.queryProcessesInterval = setInterval(function () {
|
||||
self.queryProcesses()
|
||||
}, processesInterval)
|
||||
this.queryStatusInterval = setInterval(function () {
|
||||
self.queryStatus()
|
||||
}, queryInterval)
|
||||
@ -274,6 +325,7 @@ Server.prototype.toJSON = function () {
|
||||
persistent: this.persistent,
|
||||
pid: this.pid,
|
||||
port: this.port,
|
||||
processes: this.processes,
|
||||
state: this.state,
|
||||
title: this.title,
|
||||
von: this.von,
|
||||
|
@ -38,6 +38,7 @@
|
||||
"lodash": "^4.17.10",
|
||||
"morgan": "^1.8.1",
|
||||
"multer": "^1.3.0",
|
||||
"pidusage": "2.0.17",
|
||||
"raw-loader": "^0.5.1",
|
||||
"serve-static": "^1.12.1",
|
||||
"slugify": "^1.1.0",
|
||||
|
@ -18,6 +18,7 @@ module.exports = Backbone.Model.extend({
|
||||
password: '',
|
||||
persistent: false,
|
||||
port: 2302,
|
||||
processes: null,
|
||||
state: null,
|
||||
title: '',
|
||||
von: false,
|
||||
|
@ -39,6 +39,36 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if (processes) { %>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">Processes</label>
|
||||
<div class="col-sm-11">
|
||||
<% processes.map(function (process) { %>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">Name</label>
|
||||
<div class="col-sm-11">
|
||||
<p class="form-control-static"><%= process.name %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">CPU</label>
|
||||
<div class="col-sm-11">
|
||||
<p class="form-control-static"><%= process.cpuFormatted %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">RAM</label>
|
||||
<div class="col-sm-11">
|
||||
<p class="form-control-static"><%= process.memoryFormatted %></p>
|
||||
</div>
|
||||
</div>
|
||||
<% }) %>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (state) { %>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-1 control-label">Name</label>
|
||||
|
@ -1,9 +1,12 @@
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">Status</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
<th>Port</th>
|
||||
<th>Title</th>
|
||||
<th>CPU</th>
|
||||
<th>RAM</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
@ -21,13 +21,21 @@
|
||||
<span class="glyphicon glyphicon-play"></span> Start
|
||||
</button>
|
||||
<% } %>
|
||||
|
||||
|
||||
</td>
|
||||
<td><%-port%></td>
|
||||
<td style="width: 100%;">
|
||||
<a href='#servers/<%-id%>'><%-title%></a>
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
<% if (processes && processes[0]) { %>
|
||||
<%= processes[0].cpuFormatted %>
|
||||
<% } %>
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
<% if (processes && processes[0]) { %>
|
||||
<%= processes[0].memoryFormatted %></td>
|
||||
<% } %>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-xs clone pull-right">
|
||||
<span class="glyphicon glyphicon-plus-sign"></span> Clone
|
||||
|
Reference in New Issue
Block a user