Skip to content

Commit

Permalink
work on metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Koos85 committed Jun 10, 2024
1 parent fc1c144 commit c6e01cf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
17 changes: 2 additions & 15 deletions lib/check/guests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,8 @@ async def check_guests(

guests = [{
'name': str(d['vmid']), # str
'status': d['status'], # ???
'vmid': d['vmid'], # ???
'cpu': d.get('cpu'), # ???
'cpus': d.get('cpus'), # ???
'disk': d.get('disk'), # ???
'diskread': d.get('diskread'), # ???
'diskwrite': d.get('diskwrite'), # ???
'maxdisk': d.get('maxdisk'), # ???
'maxmem': d.get('maxmem'), # ???
'mem': d.get('mem'), # ???
'netin': d.get('netin'), # ???
'netout': d.get('netout'), # ???
'pid': d.get('pid'), # ???
'uptime': d.get('uptime'), # ???
'vmname': d.get('name'), # ???
'status': d['status'], # str
'vm_name': d.get('name'), # str
} for d in data['data']]
return {
'guests': guests
Expand Down
33 changes: 17 additions & 16 deletions lib/check/network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import aiohttp
from typing import Optional
from libprobe.asset import Asset
from libprobe.exceptions import CheckException
from ..utils import to_bool


DEFAULT_PORT = 8006
Expand Down Expand Up @@ -37,22 +39,21 @@ async def check_network(

network = [{
'name': d['iface'], # str
'active': d.get('active'), # ???, optional
'address': d.get('address'), # str, optional
'autostart': d.get('autostart'), # ???, optional
'bridge_fd': d.get('bridge_fd'), # ???, optional
'bridge_ports': d.get('bridge_ports'), # ???, optional
'bridge_stp': d.get('bridge_stp'), # ???, optional
'cdir': d.get('cdir'), # ???, optional
'exists': d.get('exists'), # ???, optional
'families': d.get('families'), # ???
'gateway': d.get('gateway'), # ???, optional
'method': d.get('method'), # ???
'method6': d.get('method6'), # ???
'netmask': d.get('netmask'), # ??? optional
'priority': d.get('priority'), # ???
'type': d.get('type'), # ???

'active': d.get('active'), # int/optional
'address': d.get('address'), # str/optional
'autostart': to_bool(d.get('autostart')), # int/optional
'bridge_fd': d.get('bridge_fd'), # str/optional
'bridge_ports': d.get('bridge_ports'), # str/ optional
'bridge_stp': d.get('bridge_stp'), # str/optional
'cdir': d.get('cdir'), # str/optional
'exists': to_bool(d.get('exists')), # int/optional
'families': d.get('families'), # liststr/optional
'gateway': d.get('gateway'), # str/optional
'method': d.get('method'), # str
'method6': d.get('method6'), # str
'netmask': d.get('netmask'), # str/optional
'priority': d.get('priority'), # int
'type': d.get('type'), # str
} for d in data['data']]
return {
'network': network
Expand Down
22 changes: 11 additions & 11 deletions lib/check/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import aiohttp
from libprobe.asset import Asset
from libprobe.exceptions import CheckException
from ..utils import to_bool, to_list_str


DEFAULT_PORT = 8006
Expand Down Expand Up @@ -36,17 +37,16 @@ async def check_storage(
data = await resp.json()

storage = [{
'name': d['storage'], # ???
'content': d['content'], # ???
'type': d['type'], # ???
'active': d.get('active'), # ???
'avail': d.get('avail'), # ???
'enabled': d.get('enabled'), # ???
# 'format': d.get('format'), # ???
'shared': d.get('shared'), # ???
'total': d.get('total'), # ???
'used': d.get('used'), # ???
'used_fraction': d.get('used_fraction'), # ???
'name': d['storage'], # str
'content': to_list_str(d['content']), # liststr
'type': d['type'], # str
'active': to_bool(d.get('active')), # bool
'avail': d.get('avail'), # int
'enabled': to_bool(d.get('enabled')), # bool
'shared': to_bool(d.get('shared')), # bool
'total': d.get('total'), # int
'used': d.get('used'), # int
'used_fraction': d.get('used_fraction'), # int
} for d in data['data']]
return {
'storage': storage
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Optional, List


def to_bool(val: Optional[int]) -> bool:
if val is None:
return
return bool(val)


def to_list_str(val: Optional[str]) -> List[str]:
if val is None or not isinstance(val, str):
return
return val.split(',')

0 comments on commit c6e01cf

Please sign in to comment.