Hello Piotr Kliczewski, Francesco Romani,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/59774
to review the following change.
Change subject: Adding report_stats to host.api
......................................................................
Adding report_stats to host.api
Adding functions that use reports.send function to report internal host info
Change-Id: Ie65c865669422b7652b028492b1380157fc5e177
Signed-off-by: Yaniv Bronhaim <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/58661
Continuous-Integration: Jenkins CI
Reviewed-by: Francesco Romani <[email protected]>
Reviewed-by: Piotr Kliczewski <[email protected]>
---
M lib/vdsm/host/api.py
M lib/vdsm/host/stats.py
M tests/hoststatsTests.py
3 files changed, 64 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/74/59774/1
diff --git a/lib/vdsm/host/api.py b/lib/vdsm/host/api.py
index c1e70f3..b93900b 100644
--- a/lib/vdsm/host/api.py
+++ b/lib/vdsm/host/api.py
@@ -22,10 +22,12 @@
import errno
import logging
import time
+from . import uuid
from . import stats
from vdsm import cpuarch
from vdsm import hooks
from vdsm import utils
+from vdsm import reports
from vdsm.config import config
from vdsm.define import Kbytes, Mbytes
from vdsm.virt import vmstatus
@@ -79,6 +81,62 @@
return ret
+def report_stats(hoststats):
+ prefix = "hosts." + uuid()
+ report = {}
+
+ try:
+ for dom in hoststats['storageDomains']:
+ storage_prefix = prefix + '.storage.' + dom
+ dom_info = hoststats['storageDomains'][dom]
+ report[storage_prefix + '.delay'] = dom_info['delay']
+ report[storage_prefix + '.last_check'] = dom_info['lastCheck']
+
+ report[prefix + '.memory.available'] = hoststats['memAvailable']
+ report[prefix + '.memory.committed'] = hoststats['memCommitted']
+ report[prefix + '.memory.free_mb'] = hoststats['memFree']
+ report[prefix + '.memory.usage_percent'] = hoststats['memUsed']
+ report[prefix + '.memory.anon_huge_pages'] = hoststats['anonHugePages']
+
+ report[prefix + '.swap.total_mb'] = hoststats['swapTotal']
+ report[prefix + '.swap.free_mb'] = hoststats['swapFree']
+
+ report[prefix + '.vms.active'] = hoststats['vmActive']
+ report[prefix + '.vms.total'] = hoststats['vmCount']
+
+ report[prefix + '.cpu.load'] = hoststats['cpuLoad']
+ report[prefix + '.cpu.user'] = hoststats['cpuUser']
+ report[prefix + '.cpu.sys'] = hoststats['cpuSys']
+ report[prefix + '.cpu.idle'] = hoststats['cpuIdle']
+ report[prefix + '.cpu.sys_vdsmd'] = hoststats['cpuSysVdsmd']
+ report[prefix + '.cpu.user_vdsmd'] = hoststats['cpuUserVdsmd']
+ report[prefix + '.cpu.ksm_pages'] = hoststats['ksmPages']
+ report[prefix + '.cpu.ksm_cpu_precent'] = hoststats['ksmCpu']
+
+ if hoststats['haStats']['configured']:
+ report[prefix + '.ha_score'] = hoststats['haScore']
+
+ report[prefix + '.elapsed_time'] = hoststats['elapsedTime']
+
+ if 'network' in hoststats:
+ for interface in hoststats['network']:
+ if_info = hoststats['network'][interface]
+ net_prefix = prefix + '.network_interfaces.' + interface
+ report[net_prefix + '.speed'] = if_info['speed']
+ report[net_prefix + '.rx_rate'] = if_info['rxRate']
+ report[net_prefix + '.tx_rate'] = if_info['txRate']
+ report[net_prefix + '.rx_errors'] = if_info['rxErrors']
+ report[net_prefix + '.tx_errors'] = if_info['txErrors']
+ report[net_prefix + '.rx_dropped'] = if_info['rxDropped']
+ report[net_prefix + '.tx_dropped'] = if_info['txDropped']
+ report[net_prefix + '.rx'] = if_info['rx']
+ report[net_prefix + '.tx'] = if_info['tx']
+
+ reports.send(report)
+ except KeyError:
+ logging.exception('Report host stats failed')
+
+
def _readSwapTotalFree():
meminfo = utils.readMemInfo()
return meminfo['SwapTotal'] / 1024, meminfo['SwapFree'] / 1024
diff --git a/lib/vdsm/host/stats.py b/lib/vdsm/host/stats.py
index 23ce688..63a3b43 100644
--- a/lib/vdsm/host/stats.py
+++ b/lib/vdsm/host/stats.py
@@ -231,6 +231,7 @@
def _empty_stats():
return {
+ 'cpuLoad': 0.0,
'cpuUser': 0.0,
'cpuSys': 0.0,
'cpuIdle': 100.0,
@@ -239,4 +240,6 @@
'cpuSysVdsmd': 0.0,
'cpuUserVdsmd': 0.0,
'elapsedTime': _elapsed_time(),
+ 'memUsed': 0.0,
+ 'anonHugePages': 0.0,
}
diff --git a/tests/hoststatsTests.py b/tests/hoststatsTests.py
index e40445f..04324c9 100644
--- a/tests/hoststatsTests.py
+++ b/tests/hoststatsTests.py
@@ -174,9 +174,12 @@
'cpuSysVdsmd': 0.0,
'cpuUser': 0.0,
'cpuUserVdsmd': 0.0,
+ 'memUsed': 0.0,
'rxRate': 0.0,
'txRate': 0.0,
'elapsedTime': 0,
+ 'anonHugePages': 0.0,
+ 'cpuLoad': 0.0,
}
hoststats.start(lambda: 0)
self.assertEquals(hoststats.produce(None, None), expected)
--
To view, visit https://gerrit.ovirt.org/59774
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie65c865669422b7652b028492b1380157fc5e177
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-4.0
Gerrit-Owner: Yaniv Bronhaim <[email protected]>
Gerrit-Reviewer: Francesco Romani <[email protected]>
Gerrit-Reviewer: Piotr Kliczewski <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]