Moved CPU percentage on the level of the CPU entity instead of a child entity.

This commit is contained in:
Fabio Manganiello 2023-04-19 01:48:05 +02:00
parent 4ebfbf3851
commit 153d03d43f
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 50 additions and 6 deletions

View file

@ -0,0 +1,46 @@
<template>
<div class="entity cpu-container">
<div class="head">
<div class="col-1 icon">
<EntityIcon
:entity="value"
:loading="loading"
:error="error" />
</div>
<div class="col-9 label">
<div class="name" v-text="value.name" />
</div>
<div class="col-2 value" v-text="Math.round(value.percent * 100, 1) + '%'" />
</div>
</div>
</template>
<script>
import EntityMixin from "./EntityMixin"
import EntityIcon from "./EntityIcon"
export default {
name: 'Cpu',
components: {EntityIcon},
mixins: [EntityMixin],
}
</script>
<style lang="scss" scoped>
@import "common";
.cpu-container {
.head {
.value {
text-align: right;
font-weight: bold;
}
}
.icon {
margin-right: 1em;
}
}
</style>

View file

@ -135,6 +135,7 @@ export default {
.value { .value {
text-align: right; text-align: right;
font-weight: bold;
} }
} }
} }

View file

@ -18,6 +18,8 @@ if 'cpu' not in Base.metadata:
Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True Integer, ForeignKey(Entity.id, ondelete='CASCADE'), primary_key=True
) )
percent = Column(Float)
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': __tablename__, 'polymorphic_identity': __tablename__,
} }

View file

@ -807,6 +807,7 @@ class SystemPlugin(SensorPlugin, EntityManager):
Cpu( Cpu(
id='system:cpu', id='system:cpu',
name='CPU', name='CPU',
percent=cpu['percent'],
children=[ children=[
CpuInfoModel( CpuInfoModel(
id='system:cpu:info', id='system:cpu:info',
@ -857,11 +858,6 @@ class SystemPlugin(SensorPlugin, EntityManager):
max=cpu['frequency']['max'], max=cpu['frequency']['max'],
unit='MHz', unit='MHz',
), ),
PercentSensor(
id='system:cpu:percent',
name='Percent',
value=cpu['percent'],
),
], ],
), ),
MemoryStatsModel( MemoryStatsModel(