sflow / host-sflow

host-sflow agent
http://sflow.net
Other
154 stars 55 forks source link

KVM monitoring is not work on CentOS 7 #28

Closed MyungChi closed 6 years ago

MyungChi commented 6 years ago

Hi. I've install latest RPM((hsflowd-centos7-2.0.15-1.x86_64.rpm)) on CentOS 7 to monitor resource of Host and KVM.

When I start hsflowd with /usr/sbin/hslowd -dd I got below error.

libvirt: XML-RPC error : Cannot create user runtime directory '/run/user/0/libvirt': Permission denied virConnectOpenReadOnly() failed

Some body know reason why ? How to resolve this issue ?

sflow commented 6 years ago

Haven't seen this before. Please try running with "sudo /usr/sbin/hsflowd -dd -P" to retain root privileges, and let me know if that helps.

MyungChi commented 6 years ago

Thanks for your help. I execute with root.
If I execute "systemctl start hsflowd or /usr/sbin/hsflowd -dd" then owner of this process was nobody.

[root@R117 ~]# ps -eaf | grep hsflowd
nobody    2333  1680  1 06:43 pts/0    00:00:00 /usr/sbin/hsflowd -dd

As you guide, I execute "/usr/sbin/hsflowd -dd -P" then owner of this process is root.

[root@R117 ~]# ps -eaf | grep hsflowd
root      1871  1680  0 06:36 pts/0    00:00:00 /usr/sbin/hsflowd -dd -P

With root privideges, KVM monitoring is working. Maybe, I need to add -P option in start scripts(/usr/lib/systemd/system/hsflowd.service) to resolve this issue as below

ExecStart=/usr/sbin/hsflowd -m %m -dP

sflow commented 6 years ago

It sounds like mod_kvm.c should ask to retain root privileges. Just like mod_docker.c does here: https://github.com/sflow/host-sflow/blob/master/src/Linux/mod_docker.c#L1334

MyungChi commented 6 years ago

I want to get your help. After I get the Host and VM info. from host sflow, How can I calculate CPU time(ms) of VM to CPU utilization. Can U advise it ?

sflow commented 6 years ago

From the specs here: https://sflow.org/sflow_host.txt

You can see that in struct virt_cpu the cpuTime field is in mS. That counts the total mS used, so to get to utilization you have to calcuate:

∑delta(cpuTime) / delta(time)

So if over the course of 60 seconds you saw three readings of cpuTime like this:

10123 20123 30123

you would calculate ∑delta(cpuTime) = (20123 - 10123) + (30123 - 20123) = 20000mS and divide by 60000mS to come up with 33.3% VM CPU utilization.

Presentation examples can be found here: http://demo.inmon.com/inmsf/Hosts?action=stats&view=voverview

These free-to-play-with tools could be used for comparison: https://inmon.com/products/sFlowTrend.php https://inmon.com/products/sFlow-RT.php

And please note that once you have this working then the exact same sFlow structures are reported for Docker containers and Linux services when you load docker{} or systemd{} modules in hsflowd: https://blog.sflow.com/2016/09/asynchronous-docker-metrics.html https://blog.sflow.com/2016/12/monitoring-linux-services.html

MyungChi commented 6 years ago

Thanks a lot.