mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-21 23:32:59 +00:00
disk report "used" instead of "free"
This commit is contained in:
parent
06f8ba1316
commit
a9cf044fe1
2 changed files with 14 additions and 12 deletions
|
@ -8,17 +8,17 @@ def disk() -> Report | None:
|
||||||
if not SETTINGS.disk.enabled:
|
if not SETTINGS.disk.enabled:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def path_to_free_percent(path: os.PathLike) -> float:
|
def path_to_used_percent(path: os.PathLike) -> float:
|
||||||
try:
|
try:
|
||||||
sv = os.statvfs(path)
|
sv = os.statvfs(path)
|
||||||
return sv.f_bavail / sv.f_blocks * 100
|
return (1 - sv.f_bavail / sv.f_blocks) * 100
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
data = sorted([
|
data = sorted([
|
||||||
(str(path), path_to_free_percent(path))
|
(str(path), path_to_used_percent(path))
|
||||||
for path in SETTINGS.disk.paths
|
for path in SETTINGS.disk.paths
|
||||||
], key=lambda d: d[1])
|
], key=lambda d: d[1], reverse=True)
|
||||||
|
|
||||||
reports = [Report.new(
|
reports = [Report.new(
|
||||||
settings=SETTINGS.disk,
|
settings=SETTINGS.disk,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import math
|
import math
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from pydantic import BaseModel, DirectoryPath, Field
|
from pydantic import BaseModel, DirectoryPath, Field
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
@ -26,18 +27,19 @@ class CpuMS(MetricSettings):
|
||||||
threshold: float = math.inf
|
threshold: float = math.inf
|
||||||
|
|
||||||
|
|
||||||
class MemoryMS(MetricSettings):
|
class MultiMS(MetricSettings):
|
||||||
|
# outer format string for reporting
|
||||||
|
report_outer: str = "{name}: [{inner}]"
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryMS(MultiMS):
|
||||||
name: str = "Memory"
|
name: str = "Memory"
|
||||||
threshold: float = 90
|
threshold: float = 90
|
||||||
|
|
||||||
|
|
||||||
class DiskMS(MetricSettings):
|
class DiskMS(MultiMS):
|
||||||
name: str = "Disk Free"
|
name: str = "Disk Used"
|
||||||
threshold: float = 15
|
threshold: float = 85
|
||||||
inverted: bool = True
|
|
||||||
|
|
||||||
# outer format string for reporting
|
|
||||||
report_outer: str = "{name}: [{inner}]"
|
|
||||||
|
|
||||||
# paths to check for disk space
|
# paths to check for disk space
|
||||||
paths: list[DirectoryPath] = Field(default_factory=list)
|
paths: list[DirectoryPath] = Field(default_factory=list)
|
||||||
|
|
Loading…
Reference in a new issue