mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-24 08:23:01 +00:00
control logging to stdout
This commit is contained in:
parent
8f6a7a37fd
commit
af9d3eb502
4 changed files with 20 additions and 2 deletions
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -11,6 +11,7 @@
|
||||||
"module": "kiwi_simple_metrics.main",
|
"module": "kiwi_simple_metrics.main",
|
||||||
"env": {
|
"env": {
|
||||||
"METRIC__INTERVAL": "5",
|
"METRIC__INTERVAL": "5",
|
||||||
|
"METRIC__QUIET": "False",
|
||||||
"METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
|
"METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
|
||||||
},
|
},
|
||||||
"justMyCode": true
|
"justMyCode": true
|
||||||
|
|
|
@ -10,11 +10,14 @@ async def run_metrics() -> None:
|
||||||
while True:
|
while True:
|
||||||
interval = asyncio.sleep(SETTINGS.interval)
|
interval = asyncio.sleep(SETTINGS.interval)
|
||||||
|
|
||||||
print(metrics.Report.concat(
|
report = metrics.Report.concat(
|
||||||
metrics.cpu(),
|
metrics.cpu(),
|
||||||
metrics.memory(),
|
metrics.memory(),
|
||||||
metrics.disk(),
|
metrics.disk(),
|
||||||
))
|
)
|
||||||
|
|
||||||
|
if not SETTINGS.quiet:
|
||||||
|
print(report)
|
||||||
|
|
||||||
await interval
|
await interval
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,14 @@ class Report:
|
||||||
result: str
|
result: str
|
||||||
failed: bool = False
|
failed: bool = False
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
state = "OK" if not self.failed else "FAIL"
|
||||||
|
|
||||||
|
return SETTINGS.report_stdout.format(
|
||||||
|
state=state,
|
||||||
|
result=self.result,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def concat(cls, *_reports: Any) -> Self:
|
def concat(cls, *_reports: Any) -> Self:
|
||||||
reports = [
|
reports = [
|
||||||
|
|
|
@ -91,6 +91,12 @@ class Settings(BaseSettings):
|
||||||
# time between gathering reports
|
# time between gathering reports
|
||||||
interval: float = 600
|
interval: float = 600
|
||||||
|
|
||||||
|
# if False, prints reports to stdout
|
||||||
|
quiet: bool = True
|
||||||
|
|
||||||
|
# how to format reports to stdout
|
||||||
|
report_stdout: str = "[{state}] {result}"
|
||||||
|
|
||||||
# separates metrics and values in reports
|
# separates metrics and values in reports
|
||||||
separator: str = ", "
|
separator: str = ", "
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue