mirror of https://github.com/nicolargo/glances.git
_api_get_extended_processes is called several time per second. Should be corrected.
This commit is contained in:
parent
1345bc24d5
commit
e1dcfc38c5
|
|
@ -239,6 +239,7 @@ class GlancesRestfulApi:
|
|||
f'{base_path}/all/views': self._api_all_views,
|
||||
f'{base_path}/pluginslist': self._api_plugins,
|
||||
f'{base_path}/serverslist': self._api_servers_list,
|
||||
f'{base_path}/processes/extended': self._api_get_extended_processes,
|
||||
f'{base_path}/processes/{{pid}}': self._api_get_processes,
|
||||
f'{plugin_path}': self._api,
|
||||
f'{plugin_path}/history': self._api_history,
|
||||
|
|
@ -923,6 +924,23 @@ class GlancesRestfulApi:
|
|||
|
||||
return GlancesJSONResponse(True)
|
||||
|
||||
def _api_get_extended_processes(self):
|
||||
"""Glances API RESTful implementation.
|
||||
|
||||
Get the extended process stats (if set before)
|
||||
HTTP/200 if OK
|
||||
HTTP/400 if PID is not found
|
||||
HTTP/404 if others error
|
||||
"""
|
||||
process_stats = glances_processes.get_extended_stats()
|
||||
|
||||
if not process_stats:
|
||||
process_stats = {}
|
||||
|
||||
print("Call _api_get_extended_processes")
|
||||
|
||||
return GlancesJSONResponse(process_stats)
|
||||
|
||||
def _api_get_processes(self, pid: str):
|
||||
"""Glances API RESTful implementation.
|
||||
|
||||
|
|
|
|||
|
|
@ -398,6 +398,11 @@ body {
|
|||
.table {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.table-hover tbody tr:hover td {
|
||||
background: $glances-link-hover-color;
|
||||
}
|
||||
|
||||
// Default column size
|
||||
* > td:nth-child(-n+12) {
|
||||
width: 5em;
|
||||
|
|
@ -427,6 +432,7 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#alerts {
|
||||
span {
|
||||
padding-left: 10px;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
<!-- Display processes -->
|
||||
<section class="plugin" id="processlist" v-if="!args.programs">
|
||||
<div>PIN PROCESS: {{ extended_stat }} - {{ getPinProcess() }}</div>
|
||||
<div class="table-responsive d-lg-none">
|
||||
<table class="table table-sm table-borderless table-striped table-hover">
|
||||
<thead>
|
||||
|
|
@ -31,7 +32,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(process, processId) in processes" :key="processId">
|
||||
<tr v-for="(process, processId) in processes" :key="processId" @click="setPinProcess(process)"
|
||||
style="cursor: pointer">
|
||||
<td scope="row" :class="getCpuPercentAlert(process)"
|
||||
v-show="!getDisableStats().includes('cpu_percent')">
|
||||
{{ process.cpu_percent == -1 ? '?' : $filters.number(process.cpu_percent, 1) }}
|
||||
|
|
@ -114,7 +116,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(process, processId) in processes" :key="processId">
|
||||
<tr v-for="(process, processId) in processes" :key="processId" @click="setPinProcess(process.pid)"
|
||||
style="cursor: pointer">
|
||||
<td scope="row" :class="getCpuPercentAlert(process)"
|
||||
v-show="!getDisableStats().includes('cpu_percent')">
|
||||
{{ process.cpu_percent == -1 ? '?' : $filters.number(process.cpu_percent, 1) }}
|
||||
|
|
@ -354,9 +357,20 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
store
|
||||
store,
|
||||
extended_stat: undefined,
|
||||
intervalId: null
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
// Refresh every second
|
||||
this.intervalId = setInterval(() => {
|
||||
this.getPinProcess()
|
||||
}, 1000)
|
||||
},
|
||||
beforeUnmount() {
|
||||
clearInterval(this.intervalId)
|
||||
},
|
||||
computed: {
|
||||
args() {
|
||||
return this.store.args || {};
|
||||
|
|
@ -527,7 +541,7 @@ export default {
|
|||
return this.config.outputs !== undefined
|
||||
? this.config.outputs.max_processes_display
|
||||
: undefined;
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getCpuPercentAlert(process) {
|
||||
|
|
@ -538,6 +552,15 @@ export default {
|
|||
},
|
||||
getDisableStats() {
|
||||
return GlancesHelper.getLimit('processlist', 'processlist_disable_stats') || [];
|
||||
},
|
||||
setPinProcess(pid) {
|
||||
fetch('api/4/processes/extended/' + pid.toString(), { method: 'POST' })
|
||||
.then((response) => response.json());
|
||||
},
|
||||
getPinProcess() {
|
||||
fetch('api/4/processes/extended', { method: 'GET' })
|
||||
.then((response) => response.json())
|
||||
.then((response) => (this.extended_stat = response));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -312,8 +312,8 @@ class GlancesProcesses:
|
|||
for k in self._max_values_list:
|
||||
self._max_values[k] = 0.0
|
||||
|
||||
def get_extended_stats(self, proc):
|
||||
"""Get the extended stats for the given PID."""
|
||||
def set_extended_stats(self, proc):
|
||||
"""Set the extended stats for the given PID."""
|
||||
# - cpu_affinity (Linux, Windows, FreeBSD)
|
||||
# - ionice (Linux and Windows > Vista)
|
||||
# - num_ctx_switches (not available on Illumos/Solaris)
|
||||
|
|
@ -359,6 +359,16 @@ class GlancesProcesses:
|
|||
ret['extended_stats'] = True
|
||||
return namedtuple_to_dict(ret)
|
||||
|
||||
def get_extended_stats(self):
|
||||
"""Return the extended stats.
|
||||
|
||||
Return the process stat when extended_stats = True
|
||||
"""
|
||||
for p in self.processlist:
|
||||
if p.get('extended_stats'):
|
||||
return p
|
||||
return None
|
||||
|
||||
def __get_min_max_mean(self, proc, prefix=['cpu', 'memory']):
|
||||
"""Return the min/max/mean for the given process"""
|
||||
ret = {}
|
||||
|
|
@ -587,7 +597,7 @@ class GlancesProcesses:
|
|||
|
||||
# Grab extended stats only for the selected process (see issue #2225)
|
||||
if self.extended_process is not None and proc['pid'] == self.extended_process['pid']:
|
||||
proc.update(self.get_extended_stats(self.extended_process))
|
||||
proc.update(self.set_extended_stats(self.extended_process))
|
||||
self.extended_process = namedtuple_to_dict(proc)
|
||||
|
||||
# Meta data
|
||||
|
|
|
|||
Loading…
Reference in New Issue