2018-06-03 00:41:06 +00:00
|
|
|
<template>
|
|
|
|
<div class="server-box animate fadein">
|
2018-06-11 19:06:12 +00:00
|
|
|
<router-link :to="{ name: 'server', params: { serverID: server.identifier }}" class="content">
|
2018-06-03 00:41:06 +00:00
|
|
|
<div class="float-right">
|
2018-06-03 02:08:53 +00:00
|
|
|
<div class="indicator" :class="status"></div>
|
2018-06-03 00:41:06 +00:00
|
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
|
|
<div class="text-black font-bold text-xl">
|
|
|
|
{{ server.name }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="mb-0 flex">
|
|
|
|
<div class="usage">
|
|
|
|
<div class="indicator-title">{{ $t('dashboard.index.cpu_title') }}</div>
|
|
|
|
</div>
|
|
|
|
<div class="usage">
|
|
|
|
<div class="indicator-title">{{ $t('dashboard.index.memory_title') }}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="mb-4 flex text-center">
|
|
|
|
<div class="inline-block border border-grey-lighter border-l-0 p-4 flex-1">
|
2018-06-03 02:08:53 +00:00
|
|
|
<span class="font-bold text-xl">{{ cpu > 0 ? cpu : '—' }}</span>
|
2018-06-03 00:41:06 +00:00
|
|
|
<span class="font-light text-sm">%</span>
|
|
|
|
</div>
|
|
|
|
<div class="inline-block border border-grey-lighter border-l-0 border-r-0 p-4 flex-1">
|
2018-06-03 02:08:53 +00:00
|
|
|
<span class="font-bold text-xl">{{ memory > 0 ? memory : '—' }}</span>
|
2018-06-03 05:23:54 +00:00
|
|
|
<span class="font-light text-sm">MB</span>
|
2018-06-03 00:41:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="text-sm">
|
|
|
|
<p class="text-grey">{{ server.node }}</p>
|
|
|
|
<p class="text-grey-dark">{{ server.allocation.ip }}:{{ server.allocation.port }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-06-03 02:08:53 +00:00
|
|
|
import get from 'lodash/get';
|
2018-06-03 00:41:06 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'server-box',
|
|
|
|
props: {
|
2018-06-03 02:08:53 +00:00
|
|
|
server: { type: Object, required: true },
|
|
|
|
},
|
|
|
|
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
resources: undefined,
|
|
|
|
cpu: 0,
|
|
|
|
memory: 0,
|
|
|
|
status: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
created: function () {
|
|
|
|
window.events.$on(`server:${this.server.uuid}::resources`, data => {
|
|
|
|
this.resources = data;
|
|
|
|
this.status = this.getServerStatus();
|
|
|
|
|
|
|
|
this.memory = Number(get(data, 'memory.current', 0)).toFixed(0);
|
|
|
|
this.cpu = this._calculateCpu(
|
|
|
|
Number(get(data, 'cpu.current', 0)),
|
|
|
|
Number(this.server.limits.cpu)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Set the CSS to use for displaying the server's current status.
|
|
|
|
*/
|
|
|
|
getServerStatus: function () {
|
|
|
|
if (!(this.resources instanceof Object)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.resources.installed || this.resources.suspended) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (this.resources.state) {
|
|
|
|
case 'off':
|
|
|
|
return 'offline';
|
|
|
|
case 'on':
|
|
|
|
case 'starting':
|
|
|
|
case 'stopping':
|
|
|
|
return 'online';
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the CPU usage for a given server relative to their set maximum.
|
|
|
|
*
|
|
|
|
* @param {Number} current
|
|
|
|
* @param {Number} max
|
|
|
|
* @return {Number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_calculateCpu: function (current, max) {
|
|
|
|
if (max === 0) {
|
|
|
|
return parseFloat(current.toFixed(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseFloat((current / max * 100).toFixed(1));
|
|
|
|
}
|
2018-06-03 00:41:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|