Skip to content

Commit 8fb43be

Browse files
committed
Show cpu usage for process and system
1 parent 2107580 commit 8fb43be

File tree

1 file changed

+65
-28
lines changed

1 file changed

+65
-28
lines changed

spring-boot-admin-server-ui/src/main/frontend/views/instances/details/details-process.vue

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@
4141
</p>
4242
</div>
4343
</div>
44-
<div class="level-item has-text-centered" v-if="cpuCount">
44+
<div class="level-item has-text-centered" v-if="processCpuLoad">
4545
<div>
46-
<p class="heading">CPUs</p>
47-
<p v-text="cpuCount"/>
46+
<p class="heading">Process CPU Usage</p>
47+
<p v-text="processCpuLoad.toFixed(2)"/>
4848
</div>
4949
</div>
50-
<div class="level-item has-text-centered" v-if="systemLoad">
50+
<div class="level-item has-text-centered" v-if="systemCpuLoad">
5151
<div>
52-
<p class="heading">System Load (last 1m)</p>
53-
<p v-text="systemLoad.toFixed(2)"/>
52+
<p class="heading">System CPU Usage</p>
53+
<p v-text="systemCpuLoad.toFixed(2)"/>
54+
</div>
55+
</div>
56+
<div class="level-item has-text-centered" v-if="systemCpuCount">
57+
<div>
58+
<p class="heading">CPUs</p>
59+
<p v-text="systemCpuCount"/>
5460
</div>
5561
</div>
5662
</div>
@@ -59,7 +65,9 @@
5965
</template>
6066

6167
<script>
68+
import subscribing from '@/mixins/subscribing';
6269
import Instance from '@/services/instance';
70+
import {Observable} from '@/utils/rxjs';
6371
import processUptime from './process-uptime';
6472
6573
export default {
@@ -69,20 +77,21 @@
6977
required: true
7078
}
7179
},
80+
mixins: [subscribing],
7281
components: {processUptime},
7382
data: () => ({
7483
hasLoaded: false,
7584
error: null,
7685
pid: null,
7786
uptime: null,
78-
systemLoad: null,
79-
cpuCount: null
87+
systemCpuLoad: null,
88+
processCpuLoad: null,
89+
systemCpuCount: null
8090
}),
8191
created() {
92+
this.fetchPid();
8293
this.fetchUptime();
8394
this.fetchCpuCount();
84-
this.fetchSystemLoad();
85-
this.fetchPid();
8695
},
8796
methods: {
8897
async fetchUptime() {
@@ -94,36 +103,64 @@
94103
}
95104
this.hasLoaded = true;
96105
},
97-
async fetchSystemLoad() {
98-
try {
99-
this.systemLoad = await this.fetchMetric('system.load.average.1m');
100-
} catch (error) {
101-
console.warn('Fetching System Load failed:', error);
106+
async fetchPid() {
107+
if (this.instance.hasEndpoint('env')) {
108+
try {
109+
const response = await this.instance.fetchEnv('PID');
110+
this.pid = response.data.property.value;
111+
} catch (error) {
112+
console.warn('Fetching PID failed:', error);
113+
}
114+
this.hasLoaded = true;
102115
}
103-
this.hasLoaded = true;
104116
},
105117
async fetchCpuCount() {
106118
try {
107-
this.cpuCount = await this.fetchMetric('system.cpu.count');
119+
this.systemCpuCount = await this.fetchMetric('system.cpu.count');
108120
} catch (error) {
109121
console.warn('Fetching Cpu Count failed:', error);
110122
}
111123
this.hasLoaded = true;
112124
},
125+
createSubscription() {
126+
const vm = this;
127+
return Observable.timer(0, 2500)
128+
.concatMap(this.fetchCpuLoadMetrics)
129+
.subscribe({
130+
next: data => {
131+
vm.processCpuLoad = data.processCpuLoad;
132+
vm.systemCpuLoad = data.systemCpuLoad;
133+
},
134+
error: error => {
135+
vm.hasLoaded = true;
136+
console.warn('Fetching CPU Usage metrics failed:', error);
137+
vm.error = error;
138+
}
139+
});
140+
},
141+
async fetchCpuLoadMetrics() {
142+
const fetchProcessCpuLoad = this.fetchMetric('process.cpu.usage');
143+
const fetchSystemCpuLoad = this.fetchMetric('system.cpu.usage');
144+
let processCpuLoad;
145+
let systemCpuLoad;
146+
try {
147+
processCpuLoad = await fetchProcessCpuLoad
148+
} catch (error) {
149+
console.warn('Fetching Process CPU Load failed:', error);
150+
}
151+
try {
152+
systemCpuLoad = await fetchSystemCpuLoad
153+
} catch (error) {
154+
console.warn('Fetching Sytem CPU Load failed:', error);
155+
}
156+
return {
157+
processCpuLoad,
158+
systemCpuLoad
159+
};
160+
},
113161
async fetchMetric(name) {
114162
const response = await this.instance.fetchMetric(name);
115163
return response.data.measurements[0].value;
116-
},
117-
async fetchPid() {
118-
if (this.instance.hasEndpoint('env')) {
119-
try {
120-
const response = await this.instance.fetchEnv('PID');
121-
this.pid = response.data.property.value;
122-
} catch (error) {
123-
console.warn('Fetching PID failed:', error);
124-
}
125-
this.hasLoaded = true;
126-
}
127164
}
128165
}
129166
}

0 commit comments

Comments
 (0)