def generate_packet(SERVICEHOSTNAME, resaultdic): packet = [] for key in resaultdic.keys(): packet.append( ZabbixMetric(SERVICEHOSTNAME, "epmmm.mysql.%s" % key, str(resaultdic[key] if resaultdic[key] != '' else 0))) return packet
def generate_packet(hostname): packet = [] try: client = Client((serviceip, serviceport)) memstatsdict = client.stats() for memstats in memstatsdict: #print(memstats) #print(memstatsdict[memstats]) packet.append( ZabbixMetric(hostname, "memcached_stats[%s]" % memstats.decode(), memstatsdict[memstats])) packet.append( ZabbixMetric(hostname, "memcached_stats[%s]" % 'status', 1)) except Exception as e: print(e) packet.append( ZabbixMetric(hostname, "memcached_stats[%s]" % 'status', 0)) #print(packet) return packet
def generate_packet(hostname): packet = [] cmd = 'top -n 2 -d 10' child = pexpect.spawn(cmd, timeout=10, encoding='utf-8', env={"TERM": "dumb"}) child.send('2') time.sleep(1) info = child.read() #logger.info('%s!', info) child.close() a = info.split('\n') for line in a: if (line.find("%Node") == 0): newline = re.split(r':|,', strip_ansi(line)) #logger.info('%s!', newline) cpunode = newline[0].strip().strip('%') packet.append( ZabbixMetric(hostname, "cpu.numa.us.[%s]" % cpunode, newline[1].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.sy.[%s]" % cpunode, newline[2].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.ni.[%s]" % cpunode, newline[3].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.id.[%s]" % cpunode, newline[4].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.wa.[%s]" % cpunode, newline[5].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.hi.[%s]" % cpunode, newline[6].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.si.[%s]" % cpunode, newline[7].strip().split()[0])) packet.append( ZabbixMetric(hostname, "cpu.numa.st.[%s]" % cpunode, newline[8].strip().split()[0])) #logger.info('%s!', packet) return packet
def generate_sar_packet(hostname): global packet diskinfodict = {} args = 'sar -d -p 3 1' infolist = Popen(args, stdout=PIPE, shell=True).stdout.read().decode() for info in infolist.split('\n'): if (info.startswith('Average')): if (info.split()[1].startswith('sd') or info.split()[1].startswith('md') or info.split()[1].startswith('nvme')): diskinfodict[info.split()[1]] = info.split()[2:] for disk in diskinfodict: packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.tps[%s]" % disk, diskinfodict[disk][0])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.rd_sec[%s]" % disk, diskinfodict[disk][1])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.wr_sec[%s]" % disk, diskinfodict[disk][2])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.avgrq-sz[%s]" % disk, diskinfodict[disk][3])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.avgqu-sz[%s]" % disk, diskinfodict[disk][4])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.await[%s]" % disk, diskinfodict[disk][5])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.svctm[%s]" % disk, diskinfodict[disk][6])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.sar-d-p.util[%s]" % disk, diskinfodict[disk][7]))
def generate_packet(hostname): args='iostat -y -x 2 1' infolist=Popen(args, stdout=PIPE, shell=True).stdout.read().decode() diskinfodict={} for info in infolist.split('\n'): if (info.startswith('sd') or info.startswith('md')): diskinfodict[info.split()[0]] = info.split()[1:] packet = [] for disk in diskinfodict: packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.rrqm[%s]" % disk,diskinfodict[disk][0])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.wrqm[%s]" % disk,diskinfodict[disk][1])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.r[%s]" % disk,diskinfodict[disk][2])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.w[%s]" % disk,diskinfodict[disk][3])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.rsec[%s]" % disk,diskinfodict[disk][4])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.wsec[%s]" % disk,diskinfodict[disk][5])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.avgrq-sz[%s]" % disk,diskinfodict[disk][6])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.avgqu-sz[%s]" % disk,diskinfodict[disk][7])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.await[%s]" % disk,diskinfodict[disk][8])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.r_await[%s]" % disk,diskinfodict[disk][9])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.w_await[%s]" % disk,diskinfodict[disk][10])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.svctm[%s]" % disk,diskinfodict[disk][11])) packet.append(ZabbixMetric(hostname, "custom.vfs.dev.iostat.util[%s]" % disk,diskinfodict[disk][12])) return packet
def generate_devstat_packet(hostname): global packet args = "find /sys/class/block/*/stat -type f -print |xargs awk '{print FILENAME, $0}'" infolist = Popen(args, stdout=PIPE, shell=True).stdout.read().decode() for line in infolist.split('\n'): if (line): linelist = line.split() diskname = linelist[0].split('/')[4] packet.append( ZabbixMetric(hostname, "custom.vfs.dev.read.ops[%s]" % diskname, linelist[1])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.read.merged[%s]" % diskname, linelist[2])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.read.sectors[%s]" % diskname, linelist[3])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.read.ms[%s]" % diskname, linelist[4])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.write.ops[%s]" % diskname, linelist[5])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.write.merged[%s]" % diskname, linelist[6])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.write.sectors[%s]" % diskname, linelist[7])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.write.ms[%s]" % diskname, linelist[8])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.io.active[%s]" % diskname, linelist[9])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.io.ms[%s]" % diskname, linelist[10])) packet.append( ZabbixMetric(hostname, "custom.vfs.dev.weight.io.ms[%s]" % diskname, linelist[11]))
def get_socket_stats(hostname): packet = [] procfile = open("/proc/net/sockstat", "r").readlines() for info in procfile: infolist = info.split() if (infolist[0] == 'sockets:'): packet.append( ZabbixMetric(hostname, "sockstat.sockets", infolist[2])) elif (infolist[0] == 'TCP:'): packet.append( ZabbixMetric(hostname, "sockstat.tcp.inuse", infolist[2])) packet.append( ZabbixMetric(hostname, "sockstat.tcp.orphan", infolist[4])) packet.append( ZabbixMetric(hostname, "sockstat.tcp.timewait", infolist[6])) packet.append( ZabbixMetric(hostname, "sockstat.tcp.allocated", infolist[8])) packet.append( ZabbixMetric(hostname, "sockstat.tcp.mem", int(infolist[10]) * 4096)) elif (infolist[0] == 'UDP:'): packet.append( ZabbixMetric(hostname, "sockstat.udp.inuse", infolist[2])) packet.append( ZabbixMetric(hostname, "sockstat.udp.mem", int(infolist[4]) * 4096)) elif (infolist[0] == 'UDPLITE:'): packet.append( ZabbixMetric(hostname, "sockstat.udplite.inuse", infolist[2])) elif (infolist[0] == 'RAW:'): packet.append( ZabbixMetric(hostname, "sockstat.raw.inuse", infolist[2])) elif (infolist[0] == 'FRAG:'): packet.append( ZabbixMetric(hostname, "sockstat.frag.inuse", infolist[2])) packet.append( ZabbixMetric(hostname, "sockstat.frag.mem", int(infolist[4]) * 4096)) args = "ss -an |grep tcp| awk '{++S[$2]} END {for(a in S) print a\":\"S[a]}'" infostr = Popen(args, stdout=PIPE, shell=True).stdout.read().decode() for info in infostr.split(): infolist = info.split(':') packet.append( ZabbixMetric(hostname, "sockstat.%s.number" % infolist[0], infolist[1])) return packet