From 677074d0f0ca89bf2cb404c7b27649f36b6947a3 Mon Sep 17 00:00:00 2001 From: Jonas Fenchel Date: Mon, 11 Dec 2023 00:03:49 +0100 Subject: [PATCH 1/5] firt mock for smart values in disk --- IoTuring/Entity/Deployments/Disk/Disk.py | 88 +++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/IoTuring/Entity/Deployments/Disk/Disk.py b/IoTuring/Entity/Deployments/Disk/Disk.py index 594027d9a..37a55ee7b 100644 --- a/IoTuring/Entity/Deployments/Disk/Disk.py +++ b/IoTuring/Entity/Deployments/Disk/Disk.py @@ -8,16 +8,33 @@ KEY_USED_PERCENTAGE = "space_used_percentage" CONFIG_KEY_DU_PATH = "path" +CONFIG_KEY_DISKIO = "IO" + EXTRA_KEY_DISK_MOUNTPOINT = "Mountpoint" EXTRA_KEY_DISK_FSTYPE = "Filesystem" EXTRA_KEY_DISK_DEVICE = "Device" EXTRA_KEY_DISK_TOTAL = "Total" EXTRA_KEY_DISK_USED = "Used" EXTRA_KEY_DISK_FREE = "Free" +EXTRA_KEY_DISK_READ_COUNT = "Read count" +EXTRA_KEY_DISK_WRITE_COUNT = "write count" +EXTRA_KEY_DISK_READ_BYTES = "Read bytes" +EXTRA_KEY_DISK_WRITE_BYTES = "Write bytes" +EXTRA_KEY_DISK_READ_TIME = "Read time" +EXTRA_KEY_DISK_WRTIE_TIME = "Write time" +EXTRA_KEY_DISK_READ_MERGED_COUNT = "Read merged count" +EXTRA_KEY_DISK_WRITE_MERGED_COUNT = "Write merged count" +EXTRA_KEY_DISK_BUSY_TIME = "Busy time" + VALUEFORMATOPTIONS_DISK_GB = ValueFormatterOptions( ValueFormatterOptions.TYPE_BYTE, 0, "GB") +VALUEFORMATOPTIONS_DISK_B = ValueFormatterOptions( + ValueFormatterOptions.TYPE_BYTE, 0, "B") + +VALUEFORMATOPTIONS_TIME = ValueFormatterOptions( + ValueFormatterOptions.TYPE_TIME, 0, "ms") DEFAULT_PATH = { OsD.WINDOWS: "C:\\", @@ -41,9 +58,10 @@ def Initialize(self) -> None: """ self.configuredPath = self.GetFromConfigurations(CONFIG_KEY_DU_PATH) + self.configuredIo = self.GetFromConfigurations(CONFIG_KEY_DISKIO) try: - # Get partision info for extra attributes: + # Get partition info for extra attributes: self.disk_partition = next( (d for d in psutil.disk_partitions() if d.mountpoint == self.configuredPath)) except StopIteration: @@ -103,6 +121,68 @@ def Update(self) -> None: attributeKey=EXTRA_KEY_DISK_FREE, attributeValue=usage.free, valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) + + if OsD.IsLinux(): + # because of this reverse parsing to get the devicename from the partition name, all the following is only linux having the partition named nvme* or sd* + if self.configuredIo: + devname = self.disk_partition.device.split("/", 2) + if "nvme" in self.disk_partition.device: + disk_io = psutil.disk_io_counters(perdisk=True)[devname[2][:-2]] + elif "sd" in self.disk_partition.device: + disk_io = psutil.disk_io_counters(perdisk=True)[devname[2][:-1]] + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_COUNT, + attributeValue=disk_io.read_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_COUNT, + attributeValue=disk_io.write_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_BYTES, + attributeValue=disk_io.read_bytes, + valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_BYTES, + attributeValue=disk_io.write_bytes, + valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_TIME, + attributeValue=disk_io.read_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRTIE_TIME, + attributeValue=disk_io.write_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + + # the following are only supported in linux + if OsD.IsLinux(): + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_MERGED_COUNT, + attributeValue=disk_io.read_merged_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_MERGED_COUNT, + attributeValue=disk_io.write_merged_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_BUSY_TIME, + attributeValue=disk_io.busy_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + @classmethod def ConfigurationPreset(cls) -> MenuPreset: @@ -115,11 +195,15 @@ def ConfigurationPreset(cls) -> MenuPreset: {"name": DISK_CHOICE_STRING[OsD.GetOs()].format( disk.device, disk.mountpoint), - "value": disk.mountpoint} + "value": disk.mountpoint, + } ) preset = MenuPreset() preset.AddEntry(name="Drive to check", key=CONFIG_KEY_DU_PATH, mandatory=False, question_type="select", choices=DISK_CHOICES) + preset.AddEntry(name="Update DiskIO", + key=CONFIG_KEY_DISKIO, mandatory=False, + question_type="yesno") return preset From 2640453339b68029e68f345772ae10d5a758d4d5 Mon Sep 17 00:00:00 2001 From: lockenkop <96825051+lockenkop@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:36:38 +0100 Subject: [PATCH 2/5] fix write count typo Co-authored-by: infeeeee --- IoTuring/Entity/Deployments/Disk/Disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IoTuring/Entity/Deployments/Disk/Disk.py b/IoTuring/Entity/Deployments/Disk/Disk.py index 37a55ee7b..25cf358ce 100644 --- a/IoTuring/Entity/Deployments/Disk/Disk.py +++ b/IoTuring/Entity/Deployments/Disk/Disk.py @@ -17,7 +17,7 @@ EXTRA_KEY_DISK_USED = "Used" EXTRA_KEY_DISK_FREE = "Free" EXTRA_KEY_DISK_READ_COUNT = "Read count" -EXTRA_KEY_DISK_WRITE_COUNT = "write count" +EXTRA_KEY_DISK_WRITE_COUNT = "Write count" EXTRA_KEY_DISK_READ_BYTES = "Read bytes" EXTRA_KEY_DISK_WRITE_BYTES = "Write bytes" EXTRA_KEY_DISK_READ_TIME = "Read time" From 6ae4979d0df1c36b0b13a23b6f32c3c03affbab7 Mon Sep 17 00:00:00 2001 From: Jonas Fenchel Date: Tue, 12 Dec 2023 11:52:00 +0100 Subject: [PATCH 3/5] have linux use partitionnames as devnames --- IoTuring/Entity/Deployments/Disk/Disk.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/IoTuring/Entity/Deployments/Disk/Disk.py b/IoTuring/Entity/Deployments/Disk/Disk.py index 25cf358ce..db6f92090 100644 --- a/IoTuring/Entity/Deployments/Disk/Disk.py +++ b/IoTuring/Entity/Deployments/Disk/Disk.py @@ -122,14 +122,12 @@ def Update(self) -> None: attributeValue=usage.free, valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) - if OsD.IsLinux(): + if self.configuredIo: # because of this reverse parsing to get the devicename from the partition name, all the following is only linux having the partition named nvme* or sd* - if self.configuredIo: - devname = self.disk_partition.device.split("/", 2) - if "nvme" in self.disk_partition.device: - disk_io = psutil.disk_io_counters(perdisk=True)[devname[2][:-2]] - elif "sd" in self.disk_partition.device: - disk_io = psutil.disk_io_counters(perdisk=True)[devname[2][:-1]] + + if OsD.IsLinux(): + devname = self.disk_partition.device.split("/")[-1] + disk_io = psutil.disk_io_counters(perdisk=True)[devname] self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, From 940d7666ce27b002a3a5dc3cfb87b18a3070d3ce Mon Sep 17 00:00:00 2001 From: Jonas Fenchel Date: Tue, 12 Dec 2023 12:20:01 +0000 Subject: [PATCH 4/5] ensure only linux does diskio --- IoTuring/Entity/Deployments/Disk/Disk.py | 121 +++++++++++------------ 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/IoTuring/Entity/Deployments/Disk/Disk.py b/IoTuring/Entity/Deployments/Disk/Disk.py index db6f92090..7b5b25ca2 100644 --- a/IoTuring/Entity/Deployments/Disk/Disk.py +++ b/IoTuring/Entity/Deployments/Disk/Disk.py @@ -122,65 +122,63 @@ def Update(self) -> None: attributeValue=usage.free, valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) - if self.configuredIo: - # because of this reverse parsing to get the devicename from the partition name, all the following is only linux having the partition named nvme* or sd* + if self.configuredIo and OsD.IsLinux(): + # the following are supported on nearly every OS, Windows drivenames/devnames are complicated, so no Windows support - if OsD.IsLinux(): - devname = self.disk_partition.device.split("/")[-1] - disk_io = psutil.disk_io_counters(perdisk=True)[devname] - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_READ_COUNT, - attributeValue=disk_io.read_count) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_WRITE_COUNT, - attributeValue=disk_io.write_count) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_READ_BYTES, - attributeValue=disk_io.read_bytes, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_WRITE_BYTES, - attributeValue=disk_io.write_bytes, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_READ_TIME, - attributeValue=disk_io.read_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_WRTIE_TIME, - attributeValue=disk_io.write_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - - # the following are only supported in linux - if OsD.IsLinux(): - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_READ_MERGED_COUNT, - attributeValue=disk_io.read_merged_count) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_WRITE_MERGED_COUNT, - attributeValue=disk_io.write_merged_count) - - self.SetEntitySensorExtraAttribute( - sensorDataKey=KEY_USED_PERCENTAGE, - attributeKey=EXTRA_KEY_DISK_BUSY_TIME, - attributeValue=disk_io.busy_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - + devname = self.disk_partition.device.split("/")[-1] + disk_io = psutil.disk_io_counters(perdisk=True)[devname] + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_COUNT, + attributeValue=disk_io.read_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_COUNT, + attributeValue=disk_io.write_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_BYTES, + attributeValue=disk_io.read_bytes, + valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_BYTES, + attributeValue=disk_io.write_bytes, + valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_TIME, + attributeValue=disk_io.read_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRTIE_TIME, + attributeValue=disk_io.write_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + + # the following are only supported in linux + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_MERGED_COUNT, + attributeValue=disk_io.read_merged_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_MERGED_COUNT, + attributeValue=disk_io.write_merged_count) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_BUSY_TIME, + attributeValue=disk_io.busy_time, + valueFormatterOptions=VALUEFORMATOPTIONS_TIME) + @classmethod def ConfigurationPreset(cls) -> MenuPreset: @@ -201,7 +199,8 @@ def ConfigurationPreset(cls) -> MenuPreset: preset.AddEntry(name="Drive to check", key=CONFIG_KEY_DU_PATH, mandatory=False, question_type="select", choices=DISK_CHOICES) - preset.AddEntry(name="Update DiskIO", - key=CONFIG_KEY_DISKIO, mandatory=False, - question_type="yesno") + if OsD.IsLinux(): + preset.AddEntry(name="Update DiskIO", + key=CONFIG_KEY_DISKIO, mandatory=False, + question_type="yesno") return preset From 259fa005f4353f49bc2e3e1aeec4fccdd1aff423 Mon Sep 17 00:00:00 2001 From: Jonas Fenchel Date: Sun, 30 Jun 2024 21:06:15 +0200 Subject: [PATCH 5/5] Valueformatteroptions, formatting, calculate red/write-rates --- IoTuring/Entity/Deployments/Disk/Disk.py | 178 +++++++++++++++-------- 1 file changed, 120 insertions(+), 58 deletions(-) diff --git a/IoTuring/Entity/Deployments/Disk/Disk.py b/IoTuring/Entity/Deployments/Disk/Disk.py index 7b5b25ca2..52e24027b 100644 --- a/IoTuring/Entity/Deployments/Disk/Disk.py +++ b/IoTuring/Entity/Deployments/Disk/Disk.py @@ -1,4 +1,6 @@ import psutil +from time import time + from IoTuring.Entity.Entity import Entity from IoTuring.Entity.EntityData import EntitySensor from IoTuring.Configurator.MenuPreset import MenuPreset @@ -22,30 +24,35 @@ EXTRA_KEY_DISK_WRITE_BYTES = "Write bytes" EXTRA_KEY_DISK_READ_TIME = "Read time" EXTRA_KEY_DISK_WRTIE_TIME = "Write time" +EXTRA_KEY_DISK_READ_RATE = "Read rate" +EXTRA_KEY_DISK_WRITE_RATE = "Write rate" EXTRA_KEY_DISK_READ_MERGED_COUNT = "Read merged count" EXTRA_KEY_DISK_WRITE_MERGED_COUNT = "Write merged count" EXTRA_KEY_DISK_BUSY_TIME = "Busy time" -VALUEFORMATOPTIONS_DISK_GB = ValueFormatterOptions( - ValueFormatterOptions.TYPE_BYTE, 0, "GB") +VALUEFORMATOPTIONS_GB = ValueFormatterOptions(ValueFormatterOptions.TYPE_BYTE, 0, "GB") -VALUEFORMATOPTIONS_DISK_B = ValueFormatterOptions( - ValueFormatterOptions.TYPE_BYTE, 0, "B") +VALUEFORMATOPTIONS_B = ValueFormatterOptions(ValueFormatterOptions.TYPE_BYTE, 0, "B") VALUEFORMATOPTIONS_TIME = ValueFormatterOptions( - ValueFormatterOptions.TYPE_TIME, 0, "ms") + ValueFormatterOptions.TYPE_TIME, 0, "ms" +) -DEFAULT_PATH = { - OsD.WINDOWS: "C:\\", - OsD.MACOS: "/", - OsD.LINUX: "/" -} +VALUEFORMATOPTIONS_PERCENT = ValueFormatterOptions( + ValueFormatterOptions.TYPE_PERCENTAGE, 1, "%" +) + +VALUEFORMATOPTIONS_BpS = ValueFormatterOptions( + ValueFormatterOptions.TYPE_BYTE_PER_SECOND, 0, "B/s" +) + +DEFAULT_PATH = {OsD.WINDOWS: "C:\\", OsD.MACOS: "/", OsD.LINUX: "/"} DISK_CHOICE_STRING = { OsD.WINDOWS: "Drive with Driveletter {}", OsD.MACOS: "{}, mounted in {}", - OsD.LINUX: "{}, mounted in {}" + OsD.LINUX: "{}, mounted in {}", } @@ -54,16 +61,21 @@ class Disk(Entity): ALLOW_MULTI_INSTANCE = True def Initialize(self) -> None: - """Initialise the DiskUsage Entity and Register it - """ + """Initialise the DiskUsage Entity and Register it""" self.configuredPath = self.GetFromConfigurations(CONFIG_KEY_DU_PATH) self.configuredIo = self.GetFromConfigurations(CONFIG_KEY_DISKIO) + self.lastUpdate = "" try: # Get partition info for extra attributes: self.disk_partition = next( - (d for d in psutil.disk_partitions() if d.mountpoint == self.configuredPath)) + ( + d + for d in psutil.disk_partitions() + if d.mountpoint == self.configuredPath + ) + ) except StopIteration: raise Exception(f"Device not found: {self.configuredPath}") @@ -74,133 +86,183 @@ def Initialize(self) -> None: supportsExtraAttributes=True, valueFormatterOptions=ValueFormatterOptions( ValueFormatterOptions.TYPE_PERCENTAGE - ) + ), ) ) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_MOUNTPOINT, - attributeValue=self.disk_partition.mountpoint) + attributeValue=self.disk_partition.mountpoint, + ) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_FSTYPE, - attributeValue=self.disk_partition.fstype) + attributeValue=self.disk_partition.fstype, + ) if not OsD.IsWindows(): self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_DEVICE, - attributeValue=self.disk_partition.device) + attributeValue=self.disk_partition.device, + ) def Update(self) -> None: - """UpdateMethod, psutil does not need separate behaviour on any os - """ + """UpdateMethod, psutil does not need separate behaviour on any os""" usage = psutil.disk_usage(self.configuredPath) - self.SetEntitySensorValue( - key=KEY_USED_PERCENTAGE, - value=usage.percent) + self.SetEntitySensorValue(key=KEY_USED_PERCENTAGE, value=usage.percent) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_TOTAL, attributeValue=usage.total, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) + valueFormatterOptions=VALUEFORMATOPTIONS_GB, + ) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_USED, attributeValue=usage.used, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) + valueFormatterOptions=VALUEFORMATOPTIONS_GB, + ) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_FREE, attributeValue=usage.free, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_GB) - + valueFormatterOptions=VALUEFORMATOPTIONS_GB, + ) + if self.configuredIo and OsD.IsLinux(): # the following are supported on nearly every OS, Windows drivenames/devnames are complicated, so no Windows support - + devname = self.disk_partition.device.split("/")[-1] - disk_io = psutil.disk_io_counters(perdisk=True)[devname] + disk_io: psutil._common.sdiskio = psutil.disk_io_counters(perdisk=True)[ + devname + ] + currentTime = time() + if self.lastUpdate: + timeSinceLastUpdate = currentTime - self.lastUpdate + readrate = ( + disk_io.read_bytes - self.lastReadBytes + ) / timeSinceLastUpdate + writerate = ( + disk_io.write_bytes - self.lastWriteBytes + ) / timeSinceLastUpdate + else: + readrate = 0 + writerate = 0 self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_READ_COUNT, - attributeValue=disk_io.read_count) - + attributeValue=disk_io.read_count, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_WRITE_COUNT, - attributeValue=disk_io.write_count) + attributeValue=disk_io.write_count, + ) self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_READ_BYTES, attributeValue=disk_io.read_bytes, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) - + valueFormatterOptions=VALUEFORMATOPTIONS_B, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_WRITE_BYTES, attributeValue=disk_io.write_bytes, - valueFormatterOptions=VALUEFORMATOPTIONS_DISK_B) - + valueFormatterOptions=VALUEFORMATOPTIONS_B, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_READ_TIME, attributeValue=disk_io.read_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - + valueFormatterOptions=VALUEFORMATOPTIONS_TIME, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_WRTIE_TIME, attributeValue=disk_io.write_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - + valueFormatterOptions=VALUEFORMATOPTIONS_TIME, + ) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_READ_RATE, + attributeValue=readrate, + valueFormatterOptions=VALUEFORMATOPTIONS_BpS, + ) + + self.SetEntitySensorExtraAttribute( + sensorDataKey=KEY_USED_PERCENTAGE, + attributeKey=EXTRA_KEY_DISK_WRITE_RATE, + attributeValue=writerate, + valueFormatterOptions=VALUEFORMATOPTIONS_BpS, + ) + # the following are only supported in linux self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_READ_MERGED_COUNT, - attributeValue=disk_io.read_merged_count) - + attributeValue=disk_io.read_merged_count, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_WRITE_MERGED_COUNT, - attributeValue=disk_io.write_merged_count) - + attributeValue=disk_io.write_merged_count, + ) + self.SetEntitySensorExtraAttribute( sensorDataKey=KEY_USED_PERCENTAGE, attributeKey=EXTRA_KEY_DISK_BUSY_TIME, attributeValue=disk_io.busy_time, - valueFormatterOptions=VALUEFORMATOPTIONS_TIME) - + valueFormatterOptions=VALUEFORMATOPTIONS_TIME, + ) + + self.lastUpdate = time() + self.lastReadBytes = disk_io.read_bytes + self.lastWriteBytes = disk_io.write_bytes @classmethod def ConfigurationPreset(cls) -> MenuPreset: - # Get the choices for menu: DISK_CHOICES = [] for disk in psutil.disk_partitions(): DISK_CHOICES.append( - {"name": - DISK_CHOICE_STRING[OsD.GetOs()].format( - disk.device, disk.mountpoint), - "value": disk.mountpoint, - } + { + "name": DISK_CHOICE_STRING[OsD.GetOs()].format( + disk.device, disk.mountpoint + ), + "value": disk.mountpoint, + } ) preset = MenuPreset() - preset.AddEntry(name="Drive to check", - key=CONFIG_KEY_DU_PATH, mandatory=False, - question_type="select", choices=DISK_CHOICES) + preset.AddEntry( + name="Drive to check", + key=CONFIG_KEY_DU_PATH, + mandatory=True, + question_type="select", + choices=DISK_CHOICES, + ) if OsD.IsLinux(): - preset.AddEntry(name="Update DiskIO", - key=CONFIG_KEY_DISKIO, mandatory=False, - question_type="yesno") + preset.AddEntry( + name="Update DiskIO", + key=CONFIG_KEY_DISKIO, + mandatory=True, + question_type="yesno", + ) return preset