def mem_u(self, d, day, start, end): cols = [ 'date', 'kbmemfree', 'kbmemused', 'pct_memused', 'kbmemsys', 'nodename' ] cmd = ['sysctl', 'hw.physmem'] (ret, out, err) = call(cmd) physmem = int(out.split(': ')[1]) / 1024 cmd = ['sysctl', 'hw.usermem'] (ret, out, err) = call(cmd) usermem = int(out.split(': ')[1]) / 1024 cmd = ['bsdsar', '-r', '-n', day] (ret, buff, err) = call(cmd) lines = [] for line in buff.split('\n'): l = line.split() if len(l) != 7: continue if l[0] == 'Time': continue free = self.kb(l[1]) used = self.kb(l[2]) + self.kb(l[3]) x = [ l[0], str(free), str(used), str(used / (used + free)), str(physmem - usermem), self.nodename ] x[0] = '%s %s' % (d, x[0]) lines.append(x) return cols, lines
def __init__(self, name): self.used_pct = 0 self.size = 0 self.free = 0 cmd = ['showfdmn', name] ret, out, err = call(cmd) if ret != 0: raise ExInit() d = {} """ Id Date Created LogPgs Version Domain Name 46a70bfd.000964b0 Wed Jul 25 10:38:21 2007 512 4 dom1 Vol 1K-Blks Free % Used Cmode Rblks Wblks Vol Name 2L 62914560 21056568 67% on 256 256 /dev/disk/dsk13c """ lines = out.split('\n') if len(lines) < 5: raise ExInit() header = lines[2].split() self.domid = header[0] self.name = header[-1] self.version = header[-2] self.logpgs = header[-3] self.vols = {} self.fsets = {} for line in lines[5:]: try: v = Volume(line) self += v except ExInit: pass cmd = ['showfsets', '-k', name] ret, out, err = call(cmd) if ret != 0: raise ExInit() lines = out.split('\n') n_lines = len(lines) if n_lines == 0: return h = 0 for i, line in enumerate(lines): if i != 0 and not line.startswith('\t') or i == n_lines - 1: f = Fset(lines[h:i]) self += f if not line.startswith('\t'): h = i
def swap(self, d, day, start, end): cols = [ 'date', 'kbswpfree', 'kbswpused', 'pct_swpused', 'kbswpcad', 'pct_swpcad', 'nodename' ] cmd = ['bsdsar', '-r', '-n', day] (ret, buff, err) = call(cmd, errlog=False) lines = [] if ret != 0: return cols, lines for line in buff.split('\n'): l = line.split() if len(l) != 7: continue if l[0] == 'Time': continue free = self.kb(l[6]) used = self.kb(l[5]) x = [ l[0], str(free), str(used), str(used / (free + used)), '0', '0' ] x.append(self.nodename) x[0] = '%s %s' % (d, x[0]) lines.append(x) return cols, lines
def scan(self, lname): vid = 'unknown' pid = 'unknown' wwid = 'unknown' size = 'unknown' cmd = ['lscfg', '-vpl', lname] (ret, out, err) = call(cmd) for f in out.split('\n'): if "Manufacturer" in f: vid = f.split('.')[-1] if "Machine Type and Model" in f: pid = f.split('.')[-1] cmd = ['bootinfo', '-s', lname] out, err, ret = justcall(cmd) if ret == 0: size = int(out.strip()) else: size = 0 wwid = self.odmget(lname, 'ww_name').replace('0x', '') if wwid == 'unknown': wwid = self.get_vscsi_id(lname) self.h[lname] = dict(vid=vid, pid=pid, wwid=wwid, size=size)
def do_check(self): """ # bdf -li Filesystem kbytes used avail %used iused ifree %iuse Mounted on /dev/vg00/lvol3 1048576 228160 814136 22% 2105 25607 8% / """ cmd = ['bdf', '-li'] (ret, out, err) = call(cmd) if ret != 0: return self.undef lines = out.split('\n') if len(lines) < 2: return self.undef r = [] for line in lines[1:]: l = line.split() if len(l) == 9: inst = ' '.join(l[8:]) r.append({ "instance": inst, "value": l[7], "path": self.find_svc(inst), }) elif len(l) == 8: inst = ' '.join(l[7:]) r.append({ "instance": inst, "value": l[6], "path": self.find_svc(inst), }) return r
def netdev(self, d, day, start, end): cols = ['date', 'dev', 'rxpckps', 'rxkBps', 'txpckps', 'txkBps', 'nodename'] f = self.sarfile(day) lines = [] if f is None: return cols, lines cmd = ['sar', '-n', 'DEV', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd, errlog=False) for line in buff.split('\n'): l = line.split() if len(l) != 6: continue if l[1] in ['IFACE', 'lo0'] : continue if 'dummy' in l[1] or 'vnet' in l[1] or 'veth' in l[1] or \ 'gif' in l[1] or 'stf' in l[1]: continue if l[0] == 'Average:': continue l.append(self.nodename) l[0] = '%s %s'%(d, l[0]) lines.append(l) return cols, lines
def blockdev(self, d, day, start, end): cols = ['date', 'dev', 'tps', 'rsecps', 'nodename'] f = self.sarfile(day) lines = [] if f is None: return cols, lines cmd = ['sar', '-d', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd, errlog=False) for line in buff.split('\n'): l = line.split() if len(l) != 4: continue if l[1] == 'device': continue if l[1] == 'Disk:': continue if l[0] == 'Average:': continue l.append(self.nodename) l[0] = '%s %s'%(d, l[0]) lines.append(l) return cols, lines
def cpu(self, d, day, start, end): cols = ['date', 'cpu', 'usr', 'nice', 'sys', 'idle', 'nodename'] f = self.sarfile(day) lines = [] if f is None: return cols, lines cmd = ['sar', '-u', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd, errlog=False) for line in buff.split('\n'): l = line.split() if len(l) != 5: continue if l[1] == '%usr': continue if l[0] == 'Average:': continue (time, usr, nice, sys, idle) = l l = ['%s %s'%(d, time), 'all', usr, nice, sys, idle, self.nodename] lines.append(l) return cols, lines
def stats_blockdev_day(t): d = t.strftime("%Y-%m-%d") day = t.strftime("%d") f = sarfile(day) if f is None: return [] cmd = ['sar', '-d', '-f', f] (ret, buff, err) = call(cmd, errlog=False) lines = [] for line in buff.split('\n'): l = line.split() if len(l) == 8: date = l[0] if len(l) == 7: l = [date] + l if len(l) != 8: continue if l[1] == 'device': continue if l[0] == 'Average': continue """ xmlrpc: 22:05:01 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 00:00:00 device %busy avque r+w/s blks/s avwait avserv """ x = ['%s %s'%(d, l[0]), l[1], l[4], '0', '0', '0', l[3], l[6], l[7], l[2], rcEnv.nodename] lines.append(x) return lines
def stats_cpu_day(t): d = t.strftime("%Y-%m-%d") day = t.strftime("%d") f = sarfile(day) if f is None: return [] cmd = ['sar', '-u', '-P', 'ALL', '-f', f] (ret, buff, err) = call(cmd, errlog=False) lines = [] for line in buff.split('\n'): l = line.split() if len(l) != 6: continue if l[1] == '%usr': continue if l[0] == 'Average': continue # SunOS: date %usr %sys %wio %idle # xmlrpc: date cpu usr nice sys iowait steal irq soft guest idle nodename x = ['%s %s'%(d, l[0]), 'all', '0', '0', '0', '0', '0', '0', '0', '0', '0', rcEnv.nodename] x[1] = l[1].replace('-', 'all') x[2] = l[2] x[4] = l[3] x[5] = l[4] x[10] = l[5] lines.append(x) return lines
def blockdev(self, d, day, start, end): cols = [ 'date', 'dev', 'pct_util', 'avgqu_sz', 'rsecps', 'await', 'svctm', 'nodename' ] f = self.sarfile(day) lines = [] if f is None: return cols, lines cmd = ['sar', '-d', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd, errlog=False) for line in buff.split('\n'): l = line.split() if len(l) == 8: date = l[0] if len(l) == 7: l = [date] + l if len(l) != 8: continue if l[1] == 'device': continue if l[0] == 'Average': continue # 00:00:00 device %busy avque r+w/s [blks/s] avwait avserv x = [ '%s %s' % (d, l[0]), l[1], l[2], l[3], l[4], l[6], l[7], self.nodename ] lines.append(x) return cols, lines
def file_to_loop(f): """Given a file path, returns the disk device associated. For example, /path/to/file => /dev/disk0s1 """ if which('hdiutil') is None: return [] if not os.path.isfile(f): return [] (ret, out, err) = call(['hdiutil', 'info', '-plist']) if ret != 0: return [] devs = [] try: pl = plistlib.readPlistFromString(out) except AttributeError as exc: raise ex.excError(str(exc)) for image in pl['images']: if image.get('image-path') == f: for se in image['system-entities']: diskdevice = se.get('dev-entry') if diskdevice is not None: devs.append(diskdevice) else: return [] return devs
def file_to_loop(f): """Given a file path, returns the loop device associated. For example, /path/to/file => /dev/loop0 """ if which('mdconfig') is None: return [] if not os.path.isfile(f): return [] (ret, out, err) = call(['mdconfig', '-l', '-v']) if ret != 0: return [] """ It's possible multiple loopdev are associated with the same file """ devs= [] for line in out.split('\n'): l = line.split() if len(l) < 4: continue path = ' '.join(l[3:]) if path != f: continue if not os.path.exists('/dev/'+l[0]): continue devs.append(l[0]) return devs
def check_ping(addr, timeout=5, count=1): cmd = ['ping', addr, '-n', repr(count), '-m', repr(timeout)] (ret, out, err) = call(cmd) if ret == 0: return True return False
def odmget(self, lname, attr): cmd = ['odmget', '-q', 'name='+lname+' AND attribute='+attr, 'CuAt'] (ret, out, err) = call(cmd) for f in out.split('\n'): if "value" not in f: continue return f.split(" = ")[-1].strip('"') return 'unknown'
def check_ping(addr, timeout=5, count=1): if ':' in addr: cmd = ['ping6'] else: cmd = ['ping', '-W', str(timeout)] cmd += ['-c', repr(count), addr] (ret, out, err) = call(cmd) if ret == 0: return True return False
def check_ping(addr, timeout=5, count=1): cmd = ['ping', '-c', repr(count), '-w', repr(timeout)] if ':' in addr: cmd += ['-a', 'inet6'] cmd += [addr] (ret, out, err) = call(cmd) if ret == 0: return True return False
def pkgversion(package): cmd = ['pkgutil', '--pkg-info', package] (ret, out, err) = call(cmd, errlog=False, cache=True) for line in out.split('\n'): l = line.split(': ') if len(l) != 2: continue if l[0] == 'version': return l[1] return ''
def __str__(self, option=None): if option is None: cmd = [rcEnv.syspaths.zfs, 'list', self.name] else: cmd = [rcEnv.syspaths.zfs, 'list'] + option + [self.name] (retcode, stdout, stderr) = call(cmd, log=self.log) if retcode == 0: return stdout else: return "Failed to list info for dataset: %s" % (self.name)
def listpkg(): if which('pkgutil') is None: return [] cmd = ['pkgutil', '--packages'] (ret, out, err) = call(cmd, errlog=False, cache=True) lines = [] for line in out.split('\n'): if len(line) == 0: continue x = [rcEnv.nodename, line, pkgversion(line), ""] lines.append(x) return lines
def get_vscsi_id(self, lname): cmd = ['lscfg', '-l', lname] (ret, out, err) = call(cmd) if ret != 0: return 'unknown' l = out.split() if len(l) < 2: return 'unknown' d = l[1] regex = re.compile(r'-C[0-9]+-T[0-9]+') d = regex.sub('', d) return d
def __init__(self, interval=2880, stats_dir=None, stats_start=None, stats_end=None): rcStats.StatsProvider.__init__(self, interval=interval, stats_dir=stats_dir, stats_start=stats_start, stats_end=stats_end) cmd = ['pagesize'] (ret, pagesize, err) = call(cmd) self.pagesize = int(pagesize)
def check_ping(addr, timeout=5, count=1): if ':' in addr: ping = 'ping6' else: ping = 'ping' cmd = [ ping, '-c', repr(count), '-W', repr(timeout), '-t', repr(timeout), addr ] (ret, out, err) = call(cmd) if ret == 0: return True return False
def netdev_err(self, d, day, start, end): cols = ['date', 'rxerrps', 'txerrps', 'collps', 'dev', 'nodename'] cmd = ['bsdsar', '-I', '-n', day] (ret, buff, err) = call(cmd, errlog=False) lines = [] if ret != 0: return cols, lines for line in buff.split('\n'): l = line.split() if len(l) != 9: continue if l[0] == 'Time': continue x = [l[0], l[2], l[5], l[7], l[8], self.nodename] x[0] = '%s %s' % (d, l[0]) lines.append(x) return cols, lines
def cpu(self, d, day, start, end): cols = ['date', 'usr', 'sys', 'nice', 'irq', 'idle', 'cpu', 'nodename'] cmd = ['bsdsar', '-u', '-n', day] (ret, buff, err) = call(cmd, errlog=False) lines = [] if ret != 0: return cols, lines for line in buff.split('\n'): l = line.split() if len(l) != 6: continue if l[0] == 'Time': continue l += ['ALL', self.nodename] l[0] = '%s %s' % (d, l[0]) lines.append(l) return cols, lines
def listpkg_t(t): cmd = ['swlist', '-l', t, '-a', 'revision', '-a', 'mod_time'] (ret, out, err) = call(cmd, errlog=False, cache=True) lines = [] for line in out.split('\n'): l = line.split() if len(l) < 3: continue if line[0] == '#': continue try: l[2] = datetime.datetime.fromtimestamp(int( l[2])).strftime("%Y-%m-%d %H:%M:%S") except: l[2] = "" x = [rcEnv.nodename, l[0], l[1], '', t, l[2]] lines.append(x) return lines
def proc(self, d, day, start, end): cols = ['date', 'runq_sz', 'nodename'] f = self.sarfile(day) lines = [] if f is None: return cols, lines cmd = ['sar', '-q', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd) for line in buff.split('\n'): l = line.split() if len(l) != 5: continue if l[1] == 'runq-sz': continue if l[0] == 'Average': continue x = ['%s %s' % (d, l[0]), l[1], self.nodename] lines.append(x) return cols, lines
def block(self, d, day, start, end): cols = ['date', 'rbps', 'wbps', 'nodename'] f = self.sarfile(day) lines = [] if f is None: return [], [] cmd = ['sar', '-b', '-f', f, '-s', start, '-e', end] (ret, buff, err) = call(cmd) for line in buff.split('\n'): l = line.split() if len(l) != 9: continue if l[1] == 'bread/s': continue if l[0] == 'Average': continue x = ['%s %s' % (d, l[0]), l[1], l[4], self.nodename] lines.append(x) return cols, lines
def stats_proc_day(t): d = t.strftime("%Y-%m-%d") day = t.strftime("%d") f = sarfile(day) if f is None: return [] cmd = ['sar', '-q', '-f', f] (ret, buff, err) = call(cmd) lines = [] for line in buff.split('\n'): l = line.split() if len(l) < 3: continue if ':' not in l[0]: continue """ xmlrpc: date runq_sz plist_sz ldavg_1 ldavg_5 ldavg_15 nodename """ x = ['%s %s'%(d, l[0]), l[1], '0', '0', '0', '0', rcEnv.nodename] lines.append(x) return lines
def stats_block_day(t): d = t.strftime("%Y-%m-%d") day = t.strftime("%d") f = sarfile(day) if f is None: return [] cmd = ['sar', '-b', '-f', f] (ret, buff, err) = call(cmd) lines = [] for line in buff.split('\n'): l = line.split() if len(l) != 9: continue if ':' not in l[1]: continue """ xmlrpc: date tps rtps wtps rbps wbps nodename """ x = ['%s %s'%(d, l[0]), '0', '0', '0', l[1], l[4], rcEnv.nodename] lines.append(x) return lines