Skip to content
Merged

Fixes #2729

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/helpermodules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def addChargeTemplate(self, connection_id: str, payload: dict) -> None:
new_charge_template = asdict(new_charge_template)
else:
new_charge_template = get_new_charge_template()
new_charge_template["id"] = new_id
new_charge_template["id"] = new_id

Pub().pub("openWB/set/command/max_id/charge_template", new_id)
Pub().pub(f"openWB/set/vehicle/template/charge_template/{new_id}", new_charge_template)
Expand Down Expand Up @@ -648,8 +648,9 @@ def addEvTemplate(self, connection_id: str, payload: dict) -> None:
else:
new_ev_template = dataclass_utils.asdict(EvTemplateData())
new_id = self.max_id_ev_template + 1
Pub().pub(f'openWB/set/vehicle/template/ev_template/{new_id}', new_ev_template)
new_ev_template["id"] = new_id
self.max_id_ev_template = new_id
Pub().pub(f'openWB/set/vehicle/template/ev_template/{new_id}', new_ev_template)
Pub().pub("openWB/set/command/max_id/ev_template", new_id)
pub_user_message(
payload, connection_id,
Expand Down
20 changes: 19 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class UpdateConfig:

DATASTORE_VERSION = 95
DATASTORE_VERSION = 96

valid_topic = [
"^openWB/bat/config/bat_control_permitted$",
Expand Down Expand Up @@ -2535,3 +2535,21 @@ def upgrade(topic, payload):
return {topic: payload, "openWB/command/max_id/charge_template_scheduled_plan": max_id}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 95)

def upgrade_datastore_95(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
# Fix id in charge and ev templates
if (
re.search("openWB/vehicle/template/charge_template/[0-9]+$", topic) is not None
or re.search("openWB/vehicle/template/ev_template/[0-9]+$", topic) is not None
):
payload = decode_payload(payload)
topic_index = int(get_index(topic))
if "id" not in payload or payload["id"] != topic_index:
log.error(
f"Fixing id in template {topic} from {payload.get('id')} to {topic_index}"
)
payload["id"] = topic_index
return {topic: payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 96)
26 changes: 21 additions & 5 deletions web/maintenance/systeminfo_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,15 @@ function getServiceStatus($services)
return $result;
}

function getTopCpuProcesses($limit)
function getTopProcesses($order, $limit)
{
// ps gibt: PID, Benutzer, CPU-Auslastung, Speicher, Befehl
$cmd = "ps -eo pid,user,%cpu,%mem,comm --sort=-%cpu | head -n " . ($limit + 1);
$data = ['comm', 'pid', '%cpu', '%mem'];
$index = array_search($order, $data);
if ($index === false) {
return [];
}
$cmd = "ps -eo " . join(',', $data) . " --sort=-" . $order . " | head -n " . ($limit + 1);
$output = [];
exec($cmd, $output);

Expand All @@ -324,16 +329,26 @@ function getTopCpuProcesses($limit)
for ($i = 1; $i < count($output); $i++) {
// Spalten trennen (mehrere Leerzeichen)
$cols = preg_split('/\s+/', trim($output[$i]), 5);
if (count($cols) === 5) {
$result[$cols[4] . ' (' . $cols[0] . ')'] = [
'value' => (float)$cols[2],
if (count($cols) === 4) {
$result[$cols[0] . ' (' . $cols[1] . ')'] = [
'value' => (float)$cols[$index],
'unit' => '%'
];
}
}
return $result;
}

function getTopCpuProcesses($limit)
{
return getTopProcesses('%cpu', $limit);
}

function getTopMemoryProcesses($limit)
{
return getTopProcesses('%mem', $limit);
}

// API-Handler
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
header('Content-Type: application/json');
Expand Down Expand Up @@ -382,6 +397,7 @@ function getTopCpuProcesses($limit)
'cpuLoad' => getCpuLoad(),
'memory' => getMemoryUsage(),
'top10CpuProcesses' => getTopCpuProcesses($numTopProcesses),
'top10MemoryProcesses' => getTopMemoryProcesses($numTopProcesses),
'services' => getServiceStatus($serviceList),
'storage (root)' => getPartitionUsage('/', 'root'),
'storage (boot)' => getPartitionUsage('/boot', 'boot'),
Expand Down