Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiskIO values as extra attributes in Disk Entity #87

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
86 changes: 84 additions & 2 deletions IoTuring/Entity/Deployments/Disk/Disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:\\",
Expand All @@ -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:
Expand Down Expand Up @@ -103,6 +121,66 @@ def Update(self) -> None:
attributeKey=EXTRA_KEY_DISK_FREE,
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 OsD.IsLinux():
devname = self.disk_partition.device.split("/")[-1]
disk_io = psutil.disk_io_counters(perdisk=True)[devname]

lockenkop marked this conversation as resolved.
Show resolved Hide resolved
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():
lockenkop marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -115,11 +193,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