/
usr
/
local
/
lib
/
python3.9
/
site-packages
/
agent360
/
plugins
/
/usr/local/lib/python3.9/site-packages/agent360/plugins
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
apt-updates.py
1260
0644
edit
dl
rm
asterisk.py
1012
0644
edit
dl
rm
bind.py
732
0644
edit
dl
rm
bird.py
841
0644
edit
dl
rm
bitninja.py
1302
0644
edit
dl
rm
cloudlinux-dbgov.py
1066
0644
edit
dl
rm
cloudlinux.py
1020
0644
edit
dl
rm
cpanel.py
1441
0644
edit
dl
rm
cpu.py
2020
0644
edit
dl
rm
cpu_freq.py
583
0644
edit
dl
rm
dirsize.py
617
0644
edit
dl
rm
diskinodes.py
652
0644
edit
dl
rm
diskstatus-nvme.py
1618
0644
edit
dl
rm
diskstatus.py
2005
0644
edit
dl
rm
diskusage.py
4140
0644
edit
dl
rm
docker.py
3442
0644
edit
dl
rm
dovecot.py
1304
0644
edit
dl
rm
elasticsearch.py
4342
0644
edit
dl
rm
exim.py
484
0644
edit
dl
rm
fail2ban.py
831
0644
edit
dl
rm
gpu.py
959
0644
edit
dl
rm
haproxy.py
4274
0644
edit
dl
rm
httpd.py
2800
0644
edit
dl
rm
iostat.py
5227
0644
edit
dl
rm
janus.py
705
0644
edit
dl
rm
kamailio.py
556
0644
edit
dl
rm
litespeed.py
3114
0644
edit
dl
rm
loadavg.py
332
0644
edit
dl
rm
loggedin.py
400
0644
edit
dl
rm
mailq.py
528
0644
edit
dl
rm
mdstat.py
1388
0644
edit
dl
rm
megacli.py
2787
0644
edit
dl
rm
memcached.py
3165
0644
edit
dl
rm
memory.py
932
0644
edit
dl
rm
minecraft.py
2410
0644
edit
dl
rm
mongodb.py
5766
0644
edit
dl
rm
mysql.py
5256
0644
edit
dl
rm
network.py
2786
0644
edit
dl
rm
nginx.py
3275
0644
edit
dl
rm
openvpn.py
2223
0644
edit
dl
rm
phpfpm.py
2781
0644
edit
dl
rm
ping.py
3165
0644
edit
dl
rm
plesk-cgroups.py
6330
0644
edit
dl
rm
plugins.py
2538
0644
edit
dl
rm
postfix.py
1774
0644
edit
dl
rm
powerdns.py
4669
0644
edit
dl
rm
process.py
4365
0644
edit
dl
rm
proftpd.py
1130
0644
edit
dl
rm
rabbitmq.py
3569
0644
edit
dl
rm
redis_stat.py
5615
0644
edit
dl
rm
sleeper.py
244
0644
edit
dl
rm
swap.py
364
0644
edit
dl
rm
system.py
5811
0644
edit
dl
rm
tcpports.py
1110
0644
edit
dl
rm
temp.py
1480
0644
edit
dl
rm
unbound.py
3316
0644
edit
dl
rm
vms.py
6352
0644
edit
dl
rm
wp-toolkit.py
1845
0644
edit
dl
rm
yum-updates.py
810
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/usr/local/lib/python3.9/site-packages/agent360/plugins/vms.py
(6352B)
from __future__ import print_function import re, sys, os import libvirt import libxml2 import time import plugins import psutil class Plugin(plugins.BasePlugin): __name__ = 'vms' def run(self, config): ''' Using the libvirt API to fetch statistics from guests running KVM, QEMU, Xen, Virtuozzo, VMWare ESX, LXC, BHyve and more ''' results = {} last_value = {} prev_cache = self.get_agent_cache() # Get absolute values from previous check uri = os.getenv("uri", "qemu:///system") values = self.fetch_values(uri) deltas = {} for key, value in values.items(): deltas[key] = {} for subkey, subvalue in value.items(): if subkey == 'mem_bytes' or subkey == 'soft_limit_bytes' or subkey == 'min_guarantee_bytes' or subkey == 'hard_limit_bytes': deltas[key][subkey] = value[subkey] else: deltas[key][subkey] = self.absolute_to_per_second('%s_%s' % (key, subkey), float(subvalue), prev_cache) last_value['%s_%s' % (key, subkey)] = float(value[subkey]) last_value['ts'] = time.time() self.set_agent_cache(last_value) return deltas def canon(self, name): return re.sub(r"[^a-zA-Z0-9_]", "_", name) def get_ifaces(self, dom): xml = dom.XMLDesc(0) doc = None try: doc = libxml2.parseDoc(xml) except: return [] ctx = doc.xpathNewContext() ifaces = [] try: ret = ctx.xpathEval("/domain/devices/interface") for node in ret: devdst = None for child in node.children: if child.name == "target": devdst = child.prop("dev") if devdst == None: continue ifaces.append(devdst) finally: if ctx != None: ctx.xpathFreeContext() if doc != None: doc.freeDoc() return ifaces def get_memtune(self, dom): memtune = { 'min_guarantee': 0, 'soft_limit': 0, 'hard_limit': 0 } xml = dom.XMLDesc(0) try: doc = libxml2.parseDoc(xml) except: return [] ctx = doc.xpathNewContext() try: for key in memtune: ret = ctx.xpathEval("/domain/memtune/%s" % key) try: for child in ret[0].children: memtune[key] = int(child.content) break except IndexError: # key not found in xml pass finally: if ctx != None: ctx.xpathFreeContext() if doc != None: doc.freeDoc() return memtune def fetch_values(self, uri): conn = libvirt.openReadOnly(uri) ids = conn.listDomainsID() results = {} for id in ids: data = {} data['net_rx_bytes'] = 0 data['net_tx_bytes'] = 0 try: dom = conn.lookupByID(id) name = dom.name() except libvirt.libvirtError as err: print("Id: %s: %s" % (id, err), file=sys.stderr) continue if name == "Domain-0": continue ifaces = self.get_ifaces(dom) for iface in ifaces: try: stats = dom.interfaceStats(iface) data['net_rx_bytes'] += stats[0] data['net_tx_bytes'] += stats[4] except: print >>sys.stderr, "Cannot get ifstats for '%s' on '%s'" % (iface, name) cputime = float(dom.info()[4]) cputime_percentage = 1.0e-7 * cputime data['cpu'] = cputime_percentage try: data['cpu_percentage'] = cputime_percentage / psutil.cpu_count() except Exception as e: pass maxmem, mem = dom.info()[1:3] mem *= 1024 maxmem *= 1024 data['mem_bytes'] = mem memtune = self.get_memtune(dom) data['min_guarantee_bytes'] = memtune['min_guarantee'] * 1024 data['hard_limit_bytes'] = memtune['hard_limit'] * 1024 data['soft_limit_bytes'] = memtune['soft_limit'] * 1024 data['disk_rd_bytes'] = 0 data['disk_wr_bytes'] = 0 data['disk_wr_req'] = 0 data['disk_rd_req'] = 0 try: dom = conn.lookupByID(id) name = dom.name() except libvirt.libvirtError as err: print("Id: %s: %s" % (id, err), file=sys.stderr) continue if name == "Domain-0": continue disks = self.get_disks(dom) for disk in disks: try: rd_req, rd_bytes, wr_req, wr_bytes, errs = dom.blockStats(disk) data['disk_rd_bytes'] += rd_bytes data['disk_wr_bytes'] += wr_bytes data['disk_rd_req'] += rd_req data['disk_wr_req'] += wr_req except TypeError: print >>sys.stderr, "Cannot get blockstats for '%s' on '%s'" % (disk, name) results[self.canon(name)] = data return results def get_disks(self, dom): xml = dom.XMLDesc(0) doc = None try: doc = libxml2.parseDoc(xml) except: return [] ctx = doc.xpathNewContext() disks = [] try: ret = ctx.xpathEval("/domain/devices/disk") for node in ret: devdst = None for child in node.children: if child.name == "target": devdst = child.prop("dev") if devdst == None: continue disks.append(devdst) finally: if ctx != None: ctx.xpathFreeContext() if doc != None: doc.freeDoc() return disks if __name__ == '__main__': Plugin().execute()
Save
cmd:
run