repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo._initFilesystemInfo
def _initFilesystemInfo(self): """Initialize filesystem to device mappings.""" self._mapFSpathDev = {} fsinfo = FilesystemInfo() for fs in fsinfo.getFSlist(): devpath = fsinfo.getFSdev(fs) dev = self._getUniqueDev(devpath) if dev is not None: self._mapFSpathDev[fs] = dev
python
def _initFilesystemInfo(self): """Initialize filesystem to device mappings.""" self._mapFSpathDev = {} fsinfo = FilesystemInfo() for fs in fsinfo.getFSlist(): devpath = fsinfo.getFSdev(fs) dev = self._getUniqueDev(devpath) if dev is not None: self._mapFSpathDev[fs] = dev
[ "def", "_initFilesystemInfo", "(", "self", ")", ":", "self", ".", "_mapFSpathDev", "=", "{", "}", "fsinfo", "=", "FilesystemInfo", "(", ")", "for", "fs", "in", "fsinfo", ".", "getFSlist", "(", ")", ":", "devpath", "=", "fsinfo", ".", "getFSdev", "(", "fs", ")", "dev", "=", "self", ".", "_getUniqueDev", "(", "devpath", ")", "if", "dev", "is", "not", "None", ":", "self", ".", "_mapFSpathDev", "[", "fs", "]", "=", "dev" ]
Initialize filesystem to device mappings.
[ "Initialize", "filesystem", "to", "device", "mappings", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L139-L147
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo._initSwapInfo
def _initSwapInfo(self): """Initialize swap partition to device mappings.""" self._swapList = [] sysinfo = SystemInfo() for (swap,attrs) in sysinfo.getSwapStats().iteritems(): if attrs['type'] == 'partition': dev = self._getUniqueDev(swap) if dev is not None: self._swapList.append(dev)
python
def _initSwapInfo(self): """Initialize swap partition to device mappings.""" self._swapList = [] sysinfo = SystemInfo() for (swap,attrs) in sysinfo.getSwapStats().iteritems(): if attrs['type'] == 'partition': dev = self._getUniqueDev(swap) if dev is not None: self._swapList.append(dev)
[ "def", "_initSwapInfo", "(", "self", ")", ":", "self", ".", "_swapList", "=", "[", "]", "sysinfo", "=", "SystemInfo", "(", ")", "for", "(", "swap", ",", "attrs", ")", "in", "sysinfo", ".", "getSwapStats", "(", ")", ".", "iteritems", "(", ")", ":", "if", "attrs", "[", "'type'", "]", "==", "'partition'", ":", "dev", "=", "self", ".", "_getUniqueDev", "(", "swap", ")", "if", "dev", "is", "not", "None", ":", "self", ".", "_swapList", ".", "append", "(", "dev", ")" ]
Initialize swap partition to device mappings.
[ "Initialize", "swap", "partition", "to", "device", "mappings", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L149-L157
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo._initDiskStats
def _initDiskStats(self): """Parse and initialize block device I/O stats in /proc/diskstats.""" self._diskStats = {} self._mapMajorMinor2dev = {} try: fp = open(diskStatsFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading disk stats from file: %s' % diskStatsFile) for line in data.splitlines(): cols = line.split() dev = cols.pop(2) if len(cols) == 13: self._diskStats[dev] = dict(zip( ('major', 'minor', 'rios', 'rmerges', 'rsect', 'rticks', 'wios', 'wmerges', 'wsect', 'wticks', 'ios_active', 'totticks', 'rqticks'), [int(x) for x in cols])) elif len(cols) == 6: self._diskStats[dev] = dict(zip( ('major', 'minor', 'rios', 'rsect', 'wios', 'wsect'), [int(x) for x in cols])) else: continue self._diskStats[dev]['rbytes'] = ( self._diskStats[dev]['rsect'] * sectorSize) self._diskStats[dev]['wbytes'] = ( self._diskStats[dev]['wsect'] * sectorSize) self._mapMajorMinor2dev[(int(cols[0]), int(cols[1]))] = dev
python
def _initDiskStats(self): """Parse and initialize block device I/O stats in /proc/diskstats.""" self._diskStats = {} self._mapMajorMinor2dev = {} try: fp = open(diskStatsFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading disk stats from file: %s' % diskStatsFile) for line in data.splitlines(): cols = line.split() dev = cols.pop(2) if len(cols) == 13: self._diskStats[dev] = dict(zip( ('major', 'minor', 'rios', 'rmerges', 'rsect', 'rticks', 'wios', 'wmerges', 'wsect', 'wticks', 'ios_active', 'totticks', 'rqticks'), [int(x) for x in cols])) elif len(cols) == 6: self._diskStats[dev] = dict(zip( ('major', 'minor', 'rios', 'rsect', 'wios', 'wsect'), [int(x) for x in cols])) else: continue self._diskStats[dev]['rbytes'] = ( self._diskStats[dev]['rsect'] * sectorSize) self._diskStats[dev]['wbytes'] = ( self._diskStats[dev]['wsect'] * sectorSize) self._mapMajorMinor2dev[(int(cols[0]), int(cols[1]))] = dev
[ "def", "_initDiskStats", "(", "self", ")", ":", "self", ".", "_diskStats", "=", "{", "}", "self", ".", "_mapMajorMinor2dev", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "diskStatsFile", ",", "'r'", ")", "data", "=", "fp", ".", "read", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading disk stats from file: %s'", "%", "diskStatsFile", ")", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "cols", "=", "line", ".", "split", "(", ")", "dev", "=", "cols", ".", "pop", "(", "2", ")", "if", "len", "(", "cols", ")", "==", "13", ":", "self", ".", "_diskStats", "[", "dev", "]", "=", "dict", "(", "zip", "(", "(", "'major'", ",", "'minor'", ",", "'rios'", ",", "'rmerges'", ",", "'rsect'", ",", "'rticks'", ",", "'wios'", ",", "'wmerges'", ",", "'wsect'", ",", "'wticks'", ",", "'ios_active'", ",", "'totticks'", ",", "'rqticks'", ")", ",", "[", "int", "(", "x", ")", "for", "x", "in", "cols", "]", ")", ")", "elif", "len", "(", "cols", ")", "==", "6", ":", "self", ".", "_diskStats", "[", "dev", "]", "=", "dict", "(", "zip", "(", "(", "'major'", ",", "'minor'", ",", "'rios'", ",", "'rsect'", ",", "'wios'", ",", "'wsect'", ")", ",", "[", "int", "(", "x", ")", "for", "x", "in", "cols", "]", ")", ")", "else", ":", "continue", "self", ".", "_diskStats", "[", "dev", "]", "[", "'rbytes'", "]", "=", "(", "self", ".", "_diskStats", "[", "dev", "]", "[", "'rsect'", "]", "*", "sectorSize", ")", "self", ".", "_diskStats", "[", "dev", "]", "[", "'wbytes'", "]", "=", "(", "self", ".", "_diskStats", "[", "dev", "]", "[", "'wsect'", "]", "*", "sectorSize", ")", "self", ".", "_mapMajorMinor2dev", "[", "(", "int", "(", "cols", "[", "0", "]", ")", ",", "int", "(", "cols", "[", "1", "]", ")", ")", "]", "=", "dev" ]
Parse and initialize block device I/O stats in /proc/diskstats.
[ "Parse", "and", "initialize", "block", "device", "I", "/", "O", "stats", "in", "/", "proc", "/", "diskstats", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L159-L192
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo._initDevClasses
def _initDevClasses(self): """Sort block devices into lists depending on device class and initialize device type map and partition map.""" self._devClassTree = {} self._partitionTree = {} self._mapDevType = {} basedevs = [] otherdevs = [] if self._mapMajorDevclass is None: self._initBlockMajorMap() for dev in self._diskStats: stats = self._diskStats[dev] devclass = self._mapMajorDevclass.get(stats['major']) if devclass is not None: devdir = os.path.join(sysfsBlockdevDir, dev) if os.path.isdir(devdir): if not self._devClassTree.has_key(devclass): self._devClassTree[devclass] = [] self._devClassTree[devclass].append(dev) self._mapDevType[dev] = devclass basedevs.append(dev) else: otherdevs.append(dev) basedevs.sort(key=len, reverse=True) otherdevs.sort(key=len, reverse=True) idx = 0 for partdev in otherdevs: while len(basedevs[idx]) > partdev: idx += 1 for dev in basedevs[idx:]: if re.match("%s(\d+|p\d+)$" % dev, partdev): if not self._partitionTree.has_key(dev): self._partitionTree[dev] = [] self._partitionTree[dev].append(partdev) self._mapDevType[partdev] = 'part'
python
def _initDevClasses(self): """Sort block devices into lists depending on device class and initialize device type map and partition map.""" self._devClassTree = {} self._partitionTree = {} self._mapDevType = {} basedevs = [] otherdevs = [] if self._mapMajorDevclass is None: self._initBlockMajorMap() for dev in self._diskStats: stats = self._diskStats[dev] devclass = self._mapMajorDevclass.get(stats['major']) if devclass is not None: devdir = os.path.join(sysfsBlockdevDir, dev) if os.path.isdir(devdir): if not self._devClassTree.has_key(devclass): self._devClassTree[devclass] = [] self._devClassTree[devclass].append(dev) self._mapDevType[dev] = devclass basedevs.append(dev) else: otherdevs.append(dev) basedevs.sort(key=len, reverse=True) otherdevs.sort(key=len, reverse=True) idx = 0 for partdev in otherdevs: while len(basedevs[idx]) > partdev: idx += 1 for dev in basedevs[idx:]: if re.match("%s(\d+|p\d+)$" % dev, partdev): if not self._partitionTree.has_key(dev): self._partitionTree[dev] = [] self._partitionTree[dev].append(partdev) self._mapDevType[partdev] = 'part'
[ "def", "_initDevClasses", "(", "self", ")", ":", "self", ".", "_devClassTree", "=", "{", "}", "self", ".", "_partitionTree", "=", "{", "}", "self", ".", "_mapDevType", "=", "{", "}", "basedevs", "=", "[", "]", "otherdevs", "=", "[", "]", "if", "self", ".", "_mapMajorDevclass", "is", "None", ":", "self", ".", "_initBlockMajorMap", "(", ")", "for", "dev", "in", "self", ".", "_diskStats", ":", "stats", "=", "self", ".", "_diskStats", "[", "dev", "]", "devclass", "=", "self", ".", "_mapMajorDevclass", ".", "get", "(", "stats", "[", "'major'", "]", ")", "if", "devclass", "is", "not", "None", ":", "devdir", "=", "os", ".", "path", ".", "join", "(", "sysfsBlockdevDir", ",", "dev", ")", "if", "os", ".", "path", ".", "isdir", "(", "devdir", ")", ":", "if", "not", "self", ".", "_devClassTree", ".", "has_key", "(", "devclass", ")", ":", "self", ".", "_devClassTree", "[", "devclass", "]", "=", "[", "]", "self", ".", "_devClassTree", "[", "devclass", "]", ".", "append", "(", "dev", ")", "self", ".", "_mapDevType", "[", "dev", "]", "=", "devclass", "basedevs", ".", "append", "(", "dev", ")", "else", ":", "otherdevs", ".", "append", "(", "dev", ")", "basedevs", ".", "sort", "(", "key", "=", "len", ",", "reverse", "=", "True", ")", "otherdevs", ".", "sort", "(", "key", "=", "len", ",", "reverse", "=", "True", ")", "idx", "=", "0", "for", "partdev", "in", "otherdevs", ":", "while", "len", "(", "basedevs", "[", "idx", "]", ")", ">", "partdev", ":", "idx", "+=", "1", "for", "dev", "in", "basedevs", "[", "idx", ":", "]", ":", "if", "re", ".", "match", "(", "\"%s(\\d+|p\\d+)$\"", "%", "dev", ",", "partdev", ")", ":", "if", "not", "self", ".", "_partitionTree", ".", "has_key", "(", "dev", ")", ":", "self", ".", "_partitionTree", "[", "dev", "]", "=", "[", "]", "self", ".", "_partitionTree", "[", "dev", "]", ".", "append", "(", "partdev", ")", "self", ".", "_mapDevType", "[", "partdev", "]", "=", "'part'" ]
Sort block devices into lists depending on device class and initialize device type map and partition map.
[ "Sort", "block", "devices", "into", "lists", "depending", "on", "device", "class", "and", "initialize", "device", "type", "map", "and", "partition", "map", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L194-L228
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getDevType
def getDevType(self, dev): """Returns type of device dev. @return: Device type as string. """ if self._devClassTree is None: self._initDevClasses() return self._mapDevType.get(dev)
python
def getDevType(self, dev): """Returns type of device dev. @return: Device type as string. """ if self._devClassTree is None: self._initDevClasses() return self._mapDevType.get(dev)
[ "def", "getDevType", "(", "self", ",", "dev", ")", ":", "if", "self", ".", "_devClassTree", "is", "None", ":", "self", ".", "_initDevClasses", "(", ")", "return", "self", ".", "_mapDevType", ".", "get", "(", "dev", ")" ]
Returns type of device dev. @return: Device type as string.
[ "Returns", "type", "of", "device", "dev", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L230-L238
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getPartitionList
def getPartitionList(self): """Returns list of partitions. @return: List of (disk,partition) pairs. """ if self._partList is None: self._partList = [] for (disk,parts) in self.getPartitionDict().iteritems(): for part in parts: self._partList.append((disk,part)) return self._partList
python
def getPartitionList(self): """Returns list of partitions. @return: List of (disk,partition) pairs. """ if self._partList is None: self._partList = [] for (disk,parts) in self.getPartitionDict().iteritems(): for part in parts: self._partList.append((disk,part)) return self._partList
[ "def", "getPartitionList", "(", "self", ")", ":", "if", "self", ".", "_partList", "is", "None", ":", "self", ".", "_partList", "=", "[", "]", "for", "(", "disk", ",", "parts", ")", "in", "self", ".", "getPartitionDict", "(", ")", ".", "iteritems", "(", ")", ":", "for", "part", "in", "parts", ":", "self", ".", "_partList", ".", "append", "(", "(", "disk", ",", "part", ")", ")", "return", "self", ".", "_partList" ]
Returns list of partitions. @return: List of (disk,partition) pairs.
[ "Returns", "list", "of", "partitions", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L288-L299
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getDevStats
def getDevStats(self, dev, devtype = None): """Returns I/O stats for block device. @param dev: Device name @param devtype: Device type. (Ignored if None.) @return: Dict of stats. """ if devtype is not None: if self._devClassTree is None: self._initDevClasses() if devtype <> self._mapDevType.get(dev): return None return self._diskStats.get(dev)
python
def getDevStats(self, dev, devtype = None): """Returns I/O stats for block device. @param dev: Device name @param devtype: Device type. (Ignored if None.) @return: Dict of stats. """ if devtype is not None: if self._devClassTree is None: self._initDevClasses() if devtype <> self._mapDevType.get(dev): return None return self._diskStats.get(dev)
[ "def", "getDevStats", "(", "self", ",", "dev", ",", "devtype", "=", "None", ")", ":", "if", "devtype", "is", "not", "None", ":", "if", "self", ".", "_devClassTree", "is", "None", ":", "self", ".", "_initDevClasses", "(", ")", "if", "devtype", "<>", "self", ".", "_mapDevType", ".", "get", "(", "dev", ")", ":", "return", "None", "return", "self", ".", "_diskStats", ".", "get", "(", "dev", ")" ]
Returns I/O stats for block device. @param dev: Device name @param devtype: Device type. (Ignored if None.) @return: Dict of stats.
[ "Returns", "I", "/", "O", "stats", "for", "block", "device", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L367-L380
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getSwapStats
def getSwapStats(self, dev): """Returns I/O stats for swap partition. @param dev: Device name for swap partition. @return: Dict of stats. """ if self._swapList is None: self._initSwapInfo() if dev in self._swapList: return self.getDevStats(dev) else: return None
python
def getSwapStats(self, dev): """Returns I/O stats for swap partition. @param dev: Device name for swap partition. @return: Dict of stats. """ if self._swapList is None: self._initSwapInfo() if dev in self._swapList: return self.getDevStats(dev) else: return None
[ "def", "getSwapStats", "(", "self", ",", "dev", ")", ":", "if", "self", ".", "_swapList", "is", "None", ":", "self", ".", "_initSwapInfo", "(", ")", "if", "dev", "in", "self", ".", "_swapList", ":", "return", "self", ".", "getDevStats", "(", "dev", ")", "else", ":", "return", "None" ]
Returns I/O stats for swap partition. @param dev: Device name for swap partition. @return: Dict of stats.
[ "Returns", "I", "/", "O", "stats", "for", "swap", "partition", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L418-L430
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getLVstats
def getLVstats(self, *args): """Returns I/O stats for LV. @param args: Two calling conventions are implemented: - Passing two parameters vg and lv. - Passing only one parameter in 'vg-lv' format. @return: Dict of stats. """ if not len(args) in (1, 2): raise TypeError("The getLVstats must be called with either " "one or two arguments.") if self._vgTree is None: self._initDMinfo() if len(args) == 1: dmdev = self._mapLVname2dm.get(args[0]) else: dmdev = self._mapLVtuple2dm.get(args) if dmdev is not None: return self.getDevStats(dmdev) else: return None
python
def getLVstats(self, *args): """Returns I/O stats for LV. @param args: Two calling conventions are implemented: - Passing two parameters vg and lv. - Passing only one parameter in 'vg-lv' format. @return: Dict of stats. """ if not len(args) in (1, 2): raise TypeError("The getLVstats must be called with either " "one or two arguments.") if self._vgTree is None: self._initDMinfo() if len(args) == 1: dmdev = self._mapLVname2dm.get(args[0]) else: dmdev = self._mapLVtuple2dm.get(args) if dmdev is not None: return self.getDevStats(dmdev) else: return None
[ "def", "getLVstats", "(", "self", ",", "*", "args", ")", ":", "if", "not", "len", "(", "args", ")", "in", "(", "1", ",", "2", ")", ":", "raise", "TypeError", "(", "\"The getLVstats must be called with either \"", "\"one or two arguments.\"", ")", "if", "self", ".", "_vgTree", "is", "None", ":", "self", ".", "_initDMinfo", "(", ")", "if", "len", "(", "args", ")", "==", "1", ":", "dmdev", "=", "self", ".", "_mapLVname2dm", ".", "get", "(", "args", "[", "0", "]", ")", "else", ":", "dmdev", "=", "self", ".", "_mapLVtuple2dm", ".", "get", "(", "args", ")", "if", "dmdev", "is", "not", "None", ":", "return", "self", ".", "getDevStats", "(", "dmdev", ")", "else", ":", "return", "None" ]
Returns I/O stats for LV. @param args: Two calling conventions are implemented: - Passing two parameters vg and lv. - Passing only one parameter in 'vg-lv' format. @return: Dict of stats.
[ "Returns", "I", "/", "O", "stats", "for", "LV", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L432-L453
train
aouyar/PyMunin
pysysinfo/diskio.py
DiskIOinfo.getFilesystemStats
def getFilesystemStats(self, fs): """Returns I/O stats for filesystem. @param fs: Filesystem path. @return: Dict of stats. """ if self._mapFSpathDev is None: self._initFilesystemInfo() return self._diskStats.get(self._mapFSpathDev.get(fs))
python
def getFilesystemStats(self, fs): """Returns I/O stats for filesystem. @param fs: Filesystem path. @return: Dict of stats. """ if self._mapFSpathDev is None: self._initFilesystemInfo() return self._diskStats.get(self._mapFSpathDev.get(fs))
[ "def", "getFilesystemStats", "(", "self", ",", "fs", ")", ":", "if", "self", ".", "_mapFSpathDev", "is", "None", ":", "self", ".", "_initFilesystemInfo", "(", ")", "return", "self", ".", "_diskStats", ".", "get", "(", "self", ".", "_mapFSpathDev", ".", "get", "(", "fs", ")", ")" ]
Returns I/O stats for filesystem. @param fs: Filesystem path. @return: Dict of stats.
[ "Returns", "I", "/", "O", "stats", "for", "filesystem", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/diskio.py#L455-L464
train
aouyar/PyMunin
pymunin/plugins/ntphostoffset_.py
MuninNTPhostOffsetPlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" ntpinfo = NTPinfo() stats = ntpinfo.getHostOffset(self._remoteHost) if stats: graph_name = 'ntp_host_stratum_%s' % self._remoteHost if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'stratum', stats.get('stratum')) graph_name = 'ntp_host_stat_%s' % self._remoteHost if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'offset', stats.get('offset')) self.setGraphVal(graph_name, 'delay', stats.get('delay'))
python
def retrieveVals(self): """Retrieve values for graphs.""" ntpinfo = NTPinfo() stats = ntpinfo.getHostOffset(self._remoteHost) if stats: graph_name = 'ntp_host_stratum_%s' % self._remoteHost if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'stratum', stats.get('stratum')) graph_name = 'ntp_host_stat_%s' % self._remoteHost if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'offset', stats.get('offset')) self.setGraphVal(graph_name, 'delay', stats.get('delay'))
[ "def", "retrieveVals", "(", "self", ")", ":", "ntpinfo", "=", "NTPinfo", "(", ")", "stats", "=", "ntpinfo", ".", "getHostOffset", "(", "self", ".", "_remoteHost", ")", "if", "stats", ":", "graph_name", "=", "'ntp_host_stratum_%s'", "%", "self", ".", "_remoteHost", "if", "self", ".", "hasGraph", "(", "graph_name", ")", ":", "self", ".", "setGraphVal", "(", "graph_name", ",", "'stratum'", ",", "stats", ".", "get", "(", "'stratum'", ")", ")", "graph_name", "=", "'ntp_host_stat_%s'", "%", "self", ".", "_remoteHost", "if", "self", ".", "hasGraph", "(", "graph_name", ")", ":", "self", ".", "setGraphVal", "(", "graph_name", ",", "'offset'", ",", "stats", ".", "get", "(", "'offset'", ")", ")", "self", ".", "setGraphVal", "(", "graph_name", ",", "'delay'", ",", "stats", ".", "get", "(", "'delay'", ")", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/ntphostoffset_.py#L105-L116
train
aouyar/PyMunin
pysysinfo/rackspace.py
CloudFilesInfo.getContainerStats
def getContainerStats(self, limit=None, marker=None): """Returns Rackspace Cloud Files usage stats for containers. @param limit: Number of containers to return. @param marker: Return only results whose name is greater than marker. @return: Dictionary of container stats indexed by container name. """ stats = {} for row in self._conn.list_containers_info(limit, marker): stats[row['name']] = {'count': row['count'], 'size': row['bytes']} return stats
python
def getContainerStats(self, limit=None, marker=None): """Returns Rackspace Cloud Files usage stats for containers. @param limit: Number of containers to return. @param marker: Return only results whose name is greater than marker. @return: Dictionary of container stats indexed by container name. """ stats = {} for row in self._conn.list_containers_info(limit, marker): stats[row['name']] = {'count': row['count'], 'size': row['bytes']} return stats
[ "def", "getContainerStats", "(", "self", ",", "limit", "=", "None", ",", "marker", "=", "None", ")", ":", "stats", "=", "{", "}", "for", "row", "in", "self", ".", "_conn", ".", "list_containers_info", "(", "limit", ",", "marker", ")", ":", "stats", "[", "row", "[", "'name'", "]", "]", "=", "{", "'count'", ":", "row", "[", "'count'", "]", ",", "'size'", ":", "row", "[", "'bytes'", "]", "}", "return", "stats" ]
Returns Rackspace Cloud Files usage stats for containers. @param limit: Number of containers to return. @param marker: Return only results whose name is greater than marker. @return: Dictionary of container stats indexed by container name.
[ "Returns", "Rackspace", "Cloud", "Files", "usage", "stats", "for", "containers", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/rackspace.py#L58-L69
train
ContextLab/quail
quail/decode_speech.py
decode_speech
def decode_speech(path, keypath=None, save=False, speech_context=None, sample_rate=44100, max_alternatives=1, language_code='en-US', enable_word_time_offsets=True, return_raw=False): """ Decode speech for a file or folder and return results This function wraps the Google Speech API and ffmpeg to decode speech for free recall experiments. Note: in order for this to work, you must have a Google Speech account, a google speech credentials file referenced in your _bash_profile, and ffmpeg installed on your computer. See our readthedocs for more information on how to set this up: http://cdl-quail.readthedocs.io/en/latest/. Parameters ---------- path : str Path to a wav file, or a folder of wav files. keypath : str Google Cloud Speech API key filepath. This is a JSON file containing credentials that was generated when creating a service account key. If None, assumes you have a local key that is set with an environmental variable. See the speech decoding tutorial for details. save : boolean False by default, but if set to true, will save a pickle with the results object from google speech, and a text file with the decoded words. speech_context : list of str This allows you to give some context to the speech decoding algorithm. For example, this could be the words studied on a given list, or all words in an experiment. sample_rate : float The sample rate of your audio files (default is 44100). max_alternatives : int You can specify the speech decoding to return multiple guesses to the decoding. This will be saved in the results object (default is 1). language_code : str Decoding language code. Default is en-US. See here for more details: https://cloud.google.com/speech/docs/languages enable_word_time_offsets : bool Returns timing information s(onsets/offsets) for each word (default is True). return_raw : boolean Intead of returning the parsed results objects (i.e. the words), you can return the raw reponse object. This has more details about the decoding, such as confidence. Returns ---------- words : list of str, or list of lists of str The results of the speech decoding. This will be a list if only one file is input, or a list of lists if more than one file is decoded. raw : google speech object, or list of objects You can optionally return the google speech object instead of the parsed results by using the return_raw flag. """ # SUBFUNCTIONS def decode_file(file_path, client, speech_context, sample_rate, max_alternatives, enable_word_time_offsets): def recognize(chunk, file_path): """ Subfunction that loops over audio segments to recognize speech """ # export as flac chunk.export(file_path + ".flac", format = "flac", bitrate="44.1k") # open flac file with open(file_path + ".flac", 'rb') as sc: speech_content = sc.read() # initialize speech sample sample = types.RecognitionAudio(content=speech_content) # run speech decoding try: result = client.recognize(opts, sample) except ValueError as e: print(e) result = None return result opts = {} opts['encoding']=enums.RecognitionConfig.AudioEncoding.FLAC opts['language_code'] = language_code opts['sample_rate_hertz'] = sample_rate opts['max_alternatives'] = max_alternatives opts['enable_word_time_offsets'] = enable_word_time_offsets if speech_context: opts['speech_contexts']=[types.SpeechContext(phrases=speech_context)] # read in wav audio = AudioSegment.from_wav(file_path) # segment into 1 minute chunks if len(audio)>60000: segments = list(range(0,len(audio),60000)) if segments[-1]<len(audio): segments.append(len(audio)-1) print('Audio clip is longer than 1 minute. Splitting into %d one minute segments...' % (len(segments)-1)) audio_chunks = [] for i in range(len(segments)-1): audio_chunks.append(audio[segments[i]:segments[i+1]]) else: audio_chunks = [audio] # loop over audio segments results = [] for idx, chunk in enumerate(audio_chunks): results.append(recognize(chunk, file_path+str(idx))) # return list of results return results def parse_response(results): """Parses response from google speech""" words = [] for chunk in results: for result in chunk.results: alternative = result.alternatives[0] print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) for word_info in alternative.words: word = word_info.word start_time = word_info.start_time end_time = word_info.end_time print('Word: {}, start_time: {}, end_time: {}'.format( word, start_time.seconds + start_time.nanos * 1e-9, end_time.seconds + end_time.nanos * 1e-9)) words.append((str(word).upper(), start_time.seconds + start_time.nanos * 1e-9, end_time.seconds + end_time.nanos * 1e-9)) return words # def parse_response(results): # """Parses response from google speech""" # words = [] # for idx, result in enumerate(results): # if result is None: # warnings.warn('No speech was decoded for segment %d' % (idx+1)) # words.append(None) # else: # try: # for segment in result: # for chunk in segment.transcript.split(' '): # if chunk != '': # words.append(str(chunk).upper()) # except: # warnings.warn('Error parsing response for segment %d' % (idx+1)) # # return words # MAIN ##################################################################### # initialize speech client if keypath: credentials = service_account.Credentials.from_service_account_file(keypath) scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/cloud-platform']) client = speech.SpeechClient(credentials=scoped_credentials) else: client = speech.SpeechClient() # make a list of files files = [] if path.endswith(".wav"): files = [path] else: listdirectory = os.listdir(path) for filename in listdirectory: if filename.endswith(".wav"): files.append(path + filename) # initialize list of words words = [] raw = [] # loop over files for i, f in enumerate(files): # print progress print('Decoding file ' + str(i+1) + ' of ' + str(len(files))) try: # start timer start = time.time() # decode file results = decode_file(f, client, speech_context, sample_rate, max_alternatives, enable_word_time_offsets) # parsing response parsed_results = parse_response(results) # save the processed file words.append(parsed_results) # save the processed file raw.append(results) if save: # save the raw response in a pickle pickle.dump(results, open(f + ".p", "wb" ) ) # save a text file with just the words pd.DataFrame(parsed_results).to_csv(f + '.txt', header=False, index=False) # print when finished print('Finished file ' + str(i+1) + ' of ' + str(len(files)) + ' in ' + str(round(time.time()-start,2)) + ' seconds.') # handle when something goes wrong except ValueError as e: words.append("Error") print(e) print('Decoding of file ' + str(i) + 'failed. Moving on to next file.') if return_raw: if len(words)>1: return raw else: return raw[0] else: if len(words)>1: return words else: return words[0]
python
def decode_speech(path, keypath=None, save=False, speech_context=None, sample_rate=44100, max_alternatives=1, language_code='en-US', enable_word_time_offsets=True, return_raw=False): """ Decode speech for a file or folder and return results This function wraps the Google Speech API and ffmpeg to decode speech for free recall experiments. Note: in order for this to work, you must have a Google Speech account, a google speech credentials file referenced in your _bash_profile, and ffmpeg installed on your computer. See our readthedocs for more information on how to set this up: http://cdl-quail.readthedocs.io/en/latest/. Parameters ---------- path : str Path to a wav file, or a folder of wav files. keypath : str Google Cloud Speech API key filepath. This is a JSON file containing credentials that was generated when creating a service account key. If None, assumes you have a local key that is set with an environmental variable. See the speech decoding tutorial for details. save : boolean False by default, but if set to true, will save a pickle with the results object from google speech, and a text file with the decoded words. speech_context : list of str This allows you to give some context to the speech decoding algorithm. For example, this could be the words studied on a given list, or all words in an experiment. sample_rate : float The sample rate of your audio files (default is 44100). max_alternatives : int You can specify the speech decoding to return multiple guesses to the decoding. This will be saved in the results object (default is 1). language_code : str Decoding language code. Default is en-US. See here for more details: https://cloud.google.com/speech/docs/languages enable_word_time_offsets : bool Returns timing information s(onsets/offsets) for each word (default is True). return_raw : boolean Intead of returning the parsed results objects (i.e. the words), you can return the raw reponse object. This has more details about the decoding, such as confidence. Returns ---------- words : list of str, or list of lists of str The results of the speech decoding. This will be a list if only one file is input, or a list of lists if more than one file is decoded. raw : google speech object, or list of objects You can optionally return the google speech object instead of the parsed results by using the return_raw flag. """ # SUBFUNCTIONS def decode_file(file_path, client, speech_context, sample_rate, max_alternatives, enable_word_time_offsets): def recognize(chunk, file_path): """ Subfunction that loops over audio segments to recognize speech """ # export as flac chunk.export(file_path + ".flac", format = "flac", bitrate="44.1k") # open flac file with open(file_path + ".flac", 'rb') as sc: speech_content = sc.read() # initialize speech sample sample = types.RecognitionAudio(content=speech_content) # run speech decoding try: result = client.recognize(opts, sample) except ValueError as e: print(e) result = None return result opts = {} opts['encoding']=enums.RecognitionConfig.AudioEncoding.FLAC opts['language_code'] = language_code opts['sample_rate_hertz'] = sample_rate opts['max_alternatives'] = max_alternatives opts['enable_word_time_offsets'] = enable_word_time_offsets if speech_context: opts['speech_contexts']=[types.SpeechContext(phrases=speech_context)] # read in wav audio = AudioSegment.from_wav(file_path) # segment into 1 minute chunks if len(audio)>60000: segments = list(range(0,len(audio),60000)) if segments[-1]<len(audio): segments.append(len(audio)-1) print('Audio clip is longer than 1 minute. Splitting into %d one minute segments...' % (len(segments)-1)) audio_chunks = [] for i in range(len(segments)-1): audio_chunks.append(audio[segments[i]:segments[i+1]]) else: audio_chunks = [audio] # loop over audio segments results = [] for idx, chunk in enumerate(audio_chunks): results.append(recognize(chunk, file_path+str(idx))) # return list of results return results def parse_response(results): """Parses response from google speech""" words = [] for chunk in results: for result in chunk.results: alternative = result.alternatives[0] print('Transcript: {}'.format(alternative.transcript)) print('Confidence: {}'.format(alternative.confidence)) for word_info in alternative.words: word = word_info.word start_time = word_info.start_time end_time = word_info.end_time print('Word: {}, start_time: {}, end_time: {}'.format( word, start_time.seconds + start_time.nanos * 1e-9, end_time.seconds + end_time.nanos * 1e-9)) words.append((str(word).upper(), start_time.seconds + start_time.nanos * 1e-9, end_time.seconds + end_time.nanos * 1e-9)) return words # def parse_response(results): # """Parses response from google speech""" # words = [] # for idx, result in enumerate(results): # if result is None: # warnings.warn('No speech was decoded for segment %d' % (idx+1)) # words.append(None) # else: # try: # for segment in result: # for chunk in segment.transcript.split(' '): # if chunk != '': # words.append(str(chunk).upper()) # except: # warnings.warn('Error parsing response for segment %d' % (idx+1)) # # return words # MAIN ##################################################################### # initialize speech client if keypath: credentials = service_account.Credentials.from_service_account_file(keypath) scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/cloud-platform']) client = speech.SpeechClient(credentials=scoped_credentials) else: client = speech.SpeechClient() # make a list of files files = [] if path.endswith(".wav"): files = [path] else: listdirectory = os.listdir(path) for filename in listdirectory: if filename.endswith(".wav"): files.append(path + filename) # initialize list of words words = [] raw = [] # loop over files for i, f in enumerate(files): # print progress print('Decoding file ' + str(i+1) + ' of ' + str(len(files))) try: # start timer start = time.time() # decode file results = decode_file(f, client, speech_context, sample_rate, max_alternatives, enable_word_time_offsets) # parsing response parsed_results = parse_response(results) # save the processed file words.append(parsed_results) # save the processed file raw.append(results) if save: # save the raw response in a pickle pickle.dump(results, open(f + ".p", "wb" ) ) # save a text file with just the words pd.DataFrame(parsed_results).to_csv(f + '.txt', header=False, index=False) # print when finished print('Finished file ' + str(i+1) + ' of ' + str(len(files)) + ' in ' + str(round(time.time()-start,2)) + ' seconds.') # handle when something goes wrong except ValueError as e: words.append("Error") print(e) print('Decoding of file ' + str(i) + 'failed. Moving on to next file.') if return_raw: if len(words)>1: return raw else: return raw[0] else: if len(words)>1: return words else: return words[0]
[ "def", "decode_speech", "(", "path", ",", "keypath", "=", "None", ",", "save", "=", "False", ",", "speech_context", "=", "None", ",", "sample_rate", "=", "44100", ",", "max_alternatives", "=", "1", ",", "language_code", "=", "'en-US'", ",", "enable_word_time_offsets", "=", "True", ",", "return_raw", "=", "False", ")", ":", "# SUBFUNCTIONS", "def", "decode_file", "(", "file_path", ",", "client", ",", "speech_context", ",", "sample_rate", ",", "max_alternatives", ",", "enable_word_time_offsets", ")", ":", "def", "recognize", "(", "chunk", ",", "file_path", ")", ":", "\"\"\"\n Subfunction that loops over audio segments to recognize speech\n \"\"\"", "# export as flac", "chunk", ".", "export", "(", "file_path", "+", "\".flac\"", ",", "format", "=", "\"flac\"", ",", "bitrate", "=", "\"44.1k\"", ")", "# open flac file", "with", "open", "(", "file_path", "+", "\".flac\"", ",", "'rb'", ")", "as", "sc", ":", "speech_content", "=", "sc", ".", "read", "(", ")", "# initialize speech sample", "sample", "=", "types", ".", "RecognitionAudio", "(", "content", "=", "speech_content", ")", "# run speech decoding", "try", ":", "result", "=", "client", ".", "recognize", "(", "opts", ",", "sample", ")", "except", "ValueError", "as", "e", ":", "print", "(", "e", ")", "result", "=", "None", "return", "result", "opts", "=", "{", "}", "opts", "[", "'encoding'", "]", "=", "enums", ".", "RecognitionConfig", ".", "AudioEncoding", ".", "FLAC", "opts", "[", "'language_code'", "]", "=", "language_code", "opts", "[", "'sample_rate_hertz'", "]", "=", "sample_rate", "opts", "[", "'max_alternatives'", "]", "=", "max_alternatives", "opts", "[", "'enable_word_time_offsets'", "]", "=", "enable_word_time_offsets", "if", "speech_context", ":", "opts", "[", "'speech_contexts'", "]", "=", "[", "types", ".", "SpeechContext", "(", "phrases", "=", "speech_context", ")", "]", "# read in wav", "audio", "=", "AudioSegment", ".", "from_wav", "(", "file_path", ")", "# segment into 1 minute chunks", "if", "len", "(", "audio", ")", ">", "60000", ":", "segments", "=", "list", "(", "range", "(", "0", ",", "len", "(", "audio", ")", ",", "60000", ")", ")", "if", "segments", "[", "-", "1", "]", "<", "len", "(", "audio", ")", ":", "segments", ".", "append", "(", "len", "(", "audio", ")", "-", "1", ")", "print", "(", "'Audio clip is longer than 1 minute. Splitting into %d one minute segments...'", "%", "(", "len", "(", "segments", ")", "-", "1", ")", ")", "audio_chunks", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "segments", ")", "-", "1", ")", ":", "audio_chunks", ".", "append", "(", "audio", "[", "segments", "[", "i", "]", ":", "segments", "[", "i", "+", "1", "]", "]", ")", "else", ":", "audio_chunks", "=", "[", "audio", "]", "# loop over audio segments", "results", "=", "[", "]", "for", "idx", ",", "chunk", "in", "enumerate", "(", "audio_chunks", ")", ":", "results", ".", "append", "(", "recognize", "(", "chunk", ",", "file_path", "+", "str", "(", "idx", ")", ")", ")", "# return list of results", "return", "results", "def", "parse_response", "(", "results", ")", ":", "\"\"\"Parses response from google speech\"\"\"", "words", "=", "[", "]", "for", "chunk", "in", "results", ":", "for", "result", "in", "chunk", ".", "results", ":", "alternative", "=", "result", ".", "alternatives", "[", "0", "]", "print", "(", "'Transcript: {}'", ".", "format", "(", "alternative", ".", "transcript", ")", ")", "print", "(", "'Confidence: {}'", ".", "format", "(", "alternative", ".", "confidence", ")", ")", "for", "word_info", "in", "alternative", ".", "words", ":", "word", "=", "word_info", ".", "word", "start_time", "=", "word_info", ".", "start_time", "end_time", "=", "word_info", ".", "end_time", "print", "(", "'Word: {}, start_time: {}, end_time: {}'", ".", "format", "(", "word", ",", "start_time", ".", "seconds", "+", "start_time", ".", "nanos", "*", "1e-9", ",", "end_time", ".", "seconds", "+", "end_time", ".", "nanos", "*", "1e-9", ")", ")", "words", ".", "append", "(", "(", "str", "(", "word", ")", ".", "upper", "(", ")", ",", "start_time", ".", "seconds", "+", "start_time", ".", "nanos", "*", "1e-9", ",", "end_time", ".", "seconds", "+", "end_time", ".", "nanos", "*", "1e-9", ")", ")", "return", "words", "# def parse_response(results):", "# \"\"\"Parses response from google speech\"\"\"", "# words = []", "# for idx, result in enumerate(results):", "# if result is None:", "# warnings.warn('No speech was decoded for segment %d' % (idx+1))", "# words.append(None)", "# else:", "# try:", "# for segment in result:", "# for chunk in segment.transcript.split(' '):", "# if chunk != '':", "# words.append(str(chunk).upper())", "# except:", "# warnings.warn('Error parsing response for segment %d' % (idx+1))", "#", "# return words", "# MAIN #####################################################################", "# initialize speech client", "if", "keypath", ":", "credentials", "=", "service_account", ".", "Credentials", ".", "from_service_account_file", "(", "keypath", ")", "scoped_credentials", "=", "credentials", ".", "with_scopes", "(", "[", "'https://www.googleapis.com/auth/cloud-platform'", "]", ")", "client", "=", "speech", ".", "SpeechClient", "(", "credentials", "=", "scoped_credentials", ")", "else", ":", "client", "=", "speech", ".", "SpeechClient", "(", ")", "# make a list of files", "files", "=", "[", "]", "if", "path", ".", "endswith", "(", "\".wav\"", ")", ":", "files", "=", "[", "path", "]", "else", ":", "listdirectory", "=", "os", ".", "listdir", "(", "path", ")", "for", "filename", "in", "listdirectory", ":", "if", "filename", ".", "endswith", "(", "\".wav\"", ")", ":", "files", ".", "append", "(", "path", "+", "filename", ")", "# initialize list of words", "words", "=", "[", "]", "raw", "=", "[", "]", "# loop over files", "for", "i", ",", "f", "in", "enumerate", "(", "files", ")", ":", "# print progress", "print", "(", "'Decoding file '", "+", "str", "(", "i", "+", "1", ")", "+", "' of '", "+", "str", "(", "len", "(", "files", ")", ")", ")", "try", ":", "# start timer", "start", "=", "time", ".", "time", "(", ")", "# decode file", "results", "=", "decode_file", "(", "f", ",", "client", ",", "speech_context", ",", "sample_rate", ",", "max_alternatives", ",", "enable_word_time_offsets", ")", "# parsing response", "parsed_results", "=", "parse_response", "(", "results", ")", "# save the processed file", "words", ".", "append", "(", "parsed_results", ")", "# save the processed file", "raw", ".", "append", "(", "results", ")", "if", "save", ":", "# save the raw response in a pickle", "pickle", ".", "dump", "(", "results", ",", "open", "(", "f", "+", "\".p\"", ",", "\"wb\"", ")", ")", "# save a text file with just the words", "pd", ".", "DataFrame", "(", "parsed_results", ")", ".", "to_csv", "(", "f", "+", "'.txt'", ",", "header", "=", "False", ",", "index", "=", "False", ")", "# print when finished", "print", "(", "'Finished file '", "+", "str", "(", "i", "+", "1", ")", "+", "' of '", "+", "str", "(", "len", "(", "files", ")", ")", "+", "' in '", "+", "str", "(", "round", "(", "time", ".", "time", "(", ")", "-", "start", ",", "2", ")", ")", "+", "' seconds.'", ")", "# handle when something goes wrong", "except", "ValueError", "as", "e", ":", "words", ".", "append", "(", "\"Error\"", ")", "print", "(", "e", ")", "print", "(", "'Decoding of file '", "+", "str", "(", "i", ")", "+", "'failed. Moving on to next file.'", ")", "if", "return_raw", ":", "if", "len", "(", "words", ")", ">", "1", ":", "return", "raw", "else", ":", "return", "raw", "[", "0", "]", "else", ":", "if", "len", "(", "words", ")", ">", "1", ":", "return", "words", "else", ":", "return", "words", "[", "0", "]" ]
Decode speech for a file or folder and return results This function wraps the Google Speech API and ffmpeg to decode speech for free recall experiments. Note: in order for this to work, you must have a Google Speech account, a google speech credentials file referenced in your _bash_profile, and ffmpeg installed on your computer. See our readthedocs for more information on how to set this up: http://cdl-quail.readthedocs.io/en/latest/. Parameters ---------- path : str Path to a wav file, or a folder of wav files. keypath : str Google Cloud Speech API key filepath. This is a JSON file containing credentials that was generated when creating a service account key. If None, assumes you have a local key that is set with an environmental variable. See the speech decoding tutorial for details. save : boolean False by default, but if set to true, will save a pickle with the results object from google speech, and a text file with the decoded words. speech_context : list of str This allows you to give some context to the speech decoding algorithm. For example, this could be the words studied on a given list, or all words in an experiment. sample_rate : float The sample rate of your audio files (default is 44100). max_alternatives : int You can specify the speech decoding to return multiple guesses to the decoding. This will be saved in the results object (default is 1). language_code : str Decoding language code. Default is en-US. See here for more details: https://cloud.google.com/speech/docs/languages enable_word_time_offsets : bool Returns timing information s(onsets/offsets) for each word (default is True). return_raw : boolean Intead of returning the parsed results objects (i.e. the words), you can return the raw reponse object. This has more details about the decoding, such as confidence. Returns ---------- words : list of str, or list of lists of str The results of the speech decoding. This will be a list if only one file is input, or a list of lists if more than one file is decoded. raw : google speech object, or list of objects You can optionally return the google speech object instead of the parsed results by using the return_raw flag.
[ "Decode", "speech", "for", "a", "file", "or", "folder", "and", "return", "results" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/decode_speech.py#L24-L265
train
aouyar/PyMunin
pysysinfo/squid.py
parse_value
def parse_value(val): """Parse input string and return int, float or str depending on format. @param val: Input string. @return: Value of type int, float or str. """ mobj = re.match('(-{0,1}\d+)\s*(\sseconds|/\s*\w+)$', val) if mobj: return int(mobj.group(1)) mobj = re.match('(-{0,1}\d*\.\d+)\s*(\sseconds|/\s*\w+)$', val) if mobj: return float(mobj.group(1)) re.match('(-{0,1}\d+)\s*([GMK])B$', val) if mobj: return int(mobj.group(1)) * memMultiplier[mobj.group(2)] mobj = re.match('(-{0,1}\d+(\.\d+){0,1})\s*\%$', val) if mobj: return float(mobj.group(1)) / 100 return val
python
def parse_value(val): """Parse input string and return int, float or str depending on format. @param val: Input string. @return: Value of type int, float or str. """ mobj = re.match('(-{0,1}\d+)\s*(\sseconds|/\s*\w+)$', val) if mobj: return int(mobj.group(1)) mobj = re.match('(-{0,1}\d*\.\d+)\s*(\sseconds|/\s*\w+)$', val) if mobj: return float(mobj.group(1)) re.match('(-{0,1}\d+)\s*([GMK])B$', val) if mobj: return int(mobj.group(1)) * memMultiplier[mobj.group(2)] mobj = re.match('(-{0,1}\d+(\.\d+){0,1})\s*\%$', val) if mobj: return float(mobj.group(1)) / 100 return val
[ "def", "parse_value", "(", "val", ")", ":", "mobj", "=", "re", ".", "match", "(", "'(-{0,1}\\d+)\\s*(\\sseconds|/\\s*\\w+)$'", ",", "val", ")", "if", "mobj", ":", "return", "int", "(", "mobj", ".", "group", "(", "1", ")", ")", "mobj", "=", "re", ".", "match", "(", "'(-{0,1}\\d*\\.\\d+)\\s*(\\sseconds|/\\s*\\w+)$'", ",", "val", ")", "if", "mobj", ":", "return", "float", "(", "mobj", ".", "group", "(", "1", ")", ")", "re", ".", "match", "(", "'(-{0,1}\\d+)\\s*([GMK])B$'", ",", "val", ")", "if", "mobj", ":", "return", "int", "(", "mobj", ".", "group", "(", "1", ")", ")", "*", "memMultiplier", "[", "mobj", ".", "group", "(", "2", ")", "]", "mobj", "=", "re", ".", "match", "(", "'(-{0,1}\\d+(\\.\\d+){0,1})\\s*\\%$'", ",", "val", ")", "if", "mobj", ":", "return", "float", "(", "mobj", ".", "group", "(", "1", ")", ")", "/", "100", "return", "val" ]
Parse input string and return int, float or str depending on format. @param val: Input string. @return: Value of type int, float or str.
[ "Parse", "input", "string", "and", "return", "int", "float", "or", "str", "depending", "on", "format", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L31-L51
train
aouyar/PyMunin
pysysinfo/squid.py
SquidInfo._connect
def _connect(self): """Connect to Squid Proxy Manager interface.""" if sys.version_info[:2] < (2,6): self._conn = httplib.HTTPConnection(self._host, self._port) else: self._conn = httplib.HTTPConnection(self._host, self._port, False, defaultTimeout)
python
def _connect(self): """Connect to Squid Proxy Manager interface.""" if sys.version_info[:2] < (2,6): self._conn = httplib.HTTPConnection(self._host, self._port) else: self._conn = httplib.HTTPConnection(self._host, self._port, False, defaultTimeout)
[ "def", "_connect", "(", "self", ")", ":", "if", "sys", ".", "version_info", "[", ":", "2", "]", "<", "(", "2", ",", "6", ")", ":", "self", ".", "_conn", "=", "httplib", ".", "HTTPConnection", "(", "self", ".", "_host", ",", "self", ".", "_port", ")", "else", ":", "self", ".", "_conn", "=", "httplib", ".", "HTTPConnection", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "False", ",", "defaultTimeout", ")" ]
Connect to Squid Proxy Manager interface.
[ "Connect", "to", "Squid", "Proxy", "Manager", "interface", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L90-L96
train
aouyar/PyMunin
pysysinfo/squid.py
SquidInfo._retrieve
def _retrieve(self, map): """Query Squid Proxy Server Manager Interface for stats. @param map: Statistics map name. @return: Dictionary of query results. """ self._conn.request('GET', "cache_object://%s/%s" % (self._host, map), None, self._httpHeaders) rp = self._conn.getresponse() if rp.status == 200: data = rp.read() return data else: raise Exception("Retrieval of stats from Squid Proxy Server" "on host %s and port %s failed.\n" "HTTP - Status: %s Reason: %s" % (self._host, self._port, rp.status, rp.reason))
python
def _retrieve(self, map): """Query Squid Proxy Server Manager Interface for stats. @param map: Statistics map name. @return: Dictionary of query results. """ self._conn.request('GET', "cache_object://%s/%s" % (self._host, map), None, self._httpHeaders) rp = self._conn.getresponse() if rp.status == 200: data = rp.read() return data else: raise Exception("Retrieval of stats from Squid Proxy Server" "on host %s and port %s failed.\n" "HTTP - Status: %s Reason: %s" % (self._host, self._port, rp.status, rp.reason))
[ "def", "_retrieve", "(", "self", ",", "map", ")", ":", "self", ".", "_conn", ".", "request", "(", "'GET'", ",", "\"cache_object://%s/%s\"", "%", "(", "self", ".", "_host", ",", "map", ")", ",", "None", ",", "self", ".", "_httpHeaders", ")", "rp", "=", "self", ".", "_conn", ".", "getresponse", "(", ")", "if", "rp", ".", "status", "==", "200", ":", "data", "=", "rp", ".", "read", "(", ")", "return", "data", "else", ":", "raise", "Exception", "(", "\"Retrieval of stats from Squid Proxy Server\"", "\"on host %s and port %s failed.\\n\"", "\"HTTP - Status: %s Reason: %s\"", "%", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "rp", ".", "status", ",", "rp", ".", "reason", ")", ")" ]
Query Squid Proxy Server Manager Interface for stats. @param map: Statistics map name. @return: Dictionary of query results.
[ "Query", "Squid", "Proxy", "Server", "Manager", "Interface", "for", "stats", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L98-L115
train
aouyar/PyMunin
pysysinfo/squid.py
SquidInfo._parseCounters
def _parseCounters(self, data): """Parse simple stats list of key, value pairs. @param data: Multiline data with one key-value pair in each line. @return: Dictionary of stats. """ info_dict = util.NestedDict() for line in data.splitlines(): mobj = re.match('^\s*([\w\.]+)\s*=\s*(\S.*)$', line) if mobj: (key, value) = mobj.groups() klist = key.split('.') info_dict.set_nested(klist, parse_value(value)) return info_dict
python
def _parseCounters(self, data): """Parse simple stats list of key, value pairs. @param data: Multiline data with one key-value pair in each line. @return: Dictionary of stats. """ info_dict = util.NestedDict() for line in data.splitlines(): mobj = re.match('^\s*([\w\.]+)\s*=\s*(\S.*)$', line) if mobj: (key, value) = mobj.groups() klist = key.split('.') info_dict.set_nested(klist, parse_value(value)) return info_dict
[ "def", "_parseCounters", "(", "self", ",", "data", ")", ":", "info_dict", "=", "util", ".", "NestedDict", "(", ")", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'^\\s*([\\w\\.]+)\\s*=\\s*(\\S.*)$'", ",", "line", ")", "if", "mobj", ":", "(", "key", ",", "value", ")", "=", "mobj", ".", "groups", "(", ")", "klist", "=", "key", ".", "split", "(", "'.'", ")", "info_dict", ".", "set_nested", "(", "klist", ",", "parse_value", "(", "value", ")", ")", "return", "info_dict" ]
Parse simple stats list of key, value pairs. @param data: Multiline data with one key-value pair in each line. @return: Dictionary of stats.
[ "Parse", "simple", "stats", "list", "of", "key", "value", "pairs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L117-L131
train
aouyar/PyMunin
pysysinfo/squid.py
SquidInfo._parseSections
def _parseSections(self, data): """Parse data and separate sections. Returns dictionary that maps section name to section data. @param data: Multiline data. @return: Dictionary that maps section names to section data. """ section_dict = {} lines = data.splitlines() idx = 0 numlines = len(lines) section = None while idx < numlines: line = lines[idx] idx += 1 mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:$', line) if mobj: section = mobj.group(1) section_dict[section] = [] else: mobj = re.match('(\t|\s)\s*(\w.*)$', line) if mobj: section_dict[section].append(mobj.group(2)) else: mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:\s*(\S.*)$', line) if mobj: section = None if not section_dict.has_key(section): section_dict[section] = [] section_dict[section].append(line) else: if not section_dict.has_key('PARSEERROR'): section_dict['PARSEERROR'] = [] section_dict['PARSEERROR'].append(line) return section_dict
python
def _parseSections(self, data): """Parse data and separate sections. Returns dictionary that maps section name to section data. @param data: Multiline data. @return: Dictionary that maps section names to section data. """ section_dict = {} lines = data.splitlines() idx = 0 numlines = len(lines) section = None while idx < numlines: line = lines[idx] idx += 1 mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:$', line) if mobj: section = mobj.group(1) section_dict[section] = [] else: mobj = re.match('(\t|\s)\s*(\w.*)$', line) if mobj: section_dict[section].append(mobj.group(2)) else: mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:\s*(\S.*)$', line) if mobj: section = None if not section_dict.has_key(section): section_dict[section] = [] section_dict[section].append(line) else: if not section_dict.has_key('PARSEERROR'): section_dict['PARSEERROR'] = [] section_dict['PARSEERROR'].append(line) return section_dict
[ "def", "_parseSections", "(", "self", ",", "data", ")", ":", "section_dict", "=", "{", "}", "lines", "=", "data", ".", "splitlines", "(", ")", "idx", "=", "0", "numlines", "=", "len", "(", "lines", ")", "section", "=", "None", "while", "idx", "<", "numlines", ":", "line", "=", "lines", "[", "idx", "]", "idx", "+=", "1", "mobj", "=", "re", ".", "match", "(", "'^(\\w[\\w\\s\\(\\)]+[\\w\\)])\\s*:$'", ",", "line", ")", "if", "mobj", ":", "section", "=", "mobj", ".", "group", "(", "1", ")", "section_dict", "[", "section", "]", "=", "[", "]", "else", ":", "mobj", "=", "re", ".", "match", "(", "'(\\t|\\s)\\s*(\\w.*)$'", ",", "line", ")", "if", "mobj", ":", "section_dict", "[", "section", "]", ".", "append", "(", "mobj", ".", "group", "(", "2", ")", ")", "else", ":", "mobj", "=", "re", ".", "match", "(", "'^(\\w[\\w\\s\\(\\)]+[\\w\\)])\\s*:\\s*(\\S.*)$'", ",", "line", ")", "if", "mobj", ":", "section", "=", "None", "if", "not", "section_dict", ".", "has_key", "(", "section", ")", ":", "section_dict", "[", "section", "]", "=", "[", "]", "section_dict", "[", "section", "]", ".", "append", "(", "line", ")", "else", ":", "if", "not", "section_dict", ".", "has_key", "(", "'PARSEERROR'", ")", ":", "section_dict", "[", "'PARSEERROR'", "]", "=", "[", "]", "section_dict", "[", "'PARSEERROR'", "]", ".", "append", "(", "line", ")", "return", "section_dict" ]
Parse data and separate sections. Returns dictionary that maps section name to section data. @param data: Multiline data. @return: Dictionary that maps section names to section data.
[ "Parse", "data", "and", "separate", "sections", ".", "Returns", "dictionary", "that", "maps", "section", "name", "to", "section", "data", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L133-L168
train
aouyar/PyMunin
pysysinfo/squid.py
SquidInfo.getMenu
def getMenu(self): """Get manager interface section list from Squid Proxy Server @return: List of tuples (section, description, type) """ data = self._retrieve('') info_list = [] for line in data.splitlines(): mobj = re.match('^\s*(\S.*\S)\s*\t\s*(\S.*\S)\s*\t\s*(\S.*\S)$', line) if mobj: info_list.append(mobj.groups()) return info_list
python
def getMenu(self): """Get manager interface section list from Squid Proxy Server @return: List of tuples (section, description, type) """ data = self._retrieve('') info_list = [] for line in data.splitlines(): mobj = re.match('^\s*(\S.*\S)\s*\t\s*(\S.*\S)\s*\t\s*(\S.*\S)$', line) if mobj: info_list.append(mobj.groups()) return info_list
[ "def", "getMenu", "(", "self", ")", ":", "data", "=", "self", ".", "_retrieve", "(", "''", ")", "info_list", "=", "[", "]", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'^\\s*(\\S.*\\S)\\s*\\t\\s*(\\S.*\\S)\\s*\\t\\s*(\\S.*\\S)$'", ",", "line", ")", "if", "mobj", ":", "info_list", ".", "append", "(", "mobj", ".", "groups", "(", ")", ")", "return", "info_list" ]
Get manager interface section list from Squid Proxy Server @return: List of tuples (section, description, type)
[ "Get", "manager", "interface", "section", "list", "from", "Squid", "Proxy", "Server" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/squid.py#L170-L182
train
aouyar/PyMunin
pysysinfo/wanpipe.py
WanpipeInfo.getIfaceStats
def getIfaceStats(self): """Return dictionary of Traffic Stats for each Wanpipe Interface. @return: Nested dictionary of statistics for each interface. """ ifInfo = netiface.NetIfaceInfo() ifStats = ifInfo.getIfStats() info_dict = {} for ifname in ifStats: if re.match('^w\d+g\d+$', ifname): info_dict[ifname] = ifStats[ifname] return info_dict
python
def getIfaceStats(self): """Return dictionary of Traffic Stats for each Wanpipe Interface. @return: Nested dictionary of statistics for each interface. """ ifInfo = netiface.NetIfaceInfo() ifStats = ifInfo.getIfStats() info_dict = {} for ifname in ifStats: if re.match('^w\d+g\d+$', ifname): info_dict[ifname] = ifStats[ifname] return info_dict
[ "def", "getIfaceStats", "(", "self", ")", ":", "ifInfo", "=", "netiface", ".", "NetIfaceInfo", "(", ")", "ifStats", "=", "ifInfo", ".", "getIfStats", "(", ")", "info_dict", "=", "{", "}", "for", "ifname", "in", "ifStats", ":", "if", "re", ".", "match", "(", "'^w\\d+g\\d+$'", ",", "ifname", ")", ":", "info_dict", "[", "ifname", "]", "=", "ifStats", "[", "ifname", "]", "return", "info_dict" ]
Return dictionary of Traffic Stats for each Wanpipe Interface. @return: Nested dictionary of statistics for each interface.
[ "Return", "dictionary", "of", "Traffic", "Stats", "for", "each", "Wanpipe", "Interface", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/wanpipe.py#L27-L39
train
aouyar/PyMunin
pysysinfo/wanpipe.py
WanpipeInfo.getPRIstats
def getPRIstats(self, iface): """Return RDSI Operational Stats for interface. @param iface: Interface name. (Ex. w1g1) @return: Nested dictionary of statistics for interface. """ info_dict = {} output = util.exec_command([wanpipemonCmd, '-i', iface, '-c', 'Ta']) for line in output.splitlines(): mobj = re.match('^\s*(Line Code Violation|Far End Block Errors|' 'CRC4 Errors|FAS Errors)\s*:\s*(\d+)\s*$', line, re.IGNORECASE) if mobj: info_dict[mobj.group(1).lower().replace(' ', '')] = int(mobj.group(2)) continue mobj = re.match('^\s*(Rx Level)\s*:\s*>{0,1}\s*([-\d\.]+)db\s*', line, re.IGNORECASE) if mobj: info_dict[mobj.group(1).lower().replace(' ', '')] = float(mobj.group(2)) continue return info_dict
python
def getPRIstats(self, iface): """Return RDSI Operational Stats for interface. @param iface: Interface name. (Ex. w1g1) @return: Nested dictionary of statistics for interface. """ info_dict = {} output = util.exec_command([wanpipemonCmd, '-i', iface, '-c', 'Ta']) for line in output.splitlines(): mobj = re.match('^\s*(Line Code Violation|Far End Block Errors|' 'CRC4 Errors|FAS Errors)\s*:\s*(\d+)\s*$', line, re.IGNORECASE) if mobj: info_dict[mobj.group(1).lower().replace(' ', '')] = int(mobj.group(2)) continue mobj = re.match('^\s*(Rx Level)\s*:\s*>{0,1}\s*([-\d\.]+)db\s*', line, re.IGNORECASE) if mobj: info_dict[mobj.group(1).lower().replace(' ', '')] = float(mobj.group(2)) continue return info_dict
[ "def", "getPRIstats", "(", "self", ",", "iface", ")", ":", "info_dict", "=", "{", "}", "output", "=", "util", ".", "exec_command", "(", "[", "wanpipemonCmd", ",", "'-i'", ",", "iface", ",", "'-c'", ",", "'Ta'", "]", ")", "for", "line", "in", "output", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'^\\s*(Line Code Violation|Far End Block Errors|'", "'CRC4 Errors|FAS Errors)\\s*:\\s*(\\d+)\\s*$'", ",", "line", ",", "re", ".", "IGNORECASE", ")", "if", "mobj", ":", "info_dict", "[", "mobj", ".", "group", "(", "1", ")", ".", "lower", "(", ")", ".", "replace", "(", "' '", ",", "''", ")", "]", "=", "int", "(", "mobj", ".", "group", "(", "2", ")", ")", "continue", "mobj", "=", "re", ".", "match", "(", "'^\\s*(Rx Level)\\s*:\\s*>{0,1}\\s*([-\\d\\.]+)db\\s*'", ",", "line", ",", "re", ".", "IGNORECASE", ")", "if", "mobj", ":", "info_dict", "[", "mobj", ".", "group", "(", "1", ")", ".", "lower", "(", ")", ".", "replace", "(", "' '", ",", "''", ")", "]", "=", "float", "(", "mobj", ".", "group", "(", "2", ")", ")", "continue", "return", "info_dict" ]
Return RDSI Operational Stats for interface. @param iface: Interface name. (Ex. w1g1) @return: Nested dictionary of statistics for interface.
[ "Return", "RDSI", "Operational", "Stats", "for", "interface", ".", "@param", "iface", ":", "Interface", "name", ".", "(", "Ex", ".", "w1g1", ")", "@return", ":", "Nested", "dictionary", "of", "statistics", "for", "interface", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/wanpipe.py#L41-L62
train
aouyar/PyMunin
pysysinfo/freeswitch.py
FSinfo._connect
def _connect(self): """Connect to FreeSWITCH ESL Interface.""" try: self._eslconn = ESL.ESLconnection(self._eslhost, str(self._eslport), self._eslpass) except: pass if not self._eslconn.connected(): raise Exception( "Connection to FreeSWITCH ESL Interface on host %s and port %d failed." % (self._eslhost, self._eslport) )
python
def _connect(self): """Connect to FreeSWITCH ESL Interface.""" try: self._eslconn = ESL.ESLconnection(self._eslhost, str(self._eslport), self._eslpass) except: pass if not self._eslconn.connected(): raise Exception( "Connection to FreeSWITCH ESL Interface on host %s and port %d failed." % (self._eslhost, self._eslport) )
[ "def", "_connect", "(", "self", ")", ":", "try", ":", "self", ".", "_eslconn", "=", "ESL", ".", "ESLconnection", "(", "self", ".", "_eslhost", ",", "str", "(", "self", ".", "_eslport", ")", ",", "self", ".", "_eslpass", ")", "except", ":", "pass", "if", "not", "self", ".", "_eslconn", ".", "connected", "(", ")", ":", "raise", "Exception", "(", "\"Connection to FreeSWITCH ESL Interface on host %s and port %d failed.\"", "%", "(", "self", ".", "_eslhost", ",", "self", ".", "_eslport", ")", ")" ]
Connect to FreeSWITCH ESL Interface.
[ "Connect", "to", "FreeSWITCH", "ESL", "Interface", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/freeswitch.py#L60-L72
train
aouyar/PyMunin
pysysinfo/freeswitch.py
FSinfo._execCmd
def _execCmd(self, cmd, args): """Execute command and return result body as list of lines. @param cmd: Command string. @param args: Comand arguments string. @return: Result dictionary. """ output = self._eslconn.api(cmd, args) if output: body = output.getBody() if body: return body.splitlines() return None
python
def _execCmd(self, cmd, args): """Execute command and return result body as list of lines. @param cmd: Command string. @param args: Comand arguments string. @return: Result dictionary. """ output = self._eslconn.api(cmd, args) if output: body = output.getBody() if body: return body.splitlines() return None
[ "def", "_execCmd", "(", "self", ",", "cmd", ",", "args", ")", ":", "output", "=", "self", ".", "_eslconn", ".", "api", "(", "cmd", ",", "args", ")", "if", "output", ":", "body", "=", "output", ".", "getBody", "(", ")", "if", "body", ":", "return", "body", ".", "splitlines", "(", ")", "return", "None" ]
Execute command and return result body as list of lines. @param cmd: Command string. @param args: Comand arguments string. @return: Result dictionary.
[ "Execute", "command", "and", "return", "result", "body", "as", "list", "of", "lines", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/freeswitch.py#L74-L87
train
aouyar/PyMunin
pysysinfo/freeswitch.py
FSinfo._execShowCmd
def _execShowCmd(self, showcmd): """Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary. """ result = None lines = self._execCmd("show", showcmd) if lines and len(lines) >= 2 and lines[0] != '' and lines[0][0] != '-': result = {} result['keys'] = lines[0].split(',') items = [] for line in lines[1:]: if line == '': break items.append(line.split(',')) result['items'] = items return result
python
def _execShowCmd(self, showcmd): """Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary. """ result = None lines = self._execCmd("show", showcmd) if lines and len(lines) >= 2 and lines[0] != '' and lines[0][0] != '-': result = {} result['keys'] = lines[0].split(',') items = [] for line in lines[1:]: if line == '': break items.append(line.split(',')) result['items'] = items return result
[ "def", "_execShowCmd", "(", "self", ",", "showcmd", ")", ":", "result", "=", "None", "lines", "=", "self", ".", "_execCmd", "(", "\"show\"", ",", "showcmd", ")", "if", "lines", "and", "len", "(", "lines", ")", ">=", "2", "and", "lines", "[", "0", "]", "!=", "''", "and", "lines", "[", "0", "]", "[", "0", "]", "!=", "'-'", ":", "result", "=", "{", "}", "result", "[", "'keys'", "]", "=", "lines", "[", "0", "]", ".", "split", "(", "','", ")", "items", "=", "[", "]", "for", "line", "in", "lines", "[", "1", ":", "]", ":", "if", "line", "==", "''", ":", "break", "items", ".", "append", "(", "line", ".", "split", "(", "','", ")", ")", "result", "[", "'items'", "]", "=", "items", "return", "result" ]
Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary.
[ "Execute", "show", "command", "and", "return", "result", "dictionary", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/freeswitch.py#L89-L107
train
aouyar/PyMunin
pysysinfo/freeswitch.py
FSinfo._execShowCountCmd
def _execShowCountCmd(self, showcmd): """Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary. """ result = None lines = self._execCmd("show", showcmd + " count") for line in lines: mobj = re.match('\s*(\d+)\s+total', line) if mobj: return int(mobj.group(1)) return result
python
def _execShowCountCmd(self, showcmd): """Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary. """ result = None lines = self._execCmd("show", showcmd + " count") for line in lines: mobj = re.match('\s*(\d+)\s+total', line) if mobj: return int(mobj.group(1)) return result
[ "def", "_execShowCountCmd", "(", "self", ",", "showcmd", ")", ":", "result", "=", "None", "lines", "=", "self", ".", "_execCmd", "(", "\"show\"", ",", "showcmd", "+", "\" count\"", ")", "for", "line", "in", "lines", ":", "mobj", "=", "re", ".", "match", "(", "'\\s*(\\d+)\\s+total'", ",", "line", ")", "if", "mobj", ":", "return", "int", "(", "mobj", ".", "group", "(", "1", ")", ")", "return", "result" ]
Execute 'show' command and return result dictionary. @param cmd: Command string. @return: Result dictionary.
[ "Execute", "show", "command", "and", "return", "result", "dictionary", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/freeswitch.py#L109-L122
train
aouyar/PyMunin
pymunin/plugins/asteriskstats.py
MuninAsteriskPlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" if self.hasGraph('asterisk_calls') or self.hasGraph('asterisk_channels'): stats = self._ami.getChannelStats(self._chanList) if self.hasGraph('asterisk_calls') and stats: self.setGraphVal('asterisk_calls', 'active_calls', stats.get('active_calls')) self.setGraphVal('asterisk_calls', 'calls_per_min', stats.get('calls_processed')) if self.hasGraph('asterisk_channels') and stats: for field in self._chanList: self.setGraphVal('asterisk_channels', field, stats.get(field)) if 'dahdi' in self._chanList: self.setGraphVal('asterisk_channels', 'mix', stats.get('mix')) if self.hasGraph('asterisk_peers_sip'): stats = self._ami.getPeerStats('sip') if stats: for field in ('online', 'unmonitored', 'unreachable', 'lagged', 'unknown'): self.setGraphVal('asterisk_peers_sip', field, stats.get(field)) if self.hasGraph('asterisk_peers_iax2'): stats = self._ami.getPeerStats('iax2') if stats: for field in ('online', 'unmonitored', 'unreachable', 'lagged', 'unknown'): self.setGraphVal('asterisk_peers_iax2', field, stats.get(field)) if self.hasGraph('asterisk_voip_codecs'): sipstats = self._ami.getVoIPchanStats('sip', self._codecList) or {} iax2stats = self._ami.getVoIPchanStats('iax2', self._codecList) or {} if stats: for field in self._codecList: self.setGraphVal('asterisk_voip_codecs', field, sipstats.get(field,0) + iax2stats.get(field, 0)) self.setGraphVal('asterisk_voip_codecs', 'other', sipstats.get('other', 0) + iax2stats.get('other', 0)) if self.hasGraph('asterisk_conferences'): stats = self._ami.getConferenceStats() if stats: self.setGraphVal('asterisk_conferences', 'rooms', stats.get('active_conferences')) self.setGraphVal('asterisk_conferences', 'users', stats.get('conference_users')) if self.hasGraph('asterisk_voicemail'): stats = self._ami.getVoicemailStats() if stats: self.setGraphVal('asterisk_voicemail', 'accounts', stats.get('accounts')) self.setGraphVal('asterisk_voicemail', 'msg_avg', stats.get('avg_messages')) self.setGraphVal('asterisk_voicemail', 'msg_max', stats.get('max_messages')) self.setGraphVal('asterisk_voicemail', 'msg_total', stats.get('total_messages')) if self.hasGraph('asterisk_trunks') and len(self._trunkList) > 0: stats = self._ami.getTrunkStats(self._trunkList) for trunk in self._trunkList: self.setGraphVal('asterisk_trunks', trunk[0], stats.get(trunk[0])) if self._queues is not None: total_answer = 0 total_abandon = 0 for queue in self._queue_list: stats = self._queues[queue] if self.hasGraph('asterisk_queue_len'): self.setGraphVal('asterisk_queue_len', queue, stats.get('queue_len')) if self.hasGraph('asterisk_queue_avg_hold'): self.setGraphVal('asterisk_queue_avg_hold', queue, stats.get('avg_holdtime')) if self.hasGraph('asterisk_queue_avg_talk'): self.setGraphVal('asterisk_queue_avg_talk', queue, stats.get('avg_talktime')) if self.hasGraph('asterisk_queue_calls'): total_abandon += stats.get('calls_abandoned') total_answer += stats.get('calls_completed') if self.hasGraph('asterisk_queue_abandon_pcent'): prev_stats = self._queues_prev.get(queue) if prev_stats is not None: abandon = (stats.get('calls_abandoned', 0) - prev_stats.get('calls_abandoned', 0)) answer = (stats.get('calls_completed', 0) - prev_stats.get('calls_completed', 0)) total = abandon + answer if total > 0: val = 100.0 * float(abandon) / float(total) else: val = 0 self.setGraphVal('asterisk_queue_abandon_pcent', queue, val) if self.hasGraph('asterisk_queue_calls'): self.setGraphVal('asterisk_queue_calls', 'abandon', total_abandon) self.setGraphVal('asterisk_queue_calls', 'answer', total_answer) if self.hasGraph('asterisk_fax_attempts'): fax_stats = self._ami.getFaxStatsCounters() stats = fax_stats.get('general') if stats is not None: self.setGraphVal('asterisk_fax_attempts', 'send', stats.get('transmit attempts')) self.setGraphVal('asterisk_fax_attempts', 'recv', stats.get('receive attempts')) self.setGraphVal('asterisk_fax_attempts', 'fail', stats.get('failed faxes'))
python
def retrieveVals(self): """Retrieve values for graphs.""" if self.hasGraph('asterisk_calls') or self.hasGraph('asterisk_channels'): stats = self._ami.getChannelStats(self._chanList) if self.hasGraph('asterisk_calls') and stats: self.setGraphVal('asterisk_calls', 'active_calls', stats.get('active_calls')) self.setGraphVal('asterisk_calls', 'calls_per_min', stats.get('calls_processed')) if self.hasGraph('asterisk_channels') and stats: for field in self._chanList: self.setGraphVal('asterisk_channels', field, stats.get(field)) if 'dahdi' in self._chanList: self.setGraphVal('asterisk_channels', 'mix', stats.get('mix')) if self.hasGraph('asterisk_peers_sip'): stats = self._ami.getPeerStats('sip') if stats: for field in ('online', 'unmonitored', 'unreachable', 'lagged', 'unknown'): self.setGraphVal('asterisk_peers_sip', field, stats.get(field)) if self.hasGraph('asterisk_peers_iax2'): stats = self._ami.getPeerStats('iax2') if stats: for field in ('online', 'unmonitored', 'unreachable', 'lagged', 'unknown'): self.setGraphVal('asterisk_peers_iax2', field, stats.get(field)) if self.hasGraph('asterisk_voip_codecs'): sipstats = self._ami.getVoIPchanStats('sip', self._codecList) or {} iax2stats = self._ami.getVoIPchanStats('iax2', self._codecList) or {} if stats: for field in self._codecList: self.setGraphVal('asterisk_voip_codecs', field, sipstats.get(field,0) + iax2stats.get(field, 0)) self.setGraphVal('asterisk_voip_codecs', 'other', sipstats.get('other', 0) + iax2stats.get('other', 0)) if self.hasGraph('asterisk_conferences'): stats = self._ami.getConferenceStats() if stats: self.setGraphVal('asterisk_conferences', 'rooms', stats.get('active_conferences')) self.setGraphVal('asterisk_conferences', 'users', stats.get('conference_users')) if self.hasGraph('asterisk_voicemail'): stats = self._ami.getVoicemailStats() if stats: self.setGraphVal('asterisk_voicemail', 'accounts', stats.get('accounts')) self.setGraphVal('asterisk_voicemail', 'msg_avg', stats.get('avg_messages')) self.setGraphVal('asterisk_voicemail', 'msg_max', stats.get('max_messages')) self.setGraphVal('asterisk_voicemail', 'msg_total', stats.get('total_messages')) if self.hasGraph('asterisk_trunks') and len(self._trunkList) > 0: stats = self._ami.getTrunkStats(self._trunkList) for trunk in self._trunkList: self.setGraphVal('asterisk_trunks', trunk[0], stats.get(trunk[0])) if self._queues is not None: total_answer = 0 total_abandon = 0 for queue in self._queue_list: stats = self._queues[queue] if self.hasGraph('asterisk_queue_len'): self.setGraphVal('asterisk_queue_len', queue, stats.get('queue_len')) if self.hasGraph('asterisk_queue_avg_hold'): self.setGraphVal('asterisk_queue_avg_hold', queue, stats.get('avg_holdtime')) if self.hasGraph('asterisk_queue_avg_talk'): self.setGraphVal('asterisk_queue_avg_talk', queue, stats.get('avg_talktime')) if self.hasGraph('asterisk_queue_calls'): total_abandon += stats.get('calls_abandoned') total_answer += stats.get('calls_completed') if self.hasGraph('asterisk_queue_abandon_pcent'): prev_stats = self._queues_prev.get(queue) if prev_stats is not None: abandon = (stats.get('calls_abandoned', 0) - prev_stats.get('calls_abandoned', 0)) answer = (stats.get('calls_completed', 0) - prev_stats.get('calls_completed', 0)) total = abandon + answer if total > 0: val = 100.0 * float(abandon) / float(total) else: val = 0 self.setGraphVal('asterisk_queue_abandon_pcent', queue, val) if self.hasGraph('asterisk_queue_calls'): self.setGraphVal('asterisk_queue_calls', 'abandon', total_abandon) self.setGraphVal('asterisk_queue_calls', 'answer', total_answer) if self.hasGraph('asterisk_fax_attempts'): fax_stats = self._ami.getFaxStatsCounters() stats = fax_stats.get('general') if stats is not None: self.setGraphVal('asterisk_fax_attempts', 'send', stats.get('transmit attempts')) self.setGraphVal('asterisk_fax_attempts', 'recv', stats.get('receive attempts')) self.setGraphVal('asterisk_fax_attempts', 'fail', stats.get('failed faxes'))
[ "def", "retrieveVals", "(", "self", ")", ":", "if", "self", ".", "hasGraph", "(", "'asterisk_calls'", ")", "or", "self", ".", "hasGraph", "(", "'asterisk_channels'", ")", ":", "stats", "=", "self", ".", "_ami", ".", "getChannelStats", "(", "self", ".", "_chanList", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_calls'", ")", "and", "stats", ":", "self", ".", "setGraphVal", "(", "'asterisk_calls'", ",", "'active_calls'", ",", "stats", ".", "get", "(", "'active_calls'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_calls'", ",", "'calls_per_min'", ",", "stats", ".", "get", "(", "'calls_processed'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_channels'", ")", "and", "stats", ":", "for", "field", "in", "self", ".", "_chanList", ":", "self", ".", "setGraphVal", "(", "'asterisk_channels'", ",", "field", ",", "stats", ".", "get", "(", "field", ")", ")", "if", "'dahdi'", "in", "self", ".", "_chanList", ":", "self", ".", "setGraphVal", "(", "'asterisk_channels'", ",", "'mix'", ",", "stats", ".", "get", "(", "'mix'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_peers_sip'", ")", ":", "stats", "=", "self", ".", "_ami", ".", "getPeerStats", "(", "'sip'", ")", "if", "stats", ":", "for", "field", "in", "(", "'online'", ",", "'unmonitored'", ",", "'unreachable'", ",", "'lagged'", ",", "'unknown'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_peers_sip'", ",", "field", ",", "stats", ".", "get", "(", "field", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_peers_iax2'", ")", ":", "stats", "=", "self", ".", "_ami", ".", "getPeerStats", "(", "'iax2'", ")", "if", "stats", ":", "for", "field", "in", "(", "'online'", ",", "'unmonitored'", ",", "'unreachable'", ",", "'lagged'", ",", "'unknown'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_peers_iax2'", ",", "field", ",", "stats", ".", "get", "(", "field", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_voip_codecs'", ")", ":", "sipstats", "=", "self", ".", "_ami", ".", "getVoIPchanStats", "(", "'sip'", ",", "self", ".", "_codecList", ")", "or", "{", "}", "iax2stats", "=", "self", ".", "_ami", ".", "getVoIPchanStats", "(", "'iax2'", ",", "self", ".", "_codecList", ")", "or", "{", "}", "if", "stats", ":", "for", "field", "in", "self", ".", "_codecList", ":", "self", ".", "setGraphVal", "(", "'asterisk_voip_codecs'", ",", "field", ",", "sipstats", ".", "get", "(", "field", ",", "0", ")", "+", "iax2stats", ".", "get", "(", "field", ",", "0", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_voip_codecs'", ",", "'other'", ",", "sipstats", ".", "get", "(", "'other'", ",", "0", ")", "+", "iax2stats", ".", "get", "(", "'other'", ",", "0", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_conferences'", ")", ":", "stats", "=", "self", ".", "_ami", ".", "getConferenceStats", "(", ")", "if", "stats", ":", "self", ".", "setGraphVal", "(", "'asterisk_conferences'", ",", "'rooms'", ",", "stats", ".", "get", "(", "'active_conferences'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_conferences'", ",", "'users'", ",", "stats", ".", "get", "(", "'conference_users'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_voicemail'", ")", ":", "stats", "=", "self", ".", "_ami", ".", "getVoicemailStats", "(", ")", "if", "stats", ":", "self", ".", "setGraphVal", "(", "'asterisk_voicemail'", ",", "'accounts'", ",", "stats", ".", "get", "(", "'accounts'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_voicemail'", ",", "'msg_avg'", ",", "stats", ".", "get", "(", "'avg_messages'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_voicemail'", ",", "'msg_max'", ",", "stats", ".", "get", "(", "'max_messages'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_voicemail'", ",", "'msg_total'", ",", "stats", ".", "get", "(", "'total_messages'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_trunks'", ")", "and", "len", "(", "self", ".", "_trunkList", ")", ">", "0", ":", "stats", "=", "self", ".", "_ami", ".", "getTrunkStats", "(", "self", ".", "_trunkList", ")", "for", "trunk", "in", "self", ".", "_trunkList", ":", "self", ".", "setGraphVal", "(", "'asterisk_trunks'", ",", "trunk", "[", "0", "]", ",", "stats", ".", "get", "(", "trunk", "[", "0", "]", ")", ")", "if", "self", ".", "_queues", "is", "not", "None", ":", "total_answer", "=", "0", "total_abandon", "=", "0", "for", "queue", "in", "self", ".", "_queue_list", ":", "stats", "=", "self", ".", "_queues", "[", "queue", "]", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_len'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_queue_len'", ",", "queue", ",", "stats", ".", "get", "(", "'queue_len'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_avg_hold'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_queue_avg_hold'", ",", "queue", ",", "stats", ".", "get", "(", "'avg_holdtime'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_avg_talk'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_queue_avg_talk'", ",", "queue", ",", "stats", ".", "get", "(", "'avg_talktime'", ")", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_calls'", ")", ":", "total_abandon", "+=", "stats", ".", "get", "(", "'calls_abandoned'", ")", "total_answer", "+=", "stats", ".", "get", "(", "'calls_completed'", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_abandon_pcent'", ")", ":", "prev_stats", "=", "self", ".", "_queues_prev", ".", "get", "(", "queue", ")", "if", "prev_stats", "is", "not", "None", ":", "abandon", "=", "(", "stats", ".", "get", "(", "'calls_abandoned'", ",", "0", ")", "-", "prev_stats", ".", "get", "(", "'calls_abandoned'", ",", "0", ")", ")", "answer", "=", "(", "stats", ".", "get", "(", "'calls_completed'", ",", "0", ")", "-", "prev_stats", ".", "get", "(", "'calls_completed'", ",", "0", ")", ")", "total", "=", "abandon", "+", "answer", "if", "total", ">", "0", ":", "val", "=", "100.0", "*", "float", "(", "abandon", ")", "/", "float", "(", "total", ")", "else", ":", "val", "=", "0", "self", ".", "setGraphVal", "(", "'asterisk_queue_abandon_pcent'", ",", "queue", ",", "val", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_queue_calls'", ")", ":", "self", ".", "setGraphVal", "(", "'asterisk_queue_calls'", ",", "'abandon'", ",", "total_abandon", ")", "self", ".", "setGraphVal", "(", "'asterisk_queue_calls'", ",", "'answer'", ",", "total_answer", ")", "if", "self", ".", "hasGraph", "(", "'asterisk_fax_attempts'", ")", ":", "fax_stats", "=", "self", ".", "_ami", ".", "getFaxStatsCounters", "(", ")", "stats", "=", "fax_stats", ".", "get", "(", "'general'", ")", "if", "stats", "is", "not", "None", ":", "self", ".", "setGraphVal", "(", "'asterisk_fax_attempts'", ",", "'send'", ",", "stats", ".", "get", "(", "'transmit attempts'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_fax_attempts'", ",", "'recv'", ",", "stats", ".", "get", "(", "'receive attempts'", ")", ")", "self", ".", "setGraphVal", "(", "'asterisk_fax_attempts'", ",", "'fail'", ",", "stats", ".", "get", "(", "'failed faxes'", ")", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/asteriskstats.py#L309-L426
train
aouyar/PyMunin
pymunin/plugins/phpfpmstats.py
MuninPHPfpmPlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" fpminfo = PHPfpmInfo(self._host, self._port, self._user, self._password, self._monpath, self._ssl) stats = fpminfo.getStats() if self.hasGraph('php_fpm_connections') and stats: self.setGraphVal('php_fpm_connections', 'conn', stats['accepted conn']) if self.hasGraph('php_fpm_processes') and stats: self.setGraphVal('php_fpm_processes', 'active', stats['active processes']) self.setGraphVal('php_fpm_processes', 'idle', stats['idle processes']) self.setGraphVal('php_fpm_processes', 'total', stats['total processes'])
python
def retrieveVals(self): """Retrieve values for graphs.""" fpminfo = PHPfpmInfo(self._host, self._port, self._user, self._password, self._monpath, self._ssl) stats = fpminfo.getStats() if self.hasGraph('php_fpm_connections') and stats: self.setGraphVal('php_fpm_connections', 'conn', stats['accepted conn']) if self.hasGraph('php_fpm_processes') and stats: self.setGraphVal('php_fpm_processes', 'active', stats['active processes']) self.setGraphVal('php_fpm_processes', 'idle', stats['idle processes']) self.setGraphVal('php_fpm_processes', 'total', stats['total processes'])
[ "def", "retrieveVals", "(", "self", ")", ":", "fpminfo", "=", "PHPfpmInfo", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_user", ",", "self", ".", "_password", ",", "self", ".", "_monpath", ",", "self", ".", "_ssl", ")", "stats", "=", "fpminfo", ".", "getStats", "(", ")", "if", "self", ".", "hasGraph", "(", "'php_fpm_connections'", ")", "and", "stats", ":", "self", ".", "setGraphVal", "(", "'php_fpm_connections'", ",", "'conn'", ",", "stats", "[", "'accepted conn'", "]", ")", "if", "self", ".", "hasGraph", "(", "'php_fpm_processes'", ")", "and", "stats", ":", "self", ".", "setGraphVal", "(", "'php_fpm_processes'", ",", "'active'", ",", "stats", "[", "'active processes'", "]", ")", "self", ".", "setGraphVal", "(", "'php_fpm_processes'", ",", "'idle'", ",", "stats", "[", "'idle processes'", "]", ")", "self", ".", "setGraphVal", "(", "'php_fpm_processes'", ",", "'total'", ",", "stats", "[", "'total processes'", "]", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/phpfpmstats.py#L111-L125
train
aouyar/PyMunin
pymunin/plugins/phpfpmstats.py
MuninPHPfpmPlugin.autoconf
def autoconf(self): """Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise. """ fpminfo = PHPfpmInfo(self._host, self._port, self._user, self._password, self._monpath, self._ssl) return fpminfo is not None
python
def autoconf(self): """Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise. """ fpminfo = PHPfpmInfo(self._host, self._port, self._user, self._password, self._monpath, self._ssl) return fpminfo is not None
[ "def", "autoconf", "(", "self", ")", ":", "fpminfo", "=", "PHPfpmInfo", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_user", ",", "self", ".", "_password", ",", "self", ".", "_monpath", ",", "self", ".", "_ssl", ")", "return", "fpminfo", "is", "not", "None" ]
Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise.
[ "Implements", "Munin", "Plugin", "Auto", "-", "Configuration", "Option", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/phpfpmstats.py#L127-L135
train
aouyar/PyMunin
pysysinfo/redisdb.py
RedisInfo.ping
def ping(self): """Ping Redis Server and return Round-Trip-Time in seconds. @return: Round-trip-time in seconds as float. """ start = time.time() self._conn.ping() return (time.time() - start)
python
def ping(self): """Ping Redis Server and return Round-Trip-Time in seconds. @return: Round-trip-time in seconds as float. """ start = time.time() self._conn.ping() return (time.time() - start)
[ "def", "ping", "(", "self", ")", ":", "start", "=", "time", ".", "time", "(", ")", "self", ".", "_conn", ".", "ping", "(", ")", "return", "(", "time", ".", "time", "(", ")", "-", "start", ")" ]
Ping Redis Server and return Round-Trip-Time in seconds. @return: Round-trip-time in seconds as float.
[ "Ping", "Redis", "Server", "and", "return", "Round", "-", "Trip", "-", "Time", "in", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/redisdb.py#L49-L57
train
ContextLab/quail
quail/helpers.py
list2pd
def list2pd(all_data, subjindex=None, listindex=None): """ Makes multi-indexed dataframe of subject data Parameters ---------- all_data : list of lists of strings strings are either all presented or all recalled items, in the order of presentation or recall *should also work for presented / recalled ints and floats, if desired Returns ---------- subs_list_of_dfs : multi-indexed dataframe dataframe of subject data (presented or recalled words/items), indexed by subject and list number cell populated by the term presented or recalled in the position indicated by the column number """ # set default index if it is not defined # max_nlists = max(map(lambda x: len(x), all_data)) listindex = [[idx for idx in range(len(sub))] for sub in all_data] if not listindex else listindex subjindex = [idx for idx,subj in enumerate(all_data)] if not subjindex else subjindex def make_multi_index(listindex, sub_num): return pd.MultiIndex.from_tuples([(sub_num,lst) for lst in listindex], names = ['Subject', 'List']) listindex = list(listindex) subjindex = list(subjindex) subs_list_of_dfs = [pd.DataFrame(sub_data, index=make_multi_index(listindex[sub_num], subjindex[sub_num])) for sub_num,sub_data in enumerate(all_data)] return pd.concat(subs_list_of_dfs)
python
def list2pd(all_data, subjindex=None, listindex=None): """ Makes multi-indexed dataframe of subject data Parameters ---------- all_data : list of lists of strings strings are either all presented or all recalled items, in the order of presentation or recall *should also work for presented / recalled ints and floats, if desired Returns ---------- subs_list_of_dfs : multi-indexed dataframe dataframe of subject data (presented or recalled words/items), indexed by subject and list number cell populated by the term presented or recalled in the position indicated by the column number """ # set default index if it is not defined # max_nlists = max(map(lambda x: len(x), all_data)) listindex = [[idx for idx in range(len(sub))] for sub in all_data] if not listindex else listindex subjindex = [idx for idx,subj in enumerate(all_data)] if not subjindex else subjindex def make_multi_index(listindex, sub_num): return pd.MultiIndex.from_tuples([(sub_num,lst) for lst in listindex], names = ['Subject', 'List']) listindex = list(listindex) subjindex = list(subjindex) subs_list_of_dfs = [pd.DataFrame(sub_data, index=make_multi_index(listindex[sub_num], subjindex[sub_num])) for sub_num,sub_data in enumerate(all_data)] return pd.concat(subs_list_of_dfs)
[ "def", "list2pd", "(", "all_data", ",", "subjindex", "=", "None", ",", "listindex", "=", "None", ")", ":", "# set default index if it is not defined", "# max_nlists = max(map(lambda x: len(x), all_data))", "listindex", "=", "[", "[", "idx", "for", "idx", "in", "range", "(", "len", "(", "sub", ")", ")", "]", "for", "sub", "in", "all_data", "]", "if", "not", "listindex", "else", "listindex", "subjindex", "=", "[", "idx", "for", "idx", ",", "subj", "in", "enumerate", "(", "all_data", ")", "]", "if", "not", "subjindex", "else", "subjindex", "def", "make_multi_index", "(", "listindex", ",", "sub_num", ")", ":", "return", "pd", ".", "MultiIndex", ".", "from_tuples", "(", "[", "(", "sub_num", ",", "lst", ")", "for", "lst", "in", "listindex", "]", ",", "names", "=", "[", "'Subject'", ",", "'List'", "]", ")", "listindex", "=", "list", "(", "listindex", ")", "subjindex", "=", "list", "(", "subjindex", ")", "subs_list_of_dfs", "=", "[", "pd", ".", "DataFrame", "(", "sub_data", ",", "index", "=", "make_multi_index", "(", "listindex", "[", "sub_num", "]", ",", "subjindex", "[", "sub_num", "]", ")", ")", "for", "sub_num", ",", "sub_data", "in", "enumerate", "(", "all_data", ")", "]", "return", "pd", ".", "concat", "(", "subs_list_of_dfs", ")" ]
Makes multi-indexed dataframe of subject data Parameters ---------- all_data : list of lists of strings strings are either all presented or all recalled items, in the order of presentation or recall *should also work for presented / recalled ints and floats, if desired Returns ---------- subs_list_of_dfs : multi-indexed dataframe dataframe of subject data (presented or recalled words/items), indexed by subject and list number cell populated by the term presented or recalled in the position indicated by the column number
[ "Makes", "multi", "-", "indexed", "dataframe", "of", "subject", "data" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L11-L43
train
ContextLab/quail
quail/helpers.py
recmat2egg
def recmat2egg(recmat, list_length=None): """ Creates egg data object from zero-indexed recall matrix Parameters ---------- recmat : list of lists (subs) of lists (encoding lists) of ints or 2D numpy array recall matrix representing serial positions of freely recalled words \ e.g. [[[16, 15, 0, 2, 3, None, None...], [16, 4, 5, 6, 1, None, None...]]] list_length : int The length of each list (e.g. 16) Returns ---------- egg : Egg data object egg data object computed from the recall matrix """ from .egg import Egg as Egg pres = [[[str(word) for word in list(range(0,list_length))] for reclist in recsub] for recsub in recmat] rec = [[[str(word) for word in reclist if word is not None] for reclist in recsub] for recsub in recmat] return Egg(pres=pres,rec=rec)
python
def recmat2egg(recmat, list_length=None): """ Creates egg data object from zero-indexed recall matrix Parameters ---------- recmat : list of lists (subs) of lists (encoding lists) of ints or 2D numpy array recall matrix representing serial positions of freely recalled words \ e.g. [[[16, 15, 0, 2, 3, None, None...], [16, 4, 5, 6, 1, None, None...]]] list_length : int The length of each list (e.g. 16) Returns ---------- egg : Egg data object egg data object computed from the recall matrix """ from .egg import Egg as Egg pres = [[[str(word) for word in list(range(0,list_length))] for reclist in recsub] for recsub in recmat] rec = [[[str(word) for word in reclist if word is not None] for reclist in recsub] for recsub in recmat] return Egg(pres=pres,rec=rec)
[ "def", "recmat2egg", "(", "recmat", ",", "list_length", "=", "None", ")", ":", "from", ".", "egg", "import", "Egg", "as", "Egg", "pres", "=", "[", "[", "[", "str", "(", "word", ")", "for", "word", "in", "list", "(", "range", "(", "0", ",", "list_length", ")", ")", "]", "for", "reclist", "in", "recsub", "]", "for", "recsub", "in", "recmat", "]", "rec", "=", "[", "[", "[", "str", "(", "word", ")", "for", "word", "in", "reclist", "if", "word", "is", "not", "None", "]", "for", "reclist", "in", "recsub", "]", "for", "recsub", "in", "recmat", "]", "return", "Egg", "(", "pres", "=", "pres", ",", "rec", "=", "rec", ")" ]
Creates egg data object from zero-indexed recall matrix Parameters ---------- recmat : list of lists (subs) of lists (encoding lists) of ints or 2D numpy array recall matrix representing serial positions of freely recalled words \ e.g. [[[16, 15, 0, 2, 3, None, None...], [16, 4, 5, 6, 1, None, None...]]] list_length : int The length of each list (e.g. 16) Returns ---------- egg : Egg data object egg data object computed from the recall matrix
[ "Creates", "egg", "data", "object", "from", "zero", "-", "indexed", "recall", "matrix" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L72-L96
train
ContextLab/quail
quail/helpers.py
default_dist_funcs
def default_dist_funcs(dist_funcs, feature_example): """ Fills in default distance metrics for fingerprint analyses """ if dist_funcs is None: dist_funcs = dict() for key in feature_example: if key in dist_funcs: pass if key == 'item': pass elif isinstance(feature_example[key], (six.string_types, six.binary_type)): dist_funcs[key] = 'match' elif isinstance(feature_example[key], (int, np.integer, float)) or all([isinstance(i, (int, np.integer, float)) for i in feature_example[key]]): dist_funcs[key] = 'euclidean' return dist_funcs
python
def default_dist_funcs(dist_funcs, feature_example): """ Fills in default distance metrics for fingerprint analyses """ if dist_funcs is None: dist_funcs = dict() for key in feature_example: if key in dist_funcs: pass if key == 'item': pass elif isinstance(feature_example[key], (six.string_types, six.binary_type)): dist_funcs[key] = 'match' elif isinstance(feature_example[key], (int, np.integer, float)) or all([isinstance(i, (int, np.integer, float)) for i in feature_example[key]]): dist_funcs[key] = 'euclidean' return dist_funcs
[ "def", "default_dist_funcs", "(", "dist_funcs", ",", "feature_example", ")", ":", "if", "dist_funcs", "is", "None", ":", "dist_funcs", "=", "dict", "(", ")", "for", "key", "in", "feature_example", ":", "if", "key", "in", "dist_funcs", ":", "pass", "if", "key", "==", "'item'", ":", "pass", "elif", "isinstance", "(", "feature_example", "[", "key", "]", ",", "(", "six", ".", "string_types", ",", "six", ".", "binary_type", ")", ")", ":", "dist_funcs", "[", "key", "]", "=", "'match'", "elif", "isinstance", "(", "feature_example", "[", "key", "]", ",", "(", "int", ",", "np", ".", "integer", ",", "float", ")", ")", "or", "all", "(", "[", "isinstance", "(", "i", ",", "(", "int", ",", "np", ".", "integer", ",", "float", ")", ")", "for", "i", "in", "feature_example", "[", "key", "]", "]", ")", ":", "dist_funcs", "[", "key", "]", "=", "'euclidean'", "return", "dist_funcs" ]
Fills in default distance metrics for fingerprint analyses
[ "Fills", "in", "default", "distance", "metrics", "for", "fingerprint", "analyses" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L98-L116
train
ContextLab/quail
quail/helpers.py
stack_eggs
def stack_eggs(eggs, meta='concatenate'): ''' Takes a list of eggs, stacks them and reindexes the subject number Parameters ---------- eggs : list of Egg data objects A list of Eggs that you want to combine meta : string Determines how the meta data of each Egg combines. Default is 'concatenate' 'concatenate' concatenates keys in meta data dictionary shared between eggs, and copies non-overlapping keys 'separate' keeps the Eggs' meta data dictionaries separate, with each as a list index in the stacked meta data Returns ---------- new_egg : Egg data object A mega egg comprised of the input eggs stacked together ''' from .egg import Egg pres = [egg.pres.loc[sub,:].values.tolist() for egg in eggs for sub in egg.pres.index.levels[0].values.tolist()] rec = [egg.rec.loc[sub,:].values.tolist() for egg in eggs for sub in egg.rec.index.levels[0].values.tolist()] if meta is 'concatenate': new_meta = {} for egg in eggs: for key in egg.meta: if key in new_meta: new_meta[key] = list(new_meta[key]) new_meta[key].extend(egg.meta.get(key)) else: new_meta[key] = egg.meta.get(key) elif meta is 'separate': new_meta = list(egg.meta for egg in eggs) return Egg(pres=pres, rec=rec, meta=new_meta)
python
def stack_eggs(eggs, meta='concatenate'): ''' Takes a list of eggs, stacks them and reindexes the subject number Parameters ---------- eggs : list of Egg data objects A list of Eggs that you want to combine meta : string Determines how the meta data of each Egg combines. Default is 'concatenate' 'concatenate' concatenates keys in meta data dictionary shared between eggs, and copies non-overlapping keys 'separate' keeps the Eggs' meta data dictionaries separate, with each as a list index in the stacked meta data Returns ---------- new_egg : Egg data object A mega egg comprised of the input eggs stacked together ''' from .egg import Egg pres = [egg.pres.loc[sub,:].values.tolist() for egg in eggs for sub in egg.pres.index.levels[0].values.tolist()] rec = [egg.rec.loc[sub,:].values.tolist() for egg in eggs for sub in egg.rec.index.levels[0].values.tolist()] if meta is 'concatenate': new_meta = {} for egg in eggs: for key in egg.meta: if key in new_meta: new_meta[key] = list(new_meta[key]) new_meta[key].extend(egg.meta.get(key)) else: new_meta[key] = egg.meta.get(key) elif meta is 'separate': new_meta = list(egg.meta for egg in eggs) return Egg(pres=pres, rec=rec, meta=new_meta)
[ "def", "stack_eggs", "(", "eggs", ",", "meta", "=", "'concatenate'", ")", ":", "from", ".", "egg", "import", "Egg", "pres", "=", "[", "egg", ".", "pres", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "egg", "in", "eggs", "for", "sub", "in", "egg", ".", "pres", ".", "index", ".", "levels", "[", "0", "]", ".", "values", ".", "tolist", "(", ")", "]", "rec", "=", "[", "egg", ".", "rec", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "egg", "in", "eggs", "for", "sub", "in", "egg", ".", "rec", ".", "index", ".", "levels", "[", "0", "]", ".", "values", ".", "tolist", "(", ")", "]", "if", "meta", "is", "'concatenate'", ":", "new_meta", "=", "{", "}", "for", "egg", "in", "eggs", ":", "for", "key", "in", "egg", ".", "meta", ":", "if", "key", "in", "new_meta", ":", "new_meta", "[", "key", "]", "=", "list", "(", "new_meta", "[", "key", "]", ")", "new_meta", "[", "key", "]", ".", "extend", "(", "egg", ".", "meta", ".", "get", "(", "key", ")", ")", "else", ":", "new_meta", "[", "key", "]", "=", "egg", ".", "meta", ".", "get", "(", "key", ")", "elif", "meta", "is", "'separate'", ":", "new_meta", "=", "list", "(", "egg", ".", "meta", "for", "egg", "in", "eggs", ")", "return", "Egg", "(", "pres", "=", "pres", ",", "rec", "=", "rec", ",", "meta", "=", "new_meta", ")" ]
Takes a list of eggs, stacks them and reindexes the subject number Parameters ---------- eggs : list of Egg data objects A list of Eggs that you want to combine meta : string Determines how the meta data of each Egg combines. Default is 'concatenate' 'concatenate' concatenates keys in meta data dictionary shared between eggs, and copies non-overlapping keys 'separate' keeps the Eggs' meta data dictionaries separate, with each as a list index in the stacked meta data Returns ---------- new_egg : Egg data object A mega egg comprised of the input eggs stacked together
[ "Takes", "a", "list", "of", "eggs", "stacks", "them", "and", "reindexes", "the", "subject", "number" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L118-L156
train
ContextLab/quail
quail/helpers.py
crack_egg
def crack_egg(egg, subjects=None, lists=None): ''' Takes an egg and returns a subset of the subjects or lists Parameters ---------- egg : Egg data object Egg that you want to crack subjects : list List of subject idxs lists : list List of lists idxs Returns ---------- new_egg : Egg data object A sliced egg, good on a salad ''' from .egg import Egg if hasattr(egg, 'features'): all_have_features = egg.features is not None else: all_have_features=False opts = {} if subjects is None: subjects = egg.pres.index.levels[0].values.tolist() elif type(subjects) is not list: subjects = [subjects] if lists is None: lists = egg.pres.index.levels[1].values.tolist() elif type(lists) is not list: lists = [lists] idx = pd.IndexSlice pres = egg.pres.loc[idx[subjects,lists],egg.pres.columns] rec = egg.rec.loc[idx[subjects,lists],egg.rec.columns] pres = [pres.loc[sub,:].values.tolist() for sub in subjects] rec = [rec.loc[sub,:].values.tolist() for sub in subjects] if all_have_features: features = egg.features.loc[idx[subjects,lists],egg.features.columns] opts['features'] = [features.loc[sub,:].values.tolist() for sub in subjects] return Egg(pres=pres, rec=rec, **opts)
python
def crack_egg(egg, subjects=None, lists=None): ''' Takes an egg and returns a subset of the subjects or lists Parameters ---------- egg : Egg data object Egg that you want to crack subjects : list List of subject idxs lists : list List of lists idxs Returns ---------- new_egg : Egg data object A sliced egg, good on a salad ''' from .egg import Egg if hasattr(egg, 'features'): all_have_features = egg.features is not None else: all_have_features=False opts = {} if subjects is None: subjects = egg.pres.index.levels[0].values.tolist() elif type(subjects) is not list: subjects = [subjects] if lists is None: lists = egg.pres.index.levels[1].values.tolist() elif type(lists) is not list: lists = [lists] idx = pd.IndexSlice pres = egg.pres.loc[idx[subjects,lists],egg.pres.columns] rec = egg.rec.loc[idx[subjects,lists],egg.rec.columns] pres = [pres.loc[sub,:].values.tolist() for sub in subjects] rec = [rec.loc[sub,:].values.tolist() for sub in subjects] if all_have_features: features = egg.features.loc[idx[subjects,lists],egg.features.columns] opts['features'] = [features.loc[sub,:].values.tolist() for sub in subjects] return Egg(pres=pres, rec=rec, **opts)
[ "def", "crack_egg", "(", "egg", ",", "subjects", "=", "None", ",", "lists", "=", "None", ")", ":", "from", ".", "egg", "import", "Egg", "if", "hasattr", "(", "egg", ",", "'features'", ")", ":", "all_have_features", "=", "egg", ".", "features", "is", "not", "None", "else", ":", "all_have_features", "=", "False", "opts", "=", "{", "}", "if", "subjects", "is", "None", ":", "subjects", "=", "egg", ".", "pres", ".", "index", ".", "levels", "[", "0", "]", ".", "values", ".", "tolist", "(", ")", "elif", "type", "(", "subjects", ")", "is", "not", "list", ":", "subjects", "=", "[", "subjects", "]", "if", "lists", "is", "None", ":", "lists", "=", "egg", ".", "pres", ".", "index", ".", "levels", "[", "1", "]", ".", "values", ".", "tolist", "(", ")", "elif", "type", "(", "lists", ")", "is", "not", "list", ":", "lists", "=", "[", "lists", "]", "idx", "=", "pd", ".", "IndexSlice", "pres", "=", "egg", ".", "pres", ".", "loc", "[", "idx", "[", "subjects", ",", "lists", "]", ",", "egg", ".", "pres", ".", "columns", "]", "rec", "=", "egg", ".", "rec", ".", "loc", "[", "idx", "[", "subjects", ",", "lists", "]", ",", "egg", ".", "rec", ".", "columns", "]", "pres", "=", "[", "pres", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "sub", "in", "subjects", "]", "rec", "=", "[", "rec", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "sub", "in", "subjects", "]", "if", "all_have_features", ":", "features", "=", "egg", ".", "features", ".", "loc", "[", "idx", "[", "subjects", ",", "lists", "]", ",", "egg", ".", "features", ".", "columns", "]", "opts", "[", "'features'", "]", "=", "[", "features", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "sub", "in", "subjects", "]", "return", "Egg", "(", "pres", "=", "pres", ",", "rec", "=", "rec", ",", "*", "*", "opts", ")" ]
Takes an egg and returns a subset of the subjects or lists Parameters ---------- egg : Egg data object Egg that you want to crack subjects : list List of subject idxs lists : list List of lists idxs Returns ---------- new_egg : Egg data object A sliced egg, good on a salad
[ "Takes", "an", "egg", "and", "returns", "a", "subset", "of", "the", "subjects", "or", "lists" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L158-L208
train
ContextLab/quail
quail/helpers.py
df2list
def df2list(df): """ Convert a MultiIndex df to list Parameters ---------- df : pandas.DataFrame A MultiIndex DataFrame where the first level is subjects and the second level is lists (e.g. egg.pres) Returns ---------- lst : a list of lists of lists of values The input df reformatted as a list """ subjects = df.index.levels[0].values.tolist() lists = df.index.levels[1].values.tolist() idx = pd.IndexSlice df = df.loc[idx[subjects,lists],df.columns] lst = [df.loc[sub,:].values.tolist() for sub in subjects] return lst
python
def df2list(df): """ Convert a MultiIndex df to list Parameters ---------- df : pandas.DataFrame A MultiIndex DataFrame where the first level is subjects and the second level is lists (e.g. egg.pres) Returns ---------- lst : a list of lists of lists of values The input df reformatted as a list """ subjects = df.index.levels[0].values.tolist() lists = df.index.levels[1].values.tolist() idx = pd.IndexSlice df = df.loc[idx[subjects,lists],df.columns] lst = [df.loc[sub,:].values.tolist() for sub in subjects] return lst
[ "def", "df2list", "(", "df", ")", ":", "subjects", "=", "df", ".", "index", ".", "levels", "[", "0", "]", ".", "values", ".", "tolist", "(", ")", "lists", "=", "df", ".", "index", ".", "levels", "[", "1", "]", ".", "values", ".", "tolist", "(", ")", "idx", "=", "pd", ".", "IndexSlice", "df", "=", "df", ".", "loc", "[", "idx", "[", "subjects", ",", "lists", "]", ",", "df", ".", "columns", "]", "lst", "=", "[", "df", ".", "loc", "[", "sub", ",", ":", "]", ".", "values", ".", "tolist", "(", ")", "for", "sub", "in", "subjects", "]", "return", "lst" ]
Convert a MultiIndex df to list Parameters ---------- df : pandas.DataFrame A MultiIndex DataFrame where the first level is subjects and the second level is lists (e.g. egg.pres) Returns ---------- lst : a list of lists of lists of values The input df reformatted as a list
[ "Convert", "a", "MultiIndex", "df", "to", "list" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L210-L233
train
ContextLab/quail
quail/helpers.py
fill_missing
def fill_missing(x): """ Fills in missing lists (assumes end lists are missing) """ # find subject with max number of lists maxlen = max([len(xi) for xi in x]) subs = [] for sub in x: if len(sub)<maxlen: for i in range(maxlen-len(sub)): sub.append([]) new_sub = sub else: new_sub = sub subs.append(new_sub) return subs
python
def fill_missing(x): """ Fills in missing lists (assumes end lists are missing) """ # find subject with max number of lists maxlen = max([len(xi) for xi in x]) subs = [] for sub in x: if len(sub)<maxlen: for i in range(maxlen-len(sub)): sub.append([]) new_sub = sub else: new_sub = sub subs.append(new_sub) return subs
[ "def", "fill_missing", "(", "x", ")", ":", "# find subject with max number of lists", "maxlen", "=", "max", "(", "[", "len", "(", "xi", ")", "for", "xi", "in", "x", "]", ")", "subs", "=", "[", "]", "for", "sub", "in", "x", ":", "if", "len", "(", "sub", ")", "<", "maxlen", ":", "for", "i", "in", "range", "(", "maxlen", "-", "len", "(", "sub", ")", ")", ":", "sub", ".", "append", "(", "[", "]", ")", "new_sub", "=", "sub", "else", ":", "new_sub", "=", "sub", "subs", ".", "append", "(", "new_sub", ")", "return", "subs" ]
Fills in missing lists (assumes end lists are missing)
[ "Fills", "in", "missing", "lists", "(", "assumes", "end", "lists", "are", "missing", ")" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L235-L253
train
ContextLab/quail
quail/helpers.py
parse_egg
def parse_egg(egg): """Parses an egg and returns fields""" pres_list = egg.get_pres_items().values[0] rec_list = egg.get_rec_items().values[0] feature_list = egg.get_pres_features().values[0] dist_funcs = egg.dist_funcs return pres_list, rec_list, feature_list, dist_funcs
python
def parse_egg(egg): """Parses an egg and returns fields""" pres_list = egg.get_pres_items().values[0] rec_list = egg.get_rec_items().values[0] feature_list = egg.get_pres_features().values[0] dist_funcs = egg.dist_funcs return pres_list, rec_list, feature_list, dist_funcs
[ "def", "parse_egg", "(", "egg", ")", ":", "pres_list", "=", "egg", ".", "get_pres_items", "(", ")", ".", "values", "[", "0", "]", "rec_list", "=", "egg", ".", "get_rec_items", "(", ")", ".", "values", "[", "0", "]", "feature_list", "=", "egg", ".", "get_pres_features", "(", ")", ".", "values", "[", "0", "]", "dist_funcs", "=", "egg", ".", "dist_funcs", "return", "pres_list", ",", "rec_list", ",", "feature_list", ",", "dist_funcs" ]
Parses an egg and returns fields
[ "Parses", "an", "egg", "and", "returns", "fields" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L255-L261
train
ContextLab/quail
quail/helpers.py
merge_pres_feats
def merge_pres_feats(pres, features): """ Helper function to merge pres and features to support legacy features argument """ sub = [] for psub, fsub in zip(pres, features): exp = [] for pexp, fexp in zip(psub, fsub): lst = [] for p, f in zip(pexp, fexp): p.update(f) lst.append(p) exp.append(lst) sub.append(exp) return sub
python
def merge_pres_feats(pres, features): """ Helper function to merge pres and features to support legacy features argument """ sub = [] for psub, fsub in zip(pres, features): exp = [] for pexp, fexp in zip(psub, fsub): lst = [] for p, f in zip(pexp, fexp): p.update(f) lst.append(p) exp.append(lst) sub.append(exp) return sub
[ "def", "merge_pres_feats", "(", "pres", ",", "features", ")", ":", "sub", "=", "[", "]", "for", "psub", ",", "fsub", "in", "zip", "(", "pres", ",", "features", ")", ":", "exp", "=", "[", "]", "for", "pexp", ",", "fexp", "in", "zip", "(", "psub", ",", "fsub", ")", ":", "lst", "=", "[", "]", "for", "p", ",", "f", "in", "zip", "(", "pexp", ",", "fexp", ")", ":", "p", ".", "update", "(", "f", ")", "lst", ".", "append", "(", "p", ")", "exp", ".", "append", "(", "lst", ")", "sub", ".", "append", "(", "exp", ")", "return", "sub" ]
Helper function to merge pres and features to support legacy features argument
[ "Helper", "function", "to", "merge", "pres", "and", "features", "to", "support", "legacy", "features", "argument" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L263-L278
train
ContextLab/quail
quail/helpers.py
r2z
def r2z(r): """ Function that calculates the Fisher z-transformation Parameters ---------- r : int or ndarray Correlation value Returns ---------- result : int or ndarray Fishers z transformed correlation value """ with np.errstate(invalid='ignore', divide='ignore'): return 0.5 * (np.log(1 + r) - np.log(1 - r))
python
def r2z(r): """ Function that calculates the Fisher z-transformation Parameters ---------- r : int or ndarray Correlation value Returns ---------- result : int or ndarray Fishers z transformed correlation value """ with np.errstate(invalid='ignore', divide='ignore'): return 0.5 * (np.log(1 + r) - np.log(1 - r))
[ "def", "r2z", "(", "r", ")", ":", "with", "np", ".", "errstate", "(", "invalid", "=", "'ignore'", ",", "divide", "=", "'ignore'", ")", ":", "return", "0.5", "*", "(", "np", ".", "log", "(", "1", "+", "r", ")", "-", "np", ".", "log", "(", "1", "-", "r", ")", ")" ]
Function that calculates the Fisher z-transformation Parameters ---------- r : int or ndarray Correlation value Returns ---------- result : int or ndarray Fishers z transformed correlation value
[ "Function", "that", "calculates", "the", "Fisher", "z", "-", "transformation" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L287-L304
train
ContextLab/quail
quail/helpers.py
z2r
def z2r(z): """ Function that calculates the inverse Fisher z-transformation Parameters ---------- z : int or ndarray Fishers z transformed correlation value Returns ---------- result : int or ndarray Correlation value """ with np.errstate(invalid='ignore', divide='ignore'): return (np.exp(2 * z) - 1) / (np.exp(2 * z) + 1)
python
def z2r(z): """ Function that calculates the inverse Fisher z-transformation Parameters ---------- z : int or ndarray Fishers z transformed correlation value Returns ---------- result : int or ndarray Correlation value """ with np.errstate(invalid='ignore', divide='ignore'): return (np.exp(2 * z) - 1) / (np.exp(2 * z) + 1)
[ "def", "z2r", "(", "z", ")", ":", "with", "np", ".", "errstate", "(", "invalid", "=", "'ignore'", ",", "divide", "=", "'ignore'", ")", ":", "return", "(", "np", ".", "exp", "(", "2", "*", "z", ")", "-", "1", ")", "/", "(", "np", ".", "exp", "(", "2", "*", "z", ")", "+", "1", ")" ]
Function that calculates the inverse Fisher z-transformation Parameters ---------- z : int or ndarray Fishers z transformed correlation value Returns ---------- result : int or ndarray Correlation value
[ "Function", "that", "calculates", "the", "inverse", "Fisher", "z", "-", "transformation" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L306-L323
train
ContextLab/quail
quail/helpers.py
shuffle_egg
def shuffle_egg(egg): """ Shuffle an Egg's recalls""" from .egg import Egg pres, rec, features, dist_funcs = parse_egg(egg) if pres.ndim==1: pres = pres.reshape(1, pres.shape[0]) rec = rec.reshape(1, rec.shape[0]) features = features.reshape(1, features.shape[0]) for ilist in range(rec.shape[0]): idx = np.random.permutation(rec.shape[1]) rec[ilist,:] = rec[ilist,idx] return Egg(pres=pres, rec=rec, features=features, dist_funcs=dist_funcs)
python
def shuffle_egg(egg): """ Shuffle an Egg's recalls""" from .egg import Egg pres, rec, features, dist_funcs = parse_egg(egg) if pres.ndim==1: pres = pres.reshape(1, pres.shape[0]) rec = rec.reshape(1, rec.shape[0]) features = features.reshape(1, features.shape[0]) for ilist in range(rec.shape[0]): idx = np.random.permutation(rec.shape[1]) rec[ilist,:] = rec[ilist,idx] return Egg(pres=pres, rec=rec, features=features, dist_funcs=dist_funcs)
[ "def", "shuffle_egg", "(", "egg", ")", ":", "from", ".", "egg", "import", "Egg", "pres", ",", "rec", ",", "features", ",", "dist_funcs", "=", "parse_egg", "(", "egg", ")", "if", "pres", ".", "ndim", "==", "1", ":", "pres", "=", "pres", ".", "reshape", "(", "1", ",", "pres", ".", "shape", "[", "0", "]", ")", "rec", "=", "rec", ".", "reshape", "(", "1", ",", "rec", ".", "shape", "[", "0", "]", ")", "features", "=", "features", ".", "reshape", "(", "1", ",", "features", ".", "shape", "[", "0", "]", ")", "for", "ilist", "in", "range", "(", "rec", ".", "shape", "[", "0", "]", ")", ":", "idx", "=", "np", ".", "random", ".", "permutation", "(", "rec", ".", "shape", "[", "1", "]", ")", "rec", "[", "ilist", ",", ":", "]", "=", "rec", "[", "ilist", ",", "idx", "]", "return", "Egg", "(", "pres", "=", "pres", ",", "rec", "=", "rec", ",", "features", "=", "features", ",", "dist_funcs", "=", "dist_funcs", ")" ]
Shuffle an Egg's recalls
[ "Shuffle", "an", "Egg", "s", "recalls" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/helpers.py#L335-L349
train
aouyar/PyMunin
pymunin/plugins/netifacestats.py
MuninNetIfacePlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" for iface in self._ifaceList: stats = self._ifaceStats.get(iface) graph_name = 'netiface_traffic_%s' % iface if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'rx', stats.get('rxbytes') * 8) self.setGraphVal(graph_name, 'tx', stats.get('txbytes') * 8) graph_name = 'netiface_errors_%s' % iface if self.hasGraph(graph_name): for field in ('rxerrs', 'txerrs', 'rxframe', 'txcarrier', 'rxdrop', 'txdrop', 'rxfifo', 'txfifo'): self.setGraphVal(graph_name, field, stats.get(field))
python
def retrieveVals(self): """Retrieve values for graphs.""" for iface in self._ifaceList: stats = self._ifaceStats.get(iface) graph_name = 'netiface_traffic_%s' % iface if self.hasGraph(graph_name): self.setGraphVal(graph_name, 'rx', stats.get('rxbytes') * 8) self.setGraphVal(graph_name, 'tx', stats.get('txbytes') * 8) graph_name = 'netiface_errors_%s' % iface if self.hasGraph(graph_name): for field in ('rxerrs', 'txerrs', 'rxframe', 'txcarrier', 'rxdrop', 'txdrop', 'rxfifo', 'txfifo'): self.setGraphVal(graph_name, field, stats.get(field))
[ "def", "retrieveVals", "(", "self", ")", ":", "for", "iface", "in", "self", ".", "_ifaceList", ":", "stats", "=", "self", ".", "_ifaceStats", ".", "get", "(", "iface", ")", "graph_name", "=", "'netiface_traffic_%s'", "%", "iface", "if", "self", ".", "hasGraph", "(", "graph_name", ")", ":", "self", ".", "setGraphVal", "(", "graph_name", ",", "'rx'", ",", "stats", ".", "get", "(", "'rxbytes'", ")", "*", "8", ")", "self", ".", "setGraphVal", "(", "graph_name", ",", "'tx'", ",", "stats", ".", "get", "(", "'txbytes'", ")", "*", "8", ")", "graph_name", "=", "'netiface_errors_%s'", "%", "iface", "if", "self", ".", "hasGraph", "(", "graph_name", ")", ":", "for", "field", "in", "(", "'rxerrs'", ",", "'txerrs'", ",", "'rxframe'", ",", "'txcarrier'", ",", "'rxdrop'", ",", "'txdrop'", ",", "'rxfifo'", ",", "'txfifo'", ")", ":", "self", ".", "setGraphVal", "(", "graph_name", ",", "field", ",", "stats", ".", "get", "(", "field", ")", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/netifacestats.py#L122-L134
train
aouyar/PyMunin
pysysinfo/ntp.py
NTPinfo.getPeerStats
def getPeerStats(self): """Get NTP Peer Stats for localhost by querying local NTP Server. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpqCmd, '-n', '-c', 'peers']) for line in output.splitlines(): mobj = re.match('\*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+', line) if mobj: info_dict['ip'] = mobj.group(1) cols = line.split() info_dict['stratum'] = int(cols[2]) info_dict['delay'] = float(cols[7]) / 1000.0 info_dict['offset'] = float(cols[8]) / 1000.0 info_dict['jitter'] = float(cols[9]) / 1000.0 return info_dict else: raise Exception("Execution of command failed: %s" % ntpqCmd) return info_dict
python
def getPeerStats(self): """Get NTP Peer Stats for localhost by querying local NTP Server. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpqCmd, '-n', '-c', 'peers']) for line in output.splitlines(): mobj = re.match('\*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+', line) if mobj: info_dict['ip'] = mobj.group(1) cols = line.split() info_dict['stratum'] = int(cols[2]) info_dict['delay'] = float(cols[7]) / 1000.0 info_dict['offset'] = float(cols[8]) / 1000.0 info_dict['jitter'] = float(cols[9]) / 1000.0 return info_dict else: raise Exception("Execution of command failed: %s" % ntpqCmd) return info_dict
[ "def", "getPeerStats", "(", "self", ")", ":", "info_dict", "=", "{", "}", "output", "=", "util", ".", "exec_command", "(", "[", "ntpqCmd", ",", "'-n'", ",", "'-c'", ",", "'peers'", "]", ")", "for", "line", "in", "output", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'\\*(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\s+'", ",", "line", ")", "if", "mobj", ":", "info_dict", "[", "'ip'", "]", "=", "mobj", ".", "group", "(", "1", ")", "cols", "=", "line", ".", "split", "(", ")", "info_dict", "[", "'stratum'", "]", "=", "int", "(", "cols", "[", "2", "]", ")", "info_dict", "[", "'delay'", "]", "=", "float", "(", "cols", "[", "7", "]", ")", "/", "1000.0", "info_dict", "[", "'offset'", "]", "=", "float", "(", "cols", "[", "8", "]", ")", "/", "1000.0", "info_dict", "[", "'jitter'", "]", "=", "float", "(", "cols", "[", "9", "]", ")", "/", "1000.0", "return", "info_dict", "else", ":", "raise", "Exception", "(", "\"Execution of command failed: %s\"", "%", "ntpqCmd", ")", "return", "info_dict" ]
Get NTP Peer Stats for localhost by querying local NTP Server. @return: Dictionary of NTP stats converted to seconds.
[ "Get", "NTP", "Peer", "Stats", "for", "localhost", "by", "querying", "local", "NTP", "Server", ".", "@return", ":", "Dictionary", "of", "NTP", "stats", "converted", "to", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/ntp.py#L29-L49
train
aouyar/PyMunin
pysysinfo/ntp.py
NTPinfo.getHostOffset
def getHostOffset(self, host): """Get NTP Stats and offset of remote host relative to localhost by querying NTP Server on remote host. @param host: Remote Host IP. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpdateCmd, '-u', '-q', host]) for line in output.splitlines(): mobj = re.match('server.*,\s*stratum\s+(\d),.*' 'offset\s+([\d\.-]+),.*delay\s+([\d\.]+)\s*$', line) if mobj: info_dict['stratum'] = int(mobj.group(1)) info_dict['delay'] = float(mobj.group(3)) info_dict['offset'] = float(mobj.group(2)) return info_dict return info_dict
python
def getHostOffset(self, host): """Get NTP Stats and offset of remote host relative to localhost by querying NTP Server on remote host. @param host: Remote Host IP. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpdateCmd, '-u', '-q', host]) for line in output.splitlines(): mobj = re.match('server.*,\s*stratum\s+(\d),.*' 'offset\s+([\d\.-]+),.*delay\s+([\d\.]+)\s*$', line) if mobj: info_dict['stratum'] = int(mobj.group(1)) info_dict['delay'] = float(mobj.group(3)) info_dict['offset'] = float(mobj.group(2)) return info_dict return info_dict
[ "def", "getHostOffset", "(", "self", ",", "host", ")", ":", "info_dict", "=", "{", "}", "output", "=", "util", ".", "exec_command", "(", "[", "ntpdateCmd", ",", "'-u'", ",", "'-q'", ",", "host", "]", ")", "for", "line", "in", "output", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'server.*,\\s*stratum\\s+(\\d),.*'", "'offset\\s+([\\d\\.-]+),.*delay\\s+([\\d\\.]+)\\s*$'", ",", "line", ")", "if", "mobj", ":", "info_dict", "[", "'stratum'", "]", "=", "int", "(", "mobj", ".", "group", "(", "1", ")", ")", "info_dict", "[", "'delay'", "]", "=", "float", "(", "mobj", ".", "group", "(", "3", ")", ")", "info_dict", "[", "'offset'", "]", "=", "float", "(", "mobj", ".", "group", "(", "2", ")", ")", "return", "info_dict", "return", "info_dict" ]
Get NTP Stats and offset of remote host relative to localhost by querying NTP Server on remote host. @param host: Remote Host IP. @return: Dictionary of NTP stats converted to seconds.
[ "Get", "NTP", "Stats", "and", "offset", "of", "remote", "host", "relative", "to", "localhost", "by", "querying", "NTP", "Server", "on", "remote", "host", ".", "@param", "host", ":", "Remote", "Host", "IP", ".", "@return", ":", "Dictionary", "of", "NTP", "stats", "converted", "to", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/ntp.py#L51-L70
train
aouyar/PyMunin
pysysinfo/ntp.py
NTPinfo.getHostOffsets
def getHostOffsets(self, hosts): """Get NTP Stats and offset of multiple remote hosts relative to localhost by querying NTP Servers on remote hosts. @param host: List of Remote Host IPs. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpdateCmd, '-u', '-q'] + list(hosts)) for line in output.splitlines(): mobj = re.match('server\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}),' '\s*stratum\s+(\d),.*offset\s+([\d\.-]+),' '.*delay\s+([\d\.]+)\s*$', line) if mobj: host_dict = {} host = mobj.group(1) host_dict['stratum'] = int(mobj.group(2)) host_dict['delay'] = float(mobj.group(4)) host_dict['offset'] = float(mobj.group(3)) info_dict[host] = host_dict return info_dict
python
def getHostOffsets(self, hosts): """Get NTP Stats and offset of multiple remote hosts relative to localhost by querying NTP Servers on remote hosts. @param host: List of Remote Host IPs. @return: Dictionary of NTP stats converted to seconds. """ info_dict = {} output = util.exec_command([ntpdateCmd, '-u', '-q'] + list(hosts)) for line in output.splitlines(): mobj = re.match('server\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}),' '\s*stratum\s+(\d),.*offset\s+([\d\.-]+),' '.*delay\s+([\d\.]+)\s*$', line) if mobj: host_dict = {} host = mobj.group(1) host_dict['stratum'] = int(mobj.group(2)) host_dict['delay'] = float(mobj.group(4)) host_dict['offset'] = float(mobj.group(3)) info_dict[host] = host_dict return info_dict
[ "def", "getHostOffsets", "(", "self", ",", "hosts", ")", ":", "info_dict", "=", "{", "}", "output", "=", "util", ".", "exec_command", "(", "[", "ntpdateCmd", ",", "'-u'", ",", "'-q'", "]", "+", "list", "(", "hosts", ")", ")", "for", "line", "in", "output", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'server\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}),'", "'\\s*stratum\\s+(\\d),.*offset\\s+([\\d\\.-]+),'", "'.*delay\\s+([\\d\\.]+)\\s*$'", ",", "line", ")", "if", "mobj", ":", "host_dict", "=", "{", "}", "host", "=", "mobj", ".", "group", "(", "1", ")", "host_dict", "[", "'stratum'", "]", "=", "int", "(", "mobj", ".", "group", "(", "2", ")", ")", "host_dict", "[", "'delay'", "]", "=", "float", "(", "mobj", ".", "group", "(", "4", ")", ")", "host_dict", "[", "'offset'", "]", "=", "float", "(", "mobj", ".", "group", "(", "3", ")", ")", "info_dict", "[", "host", "]", "=", "host_dict", "return", "info_dict" ]
Get NTP Stats and offset of multiple remote hosts relative to localhost by querying NTP Servers on remote hosts. @param host: List of Remote Host IPs. @return: Dictionary of NTP stats converted to seconds.
[ "Get", "NTP", "Stats", "and", "offset", "of", "multiple", "remote", "hosts", "relative", "to", "localhost", "by", "querying", "NTP", "Servers", "on", "remote", "hosts", ".", "@param", "host", ":", "List", "of", "Remote", "Host", "IPs", ".", "@return", ":", "Dictionary", "of", "NTP", "stats", "converted", "to", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/ntp.py#L72-L93
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getUptime
def getUptime(self): """Return system uptime in seconds. @return: Float that represents uptime in seconds. """ try: fp = open(uptimeFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % uptimeFile) return float(line.split()[0])
python
def getUptime(self): """Return system uptime in seconds. @return: Float that represents uptime in seconds. """ try: fp = open(uptimeFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % uptimeFile) return float(line.split()[0])
[ "def", "getUptime", "(", "self", ")", ":", "try", ":", "fp", "=", "open", "(", "uptimeFile", ",", "'r'", ")", "line", "=", "fp", ".", "readline", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "uptimeFile", ")", "return", "float", "(", "line", ".", "split", "(", ")", "[", "0", "]", ")" ]
Return system uptime in seconds. @return: Float that represents uptime in seconds.
[ "Return", "system", "uptime", "in", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L46-L58
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getLoadAvg
def getLoadAvg(self): """Return system Load Average. @return: List of 1 min, 5 min and 15 min Load Average figures. """ try: fp = open(loadavgFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % loadavgFile) arr = line.split() if len(arr) >= 3: return [float(col) for col in arr[:3]] else: return None
python
def getLoadAvg(self): """Return system Load Average. @return: List of 1 min, 5 min and 15 min Load Average figures. """ try: fp = open(loadavgFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % loadavgFile) arr = line.split() if len(arr) >= 3: return [float(col) for col in arr[:3]] else: return None
[ "def", "getLoadAvg", "(", "self", ")", ":", "try", ":", "fp", "=", "open", "(", "loadavgFile", ",", "'r'", ")", "line", "=", "fp", ".", "readline", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "loadavgFile", ")", "arr", "=", "line", ".", "split", "(", ")", "if", "len", "(", "arr", ")", ">=", "3", ":", "return", "[", "float", "(", "col", ")", "for", "col", "in", "arr", "[", ":", "3", "]", "]", "else", ":", "return", "None" ]
Return system Load Average. @return: List of 1 min, 5 min and 15 min Load Average figures.
[ "Return", "system", "Load", "Average", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L60-L76
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getCPUuse
def getCPUuse(self): """Return cpu time utilization in seconds. @return: Dictionary of stats. """ hz = os.sysconf('SC_CLK_TCK') info_dict = {} try: fp = open(cpustatFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % cpustatFile) headers = ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq', 'steal', 'guest'] arr = line.split() if len(arr) > 1 and arr[0] == 'cpu': return dict(zip(headers[0:len(arr)], [(float(t) / hz) for t in arr[1:]])) return info_dict
python
def getCPUuse(self): """Return cpu time utilization in seconds. @return: Dictionary of stats. """ hz = os.sysconf('SC_CLK_TCK') info_dict = {} try: fp = open(cpustatFile, 'r') line = fp.readline() fp.close() except: raise IOError('Failed reading stats from file: %s' % cpustatFile) headers = ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq', 'steal', 'guest'] arr = line.split() if len(arr) > 1 and arr[0] == 'cpu': return dict(zip(headers[0:len(arr)], [(float(t) / hz) for t in arr[1:]])) return info_dict
[ "def", "getCPUuse", "(", "self", ")", ":", "hz", "=", "os", ".", "sysconf", "(", "'SC_CLK_TCK'", ")", "info_dict", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "cpustatFile", ",", "'r'", ")", "line", "=", "fp", ".", "readline", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "cpustatFile", ")", "headers", "=", "[", "'user'", ",", "'nice'", ",", "'system'", ",", "'idle'", ",", "'iowait'", ",", "'irq'", ",", "'softirq'", ",", "'steal'", ",", "'guest'", "]", "arr", "=", "line", ".", "split", "(", ")", "if", "len", "(", "arr", ")", ">", "1", "and", "arr", "[", "0", "]", "==", "'cpu'", ":", "return", "dict", "(", "zip", "(", "headers", "[", "0", ":", "len", "(", "arr", ")", "]", ",", "[", "(", "float", "(", "t", ")", "/", "hz", ")", "for", "t", "in", "arr", "[", "1", ":", "]", "]", ")", ")", "return", "info_dict" ]
Return cpu time utilization in seconds. @return: Dictionary of stats.
[ "Return", "cpu", "time", "utilization", "in", "seconds", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L78-L96
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getProcessStats
def getProcessStats(self): """Return stats for running and blocked processes, forks, context switches and interrupts. @return: Dictionary of stats. """ info_dict = {} try: fp = open(cpustatFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % cpustatFile) for line in data.splitlines(): arr = line.split() if len(arr) > 1 and arr[0] in ('ctxt', 'intr', 'softirq', 'processes', 'procs_running', 'procs_blocked'): info_dict[arr[0]] = arr[1] return info_dict
python
def getProcessStats(self): """Return stats for running and blocked processes, forks, context switches and interrupts. @return: Dictionary of stats. """ info_dict = {} try: fp = open(cpustatFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % cpustatFile) for line in data.splitlines(): arr = line.split() if len(arr) > 1 and arr[0] in ('ctxt', 'intr', 'softirq', 'processes', 'procs_running', 'procs_blocked'): info_dict[arr[0]] = arr[1] return info_dict
[ "def", "getProcessStats", "(", "self", ")", ":", "info_dict", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "cpustatFile", ",", "'r'", ")", "data", "=", "fp", ".", "read", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "cpustatFile", ")", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "arr", "=", "line", ".", "split", "(", ")", "if", "len", "(", "arr", ")", ">", "1", "and", "arr", "[", "0", "]", "in", "(", "'ctxt'", ",", "'intr'", ",", "'softirq'", ",", "'processes'", ",", "'procs_running'", ",", "'procs_blocked'", ")", ":", "info_dict", "[", "arr", "[", "0", "]", "]", "=", "arr", "[", "1", "]", "return", "info_dict" ]
Return stats for running and blocked processes, forks, context switches and interrupts. @return: Dictionary of stats.
[ "Return", "stats", "for", "running", "and", "blocked", "processes", "forks", "context", "switches", "and", "interrupts", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L98-L118
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getMemoryUse
def getMemoryUse(self): """Return stats for memory utilization. @return: Dictionary of stats. """ info_dict = {} try: fp = open(meminfoFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % meminfoFile) for line in data.splitlines(): mobj = re.match('^(.+):\s*(\d+)\s*(\w+|)\s*$', line) if mobj: if mobj.group(3).lower() == 'kb': mult = 1024 else: mult = 1 info_dict[mobj.group(1)] = int(mobj.group(2)) * mult return info_dict
python
def getMemoryUse(self): """Return stats for memory utilization. @return: Dictionary of stats. """ info_dict = {} try: fp = open(meminfoFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % meminfoFile) for line in data.splitlines(): mobj = re.match('^(.+):\s*(\d+)\s*(\w+|)\s*$', line) if mobj: if mobj.group(3).lower() == 'kb': mult = 1024 else: mult = 1 info_dict[mobj.group(1)] = int(mobj.group(2)) * mult return info_dict
[ "def", "getMemoryUse", "(", "self", ")", ":", "info_dict", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "meminfoFile", ",", "'r'", ")", "data", "=", "fp", ".", "read", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "meminfoFile", ")", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "mobj", "=", "re", ".", "match", "(", "'^(.+):\\s*(\\d+)\\s*(\\w+|)\\s*$'", ",", "line", ")", "if", "mobj", ":", "if", "mobj", ".", "group", "(", "3", ")", ".", "lower", "(", ")", "==", "'kb'", ":", "mult", "=", "1024", "else", ":", "mult", "=", "1", "info_dict", "[", "mobj", ".", "group", "(", "1", ")", "]", "=", "int", "(", "mobj", ".", "group", "(", "2", ")", ")", "*", "mult", "return", "info_dict" ]
Return stats for memory utilization. @return: Dictionary of stats.
[ "Return", "stats", "for", "memory", "utilization", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L120-L141
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getSwapStats
def getSwapStats(self): """Return information on swap partition and / or files. @return: Dictionary of stats. """ info_dict = {} try: fp = open(swapsFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % swapsFile) lines = data.splitlines() if len(lines) > 1: colnames = [name.lower() for name in lines[0].split()] for line in lines[1:]: cols = line.split() info_dict[cols[0]] = dict(zip(colnames[1:], cols[1:])) return info_dict
python
def getSwapStats(self): """Return information on swap partition and / or files. @return: Dictionary of stats. """ info_dict = {} try: fp = open(swapsFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % swapsFile) lines = data.splitlines() if len(lines) > 1: colnames = [name.lower() for name in lines[0].split()] for line in lines[1:]: cols = line.split() info_dict[cols[0]] = dict(zip(colnames[1:], cols[1:])) return info_dict
[ "def", "getSwapStats", "(", "self", ")", ":", "info_dict", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "swapsFile", ",", "'r'", ")", "data", "=", "fp", ".", "read", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "swapsFile", ")", "lines", "=", "data", ".", "splitlines", "(", ")", "if", "len", "(", "lines", ")", ">", "1", ":", "colnames", "=", "[", "name", ".", "lower", "(", ")", "for", "name", "in", "lines", "[", "0", "]", ".", "split", "(", ")", "]", "for", "line", "in", "lines", "[", "1", ":", "]", ":", "cols", "=", "line", ".", "split", "(", ")", "info_dict", "[", "cols", "[", "0", "]", "]", "=", "dict", "(", "zip", "(", "colnames", "[", "1", ":", "]", ",", "cols", "[", "1", ":", "]", ")", ")", "return", "info_dict" ]
Return information on swap partition and / or files. @return: Dictionary of stats.
[ "Return", "information", "on", "swap", "partition", "and", "/", "or", "files", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L143-L162
train
aouyar/PyMunin
pysysinfo/system.py
SystemInfo.getVMstats
def getVMstats(self): """Return stats for Virtual Memory Subsystem. @return: Dictionary of stats. """ info_dict = {} try: fp = open(vmstatFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % vmstatFile) for line in data.splitlines(): cols = line.split() if len(cols) == 2: info_dict[cols[0]] = cols[1] return info_dict
python
def getVMstats(self): """Return stats for Virtual Memory Subsystem. @return: Dictionary of stats. """ info_dict = {} try: fp = open(vmstatFile, 'r') data = fp.read() fp.close() except: raise IOError('Failed reading stats from file: %s' % vmstatFile) for line in data.splitlines(): cols = line.split() if len(cols) == 2: info_dict[cols[0]] = cols[1] return info_dict
[ "def", "getVMstats", "(", "self", ")", ":", "info_dict", "=", "{", "}", "try", ":", "fp", "=", "open", "(", "vmstatFile", ",", "'r'", ")", "data", "=", "fp", ".", "read", "(", ")", "fp", ".", "close", "(", ")", "except", ":", "raise", "IOError", "(", "'Failed reading stats from file: %s'", "%", "vmstatFile", ")", "for", "line", "in", "data", ".", "splitlines", "(", ")", ":", "cols", "=", "line", ".", "split", "(", ")", "if", "len", "(", "cols", ")", "==", "2", ":", "info_dict", "[", "cols", "[", "0", "]", "]", "=", "cols", "[", "1", "]", "return", "info_dict" ]
Return stats for Virtual Memory Subsystem. @return: Dictionary of stats.
[ "Return", "stats", "for", "Virtual", "Memory", "Subsystem", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/system.py#L164-L181
train
aouyar/PyMunin
pysysinfo/memcached.py
MemcachedInfo._connect
def _connect(self): """Connect to Memcached.""" if self._socketFile is not None: if not os.path.exists(self._socketFile): raise Exception("Socket file (%s) for Memcached Instance not found." % self._socketFile) try: if self._timeout is not None: self._conn = util.Telnet(self._host, self._port, self._socketFile, timeout) else: self._conn = util.Telnet(self._host, self._port, self._socketFile) except: raise Exception("Connection to %s failed." % self._instanceName)
python
def _connect(self): """Connect to Memcached.""" if self._socketFile is not None: if not os.path.exists(self._socketFile): raise Exception("Socket file (%s) for Memcached Instance not found." % self._socketFile) try: if self._timeout is not None: self._conn = util.Telnet(self._host, self._port, self._socketFile, timeout) else: self._conn = util.Telnet(self._host, self._port, self._socketFile) except: raise Exception("Connection to %s failed." % self._instanceName)
[ "def", "_connect", "(", "self", ")", ":", "if", "self", ".", "_socketFile", "is", "not", "None", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "_socketFile", ")", ":", "raise", "Exception", "(", "\"Socket file (%s) for Memcached Instance not found.\"", "%", "self", ".", "_socketFile", ")", "try", ":", "if", "self", ".", "_timeout", "is", "not", "None", ":", "self", ".", "_conn", "=", "util", ".", "Telnet", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_socketFile", ",", "timeout", ")", "else", ":", "self", ".", "_conn", "=", "util", ".", "Telnet", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_socketFile", ")", "except", ":", "raise", "Exception", "(", "\"Connection to %s failed.\"", "%", "self", ".", "_instanceName", ")" ]
Connect to Memcached.
[ "Connect", "to", "Memcached", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/memcached.py#L66-L79
train
aouyar/PyMunin
pysysinfo/memcached.py
MemcachedInfo._sendStatCmd
def _sendStatCmd(self, cmd): """Send stat command to Memcached Server and return response lines. @param cmd: Command string. @return: Array of strings. """ try: self._conn.write("%s\r\n" % cmd) regex = re.compile('^(END|ERROR)\r\n', re.MULTILINE) (idx, mobj, text) = self._conn.expect([regex,], self._timeout) #@UnusedVariable except: raise Exception("Communication with %s failed" % self._instanceName) if mobj is not None: if mobj.group(1) == 'END': return text.splitlines()[:-1] elif mobj.group(1) == 'ERROR': raise Exception("Protocol error in communication with %s." % self._instanceName) else: raise Exception("Connection with %s timed out." % self._instanceName)
python
def _sendStatCmd(self, cmd): """Send stat command to Memcached Server and return response lines. @param cmd: Command string. @return: Array of strings. """ try: self._conn.write("%s\r\n" % cmd) regex = re.compile('^(END|ERROR)\r\n', re.MULTILINE) (idx, mobj, text) = self._conn.expect([regex,], self._timeout) #@UnusedVariable except: raise Exception("Communication with %s failed" % self._instanceName) if mobj is not None: if mobj.group(1) == 'END': return text.splitlines()[:-1] elif mobj.group(1) == 'ERROR': raise Exception("Protocol error in communication with %s." % self._instanceName) else: raise Exception("Connection with %s timed out." % self._instanceName)
[ "def", "_sendStatCmd", "(", "self", ",", "cmd", ")", ":", "try", ":", "self", ".", "_conn", ".", "write", "(", "\"%s\\r\\n\"", "%", "cmd", ")", "regex", "=", "re", ".", "compile", "(", "'^(END|ERROR)\\r\\n'", ",", "re", ".", "MULTILINE", ")", "(", "idx", ",", "mobj", ",", "text", ")", "=", "self", ".", "_conn", ".", "expect", "(", "[", "regex", ",", "]", ",", "self", ".", "_timeout", ")", "#@UnusedVariable", "except", ":", "raise", "Exception", "(", "\"Communication with %s failed\"", "%", "self", ".", "_instanceName", ")", "if", "mobj", "is", "not", "None", ":", "if", "mobj", ".", "group", "(", "1", ")", "==", "'END'", ":", "return", "text", ".", "splitlines", "(", ")", "[", ":", "-", "1", "]", "elif", "mobj", ".", "group", "(", "1", ")", "==", "'ERROR'", ":", "raise", "Exception", "(", "\"Protocol error in communication with %s.\"", "%", "self", ".", "_instanceName", ")", "else", ":", "raise", "Exception", "(", "\"Connection with %s timed out.\"", "%", "self", ".", "_instanceName", ")" ]
Send stat command to Memcached Server and return response lines. @param cmd: Command string. @return: Array of strings.
[ "Send", "stat", "command", "to", "Memcached", "Server", "and", "return", "response", "lines", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/memcached.py#L81-L101
train
aouyar/PyMunin
pysysinfo/memcached.py
MemcachedInfo._parseStats
def _parseStats(self, lines, parse_slabs = False): """Parse stats output from memcached and return dictionary of stats- @param lines: Array of lines of input text. @param parse_slabs: Parse slab stats if True. @return: Stats dictionary. """ info_dict = {} info_dict['slabs'] = {} for line in lines: mobj = re.match('^STAT\s(\w+)\s(\S+)$', line) if mobj: info_dict[mobj.group(1)] = util.parse_value(mobj.group(2), True) continue elif parse_slabs: mobj = re.match('STAT\s(\w+:)?(\d+):(\w+)\s(\S+)$', line) if mobj: (slab, key, val) = mobj.groups()[-3:] if not info_dict['slabs'].has_key(slab): info_dict['slabs'][slab] = {} info_dict['slabs'][slab][key] = util.parse_value(val, True) return info_dict
python
def _parseStats(self, lines, parse_slabs = False): """Parse stats output from memcached and return dictionary of stats- @param lines: Array of lines of input text. @param parse_slabs: Parse slab stats if True. @return: Stats dictionary. """ info_dict = {} info_dict['slabs'] = {} for line in lines: mobj = re.match('^STAT\s(\w+)\s(\S+)$', line) if mobj: info_dict[mobj.group(1)] = util.parse_value(mobj.group(2), True) continue elif parse_slabs: mobj = re.match('STAT\s(\w+:)?(\d+):(\w+)\s(\S+)$', line) if mobj: (slab, key, val) = mobj.groups()[-3:] if not info_dict['slabs'].has_key(slab): info_dict['slabs'][slab] = {} info_dict['slabs'][slab][key] = util.parse_value(val, True) return info_dict
[ "def", "_parseStats", "(", "self", ",", "lines", ",", "parse_slabs", "=", "False", ")", ":", "info_dict", "=", "{", "}", "info_dict", "[", "'slabs'", "]", "=", "{", "}", "for", "line", "in", "lines", ":", "mobj", "=", "re", ".", "match", "(", "'^STAT\\s(\\w+)\\s(\\S+)$'", ",", "line", ")", "if", "mobj", ":", "info_dict", "[", "mobj", ".", "group", "(", "1", ")", "]", "=", "util", ".", "parse_value", "(", "mobj", ".", "group", "(", "2", ")", ",", "True", ")", "continue", "elif", "parse_slabs", ":", "mobj", "=", "re", ".", "match", "(", "'STAT\\s(\\w+:)?(\\d+):(\\w+)\\s(\\S+)$'", ",", "line", ")", "if", "mobj", ":", "(", "slab", ",", "key", ",", "val", ")", "=", "mobj", ".", "groups", "(", ")", "[", "-", "3", ":", "]", "if", "not", "info_dict", "[", "'slabs'", "]", ".", "has_key", "(", "slab", ")", ":", "info_dict", "[", "'slabs'", "]", "[", "slab", "]", "=", "{", "}", "info_dict", "[", "'slabs'", "]", "[", "slab", "]", "[", "key", "]", "=", "util", ".", "parse_value", "(", "val", ",", "True", ")", "return", "info_dict" ]
Parse stats output from memcached and return dictionary of stats- @param lines: Array of lines of input text. @param parse_slabs: Parse slab stats if True. @return: Stats dictionary.
[ "Parse", "stats", "output", "from", "memcached", "and", "return", "dictionary", "of", "stats", "-" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/memcached.py#L102-L124
train
aouyar/PyMunin
pymunin/plugins/memcachedstats.py
MuninMemcachedPlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" if self._stats is None: serverInfo = MemcachedInfo(self._host, self._port, self._socket_file) stats = serverInfo.getStats() else: stats = self._stats if stats is None: raise Exception("Undetermined error accesing stats.") stats['set_hits'] = stats.get('total_items') if stats.has_key('cmd_set') and stats.has_key('total_items'): stats['set_misses'] = stats['cmd_set'] - stats['total_items'] self.saveState(stats) if self.hasGraph('memcached_connections'): self.setGraphVal('memcached_connections', 'conn', stats.get('curr_connections')) if self.hasGraph('memcached_items'): self.setGraphVal('memcached_items', 'items', stats.get('curr_items')) if self.hasGraph('memcached_memory'): self.setGraphVal('memcached_memory', 'bytes', stats.get('bytes')) if self.hasGraph('memcached_connrate'): self.setGraphVal('memcached_connrate', 'conn', stats.get('total_connections')) if self.hasGraph('memcached_traffic'): self.setGraphVal('memcached_traffic', 'rxbytes', stats.get('bytes_read')) self.setGraphVal('memcached_traffic', 'txbytes', stats.get('bytes_written')) if self.hasGraph('memcached_reqrate'): self.setGraphVal('memcached_reqrate', 'set', stats.get('cmd_set')) self.setGraphVal('memcached_reqrate', 'get', stats.get('cmd_get')) if self.graphHasField('memcached_reqrate', 'del'): self.setGraphVal('memcached_reqrate', 'del', safe_sum([stats.get('delete_hits'), stats.get('delete_misses')])) if self.graphHasField('memcached_reqrate', 'cas'): self.setGraphVal('memcached_reqrate', 'cas', safe_sum([stats.get('cas_hits'), stats.get('cas_misses'), stats.get('cas_badval')])) if self.graphHasField('memcached_reqrate', 'incr'): self.setGraphVal('memcached_reqrate', 'incr', safe_sum([stats.get('incr_hits'), stats.get('incr_misses')])) if self.graphHasField('memcached_reqrate', 'decr'): self.setGraphVal('memcached_reqrate', 'decr', safe_sum([stats.get('decr_hits'), stats.get('decr_misses')])) if self.hasGraph('memcached_statget'): self.setGraphVal('memcached_statget', 'hit', stats.get('get_hits')) self.setGraphVal('memcached_statget', 'miss', stats.get('get_misses')) self.setGraphVal('memcached_statget', 'total', safe_sum([stats.get('get_hits'), stats.get('get_misses')])) if self.hasGraph('memcached_statset'): self.setGraphVal('memcached_statset', 'hit', stats.get('set_hits')) self.setGraphVal('memcached_statset', 'miss', stats.get('set_misses')) self.setGraphVal('memcached_statset', 'total', safe_sum([stats.get('set_hits'), stats.get('set_misses')])) if self.hasGraph('memcached_statdel'): self.setGraphVal('memcached_statdel', 'hit', stats.get('delete_hits')) self.setGraphVal('memcached_statdel', 'miss', stats.get('delete_misses')) self.setGraphVal('memcached_statdel', 'total', safe_sum([stats.get('delete_hits'), stats.get('delete_misses')])) if self.hasGraph('memcached_statcas'): self.setGraphVal('memcached_statcas', 'hit', stats.get('cas_hits')) self.setGraphVal('memcached_statcas', 'miss', stats.get('cas_misses')) self.setGraphVal('memcached_statcas', 'badval', stats.get('cas_badval')) self.setGraphVal('memcached_statcas', 'total', safe_sum([stats.get('cas_hits'), stats.get('cas_misses'), stats.get('cas_badval')])) if self.hasGraph('memcached_statincrdecr'): self.setGraphVal('memcached_statincrdecr', 'incr_hit', stats.get('incr_hits')) self.setGraphVal('memcached_statincrdecr', 'decr_hit', stats.get('decr_hits')) self.setGraphVal('memcached_statincrdecr', 'incr_miss', stats.get('incr_misses')) self.setGraphVal('memcached_statincrdecr', 'decr_miss', stats.get('decr_misses')) self.setGraphVal('memcached_statincrdecr', 'total', safe_sum([stats.get('incr_hits'), stats.get('decr_hits'), stats.get('incr_misses'), stats.get('decr_misses')])) if self.hasGraph('memcached_statevict'): self.setGraphVal('memcached_statevict', 'evict', stats.get('evictions')) if self.graphHasField('memcached_statevict', 'reclaim'): self.setGraphVal('memcached_statevict', 'reclaim', stats.get('reclaimed')) if self.hasGraph('memcached_statauth'): self.setGraphVal('memcached_statauth', 'reqs', stats.get('auth_cmds')) self.setGraphVal('memcached_statauth', 'errors', stats.get('auth_errors')) if self.hasGraph('memcached_hitpct'): prev_stats = self._prev_stats for (field_name, field_hits, field_misses) in ( ('set', 'set_hits', 'set_misses'), ('get', 'get_hits', 'get_misses'), ('del', 'delete_hits', 'delete_misses'), ('cas', 'cas_hits', 'cas_misses'), ('incr', 'incr_hits', 'incr_misses'), ('decr', 'decr_hits', 'decr_misses') ): if prev_stats: if (stats.has_key(field_hits) and prev_stats.has_key(field_hits) and stats.has_key(field_misses) and prev_stats.has_key(field_misses)): hits = stats[field_hits] - prev_stats[field_hits] misses = stats[field_misses] - prev_stats[field_misses] total = hits + misses if total > 0: val = 100.0 * hits / total else: val = 0 self.setGraphVal('memcached_hitpct', field_name, round(val, 2))
python
def retrieveVals(self): """Retrieve values for graphs.""" if self._stats is None: serverInfo = MemcachedInfo(self._host, self._port, self._socket_file) stats = serverInfo.getStats() else: stats = self._stats if stats is None: raise Exception("Undetermined error accesing stats.") stats['set_hits'] = stats.get('total_items') if stats.has_key('cmd_set') and stats.has_key('total_items'): stats['set_misses'] = stats['cmd_set'] - stats['total_items'] self.saveState(stats) if self.hasGraph('memcached_connections'): self.setGraphVal('memcached_connections', 'conn', stats.get('curr_connections')) if self.hasGraph('memcached_items'): self.setGraphVal('memcached_items', 'items', stats.get('curr_items')) if self.hasGraph('memcached_memory'): self.setGraphVal('memcached_memory', 'bytes', stats.get('bytes')) if self.hasGraph('memcached_connrate'): self.setGraphVal('memcached_connrate', 'conn', stats.get('total_connections')) if self.hasGraph('memcached_traffic'): self.setGraphVal('memcached_traffic', 'rxbytes', stats.get('bytes_read')) self.setGraphVal('memcached_traffic', 'txbytes', stats.get('bytes_written')) if self.hasGraph('memcached_reqrate'): self.setGraphVal('memcached_reqrate', 'set', stats.get('cmd_set')) self.setGraphVal('memcached_reqrate', 'get', stats.get('cmd_get')) if self.graphHasField('memcached_reqrate', 'del'): self.setGraphVal('memcached_reqrate', 'del', safe_sum([stats.get('delete_hits'), stats.get('delete_misses')])) if self.graphHasField('memcached_reqrate', 'cas'): self.setGraphVal('memcached_reqrate', 'cas', safe_sum([stats.get('cas_hits'), stats.get('cas_misses'), stats.get('cas_badval')])) if self.graphHasField('memcached_reqrate', 'incr'): self.setGraphVal('memcached_reqrate', 'incr', safe_sum([stats.get('incr_hits'), stats.get('incr_misses')])) if self.graphHasField('memcached_reqrate', 'decr'): self.setGraphVal('memcached_reqrate', 'decr', safe_sum([stats.get('decr_hits'), stats.get('decr_misses')])) if self.hasGraph('memcached_statget'): self.setGraphVal('memcached_statget', 'hit', stats.get('get_hits')) self.setGraphVal('memcached_statget', 'miss', stats.get('get_misses')) self.setGraphVal('memcached_statget', 'total', safe_sum([stats.get('get_hits'), stats.get('get_misses')])) if self.hasGraph('memcached_statset'): self.setGraphVal('memcached_statset', 'hit', stats.get('set_hits')) self.setGraphVal('memcached_statset', 'miss', stats.get('set_misses')) self.setGraphVal('memcached_statset', 'total', safe_sum([stats.get('set_hits'), stats.get('set_misses')])) if self.hasGraph('memcached_statdel'): self.setGraphVal('memcached_statdel', 'hit', stats.get('delete_hits')) self.setGraphVal('memcached_statdel', 'miss', stats.get('delete_misses')) self.setGraphVal('memcached_statdel', 'total', safe_sum([stats.get('delete_hits'), stats.get('delete_misses')])) if self.hasGraph('memcached_statcas'): self.setGraphVal('memcached_statcas', 'hit', stats.get('cas_hits')) self.setGraphVal('memcached_statcas', 'miss', stats.get('cas_misses')) self.setGraphVal('memcached_statcas', 'badval', stats.get('cas_badval')) self.setGraphVal('memcached_statcas', 'total', safe_sum([stats.get('cas_hits'), stats.get('cas_misses'), stats.get('cas_badval')])) if self.hasGraph('memcached_statincrdecr'): self.setGraphVal('memcached_statincrdecr', 'incr_hit', stats.get('incr_hits')) self.setGraphVal('memcached_statincrdecr', 'decr_hit', stats.get('decr_hits')) self.setGraphVal('memcached_statincrdecr', 'incr_miss', stats.get('incr_misses')) self.setGraphVal('memcached_statincrdecr', 'decr_miss', stats.get('decr_misses')) self.setGraphVal('memcached_statincrdecr', 'total', safe_sum([stats.get('incr_hits'), stats.get('decr_hits'), stats.get('incr_misses'), stats.get('decr_misses')])) if self.hasGraph('memcached_statevict'): self.setGraphVal('memcached_statevict', 'evict', stats.get('evictions')) if self.graphHasField('memcached_statevict', 'reclaim'): self.setGraphVal('memcached_statevict', 'reclaim', stats.get('reclaimed')) if self.hasGraph('memcached_statauth'): self.setGraphVal('memcached_statauth', 'reqs', stats.get('auth_cmds')) self.setGraphVal('memcached_statauth', 'errors', stats.get('auth_errors')) if self.hasGraph('memcached_hitpct'): prev_stats = self._prev_stats for (field_name, field_hits, field_misses) in ( ('set', 'set_hits', 'set_misses'), ('get', 'get_hits', 'get_misses'), ('del', 'delete_hits', 'delete_misses'), ('cas', 'cas_hits', 'cas_misses'), ('incr', 'incr_hits', 'incr_misses'), ('decr', 'decr_hits', 'decr_misses') ): if prev_stats: if (stats.has_key(field_hits) and prev_stats.has_key(field_hits) and stats.has_key(field_misses) and prev_stats.has_key(field_misses)): hits = stats[field_hits] - prev_stats[field_hits] misses = stats[field_misses] - prev_stats[field_misses] total = hits + misses if total > 0: val = 100.0 * hits / total else: val = 0 self.setGraphVal('memcached_hitpct', field_name, round(val, 2))
[ "def", "retrieveVals", "(", "self", ")", ":", "if", "self", ".", "_stats", "is", "None", ":", "serverInfo", "=", "MemcachedInfo", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_socket_file", ")", "stats", "=", "serverInfo", ".", "getStats", "(", ")", "else", ":", "stats", "=", "self", ".", "_stats", "if", "stats", "is", "None", ":", "raise", "Exception", "(", "\"Undetermined error accesing stats.\"", ")", "stats", "[", "'set_hits'", "]", "=", "stats", ".", "get", "(", "'total_items'", ")", "if", "stats", ".", "has_key", "(", "'cmd_set'", ")", "and", "stats", ".", "has_key", "(", "'total_items'", ")", ":", "stats", "[", "'set_misses'", "]", "=", "stats", "[", "'cmd_set'", "]", "-", "stats", "[", "'total_items'", "]", "self", ".", "saveState", "(", "stats", ")", "if", "self", ".", "hasGraph", "(", "'memcached_connections'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_connections'", ",", "'conn'", ",", "stats", ".", "get", "(", "'curr_connections'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_items'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_items'", ",", "'items'", ",", "stats", ".", "get", "(", "'curr_items'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_memory'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_memory'", ",", "'bytes'", ",", "stats", ".", "get", "(", "'bytes'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_connrate'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_connrate'", ",", "'conn'", ",", "stats", ".", "get", "(", "'total_connections'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_traffic'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_traffic'", ",", "'rxbytes'", ",", "stats", ".", "get", "(", "'bytes_read'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_traffic'", ",", "'txbytes'", ",", "stats", ".", "get", "(", "'bytes_written'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_reqrate'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'set'", ",", "stats", ".", "get", "(", "'cmd_set'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'get'", ",", "stats", ".", "get", "(", "'cmd_get'", ")", ")", "if", "self", ".", "graphHasField", "(", "'memcached_reqrate'", ",", "'del'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'del'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'delete_hits'", ")", ",", "stats", ".", "get", "(", "'delete_misses'", ")", "]", ")", ")", "if", "self", ".", "graphHasField", "(", "'memcached_reqrate'", ",", "'cas'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'cas'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'cas_hits'", ")", ",", "stats", ".", "get", "(", "'cas_misses'", ")", ",", "stats", ".", "get", "(", "'cas_badval'", ")", "]", ")", ")", "if", "self", ".", "graphHasField", "(", "'memcached_reqrate'", ",", "'incr'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'incr'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'incr_hits'", ")", ",", "stats", ".", "get", "(", "'incr_misses'", ")", "]", ")", ")", "if", "self", ".", "graphHasField", "(", "'memcached_reqrate'", ",", "'decr'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_reqrate'", ",", "'decr'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'decr_hits'", ")", ",", "stats", ".", "get", "(", "'decr_misses'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statget'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statget'", ",", "'hit'", ",", "stats", ".", "get", "(", "'get_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statget'", ",", "'miss'", ",", "stats", ".", "get", "(", "'get_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statget'", ",", "'total'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'get_hits'", ")", ",", "stats", ".", "get", "(", "'get_misses'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statset'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statset'", ",", "'hit'", ",", "stats", ".", "get", "(", "'set_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statset'", ",", "'miss'", ",", "stats", ".", "get", "(", "'set_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statset'", ",", "'total'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'set_hits'", ")", ",", "stats", ".", "get", "(", "'set_misses'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statdel'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statdel'", ",", "'hit'", ",", "stats", ".", "get", "(", "'delete_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statdel'", ",", "'miss'", ",", "stats", ".", "get", "(", "'delete_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statdel'", ",", "'total'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'delete_hits'", ")", ",", "stats", ".", "get", "(", "'delete_misses'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statcas'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statcas'", ",", "'hit'", ",", "stats", ".", "get", "(", "'cas_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statcas'", ",", "'miss'", ",", "stats", ".", "get", "(", "'cas_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statcas'", ",", "'badval'", ",", "stats", ".", "get", "(", "'cas_badval'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statcas'", ",", "'total'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'cas_hits'", ")", ",", "stats", ".", "get", "(", "'cas_misses'", ")", ",", "stats", ".", "get", "(", "'cas_badval'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statincrdecr'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statincrdecr'", ",", "'incr_hit'", ",", "stats", ".", "get", "(", "'incr_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statincrdecr'", ",", "'decr_hit'", ",", "stats", ".", "get", "(", "'decr_hits'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statincrdecr'", ",", "'incr_miss'", ",", "stats", ".", "get", "(", "'incr_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statincrdecr'", ",", "'decr_miss'", ",", "stats", ".", "get", "(", "'decr_misses'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statincrdecr'", ",", "'total'", ",", "safe_sum", "(", "[", "stats", ".", "get", "(", "'incr_hits'", ")", ",", "stats", ".", "get", "(", "'decr_hits'", ")", ",", "stats", ".", "get", "(", "'incr_misses'", ")", ",", "stats", ".", "get", "(", "'decr_misses'", ")", "]", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statevict'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statevict'", ",", "'evict'", ",", "stats", ".", "get", "(", "'evictions'", ")", ")", "if", "self", ".", "graphHasField", "(", "'memcached_statevict'", ",", "'reclaim'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statevict'", ",", "'reclaim'", ",", "stats", ".", "get", "(", "'reclaimed'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_statauth'", ")", ":", "self", ".", "setGraphVal", "(", "'memcached_statauth'", ",", "'reqs'", ",", "stats", ".", "get", "(", "'auth_cmds'", ")", ")", "self", ".", "setGraphVal", "(", "'memcached_statauth'", ",", "'errors'", ",", "stats", ".", "get", "(", "'auth_errors'", ")", ")", "if", "self", ".", "hasGraph", "(", "'memcached_hitpct'", ")", ":", "prev_stats", "=", "self", ".", "_prev_stats", "for", "(", "field_name", ",", "field_hits", ",", "field_misses", ")", "in", "(", "(", "'set'", ",", "'set_hits'", ",", "'set_misses'", ")", ",", "(", "'get'", ",", "'get_hits'", ",", "'get_misses'", ")", ",", "(", "'del'", ",", "'delete_hits'", ",", "'delete_misses'", ")", ",", "(", "'cas'", ",", "'cas_hits'", ",", "'cas_misses'", ")", ",", "(", "'incr'", ",", "'incr_hits'", ",", "'incr_misses'", ")", ",", "(", "'decr'", ",", "'decr_hits'", ",", "'decr_misses'", ")", ")", ":", "if", "prev_stats", ":", "if", "(", "stats", ".", "has_key", "(", "field_hits", ")", "and", "prev_stats", ".", "has_key", "(", "field_hits", ")", "and", "stats", ".", "has_key", "(", "field_misses", ")", "and", "prev_stats", ".", "has_key", "(", "field_misses", ")", ")", ":", "hits", "=", "stats", "[", "field_hits", "]", "-", "prev_stats", "[", "field_hits", "]", "misses", "=", "stats", "[", "field_misses", "]", "-", "prev_stats", "[", "field_misses", "]", "total", "=", "hits", "+", "misses", "if", "total", ">", "0", ":", "val", "=", "100.0", "*", "hits", "/", "total", "else", ":", "val", "=", "0", "self", ".", "setGraphVal", "(", "'memcached_hitpct'", ",", "field_name", ",", "round", "(", "val", ",", "2", ")", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/memcachedstats.py#L305-L440
train
aouyar/PyMunin
pymunin/plugins/memcachedstats.py
MuninMemcachedPlugin.autoconf
def autoconf(self): """Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise. """ serverInfo = MemcachedInfo(self._host, self._port, self._socket_file) return (serverInfo is not None)
python
def autoconf(self): """Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise. """ serverInfo = MemcachedInfo(self._host, self._port, self._socket_file) return (serverInfo is not None)
[ "def", "autoconf", "(", "self", ")", ":", "serverInfo", "=", "MemcachedInfo", "(", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_socket_file", ")", "return", "(", "serverInfo", "is", "not", "None", ")" ]
Implements Munin Plugin Auto-Configuration Option. @return: True if plugin can be auto-configured, False otherwise.
[ "Implements", "Munin", "Plugin", "Auto", "-", "Configuration", "Option", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/memcachedstats.py#L442-L449
train
ContextLab/quail
quail/distance.py
correlation
def correlation(a, b): "Returns correlation distance between a and b" if isinstance(a, list): a = np.array(a) if isinstance(b, list): b = np.array(b) a = a.reshape(1, -1) b = b.reshape(1, -1) return cdist(a, b, 'correlation')
python
def correlation(a, b): "Returns correlation distance between a and b" if isinstance(a, list): a = np.array(a) if isinstance(b, list): b = np.array(b) a = a.reshape(1, -1) b = b.reshape(1, -1) return cdist(a, b, 'correlation')
[ "def", "correlation", "(", "a", ",", "b", ")", ":", "if", "isinstance", "(", "a", ",", "list", ")", ":", "a", "=", "np", ".", "array", "(", "a", ")", "if", "isinstance", "(", "b", ",", "list", ")", ":", "b", "=", "np", ".", "array", "(", "b", ")", "a", "=", "a", ".", "reshape", "(", "1", ",", "-", "1", ")", "b", "=", "b", ".", "reshape", "(", "1", ",", "-", "1", ")", "return", "cdist", "(", "a", ",", "b", ",", "'correlation'", ")" ]
Returns correlation distance between a and b
[ "Returns", "correlation", "distance", "between", "a", "and", "b" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/distance.py#L9-L17
train
ContextLab/quail
quail/distance.py
euclidean
def euclidean(a, b): "Returns euclidean distance between a and b" return np.linalg.norm(np.subtract(a, b))
python
def euclidean(a, b): "Returns euclidean distance between a and b" return np.linalg.norm(np.subtract(a, b))
[ "def", "euclidean", "(", "a", ",", "b", ")", ":", "return", "np", ".", "linalg", ".", "norm", "(", "np", ".", "subtract", "(", "a", ",", "b", ")", ")" ]
Returns euclidean distance between a and b
[ "Returns", "euclidean", "distance", "between", "a", "and", "b" ]
71dd53c792dd915dc84879d8237e3582dd68b7a4
https://github.com/ContextLab/quail/blob/71dd53c792dd915dc84879d8237e3582dd68b7a4/quail/distance.py#L19-L21
train
aouyar/PyMunin
pysysinfo/process.py
ProcessInfo.execProcCmd
def execProcCmd(self, *args): """Execute ps command with positional params args and return result as list of lines. @param *args: Positional params for ps command. @return: List of output lines """ out = util.exec_command([psCmd,] + list(args)) return out.splitlines()
python
def execProcCmd(self, *args): """Execute ps command with positional params args and return result as list of lines. @param *args: Positional params for ps command. @return: List of output lines """ out = util.exec_command([psCmd,] + list(args)) return out.splitlines()
[ "def", "execProcCmd", "(", "self", ",", "*", "args", ")", ":", "out", "=", "util", ".", "exec_command", "(", "[", "psCmd", ",", "]", "+", "list", "(", "args", ")", ")", "return", "out", ".", "splitlines", "(", ")" ]
Execute ps command with positional params args and return result as list of lines. @param *args: Positional params for ps command. @return: List of output lines
[ "Execute", "ps", "command", "with", "positional", "params", "args", "and", "return", "result", "as", "list", "of", "lines", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/process.py#L47-L56
train
aouyar/PyMunin
pysysinfo/process.py
ProcessInfo.parseProcCmd
def parseProcCmd(self, fields=('pid', 'user', 'cmd',), threads=False): """Execute ps command with custom output format with columns from fields and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: List of fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @return: List of headers and list of rows and columns. """ args = [] headers = [f.lower() for f in fields] args.append('--no-headers') args.append('-e') if threads: args.append('-T') field_ranges = [] fmt_strs = [] start = 0 for header in headers: field_width = psFieldWidth.get(header, psDefaultFieldWidth) fmt_strs.append('%s:%d' % (header, field_width)) end = start + field_width + 1 field_ranges.append((start,end)) start = end args.append('-o') args.append(','.join(fmt_strs)) lines = self.execProcCmd(*args) if len(lines) > 0: stats = [] for line in lines: cols = [] for (start, end) in field_ranges: cols.append(line[start:end].strip()) stats.append(cols) return {'headers': headers, 'stats': stats} else: return None
python
def parseProcCmd(self, fields=('pid', 'user', 'cmd',), threads=False): """Execute ps command with custom output format with columns from fields and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: List of fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @return: List of headers and list of rows and columns. """ args = [] headers = [f.lower() for f in fields] args.append('--no-headers') args.append('-e') if threads: args.append('-T') field_ranges = [] fmt_strs = [] start = 0 for header in headers: field_width = psFieldWidth.get(header, psDefaultFieldWidth) fmt_strs.append('%s:%d' % (header, field_width)) end = start + field_width + 1 field_ranges.append((start,end)) start = end args.append('-o') args.append(','.join(fmt_strs)) lines = self.execProcCmd(*args) if len(lines) > 0: stats = [] for line in lines: cols = [] for (start, end) in field_ranges: cols.append(line[start:end].strip()) stats.append(cols) return {'headers': headers, 'stats': stats} else: return None
[ "def", "parseProcCmd", "(", "self", ",", "fields", "=", "(", "'pid'", ",", "'user'", ",", "'cmd'", ",", ")", ",", "threads", "=", "False", ")", ":", "args", "=", "[", "]", "headers", "=", "[", "f", ".", "lower", "(", ")", "for", "f", "in", "fields", "]", "args", ".", "append", "(", "'--no-headers'", ")", "args", ".", "append", "(", "'-e'", ")", "if", "threads", ":", "args", ".", "append", "(", "'-T'", ")", "field_ranges", "=", "[", "]", "fmt_strs", "=", "[", "]", "start", "=", "0", "for", "header", "in", "headers", ":", "field_width", "=", "psFieldWidth", ".", "get", "(", "header", ",", "psDefaultFieldWidth", ")", "fmt_strs", ".", "append", "(", "'%s:%d'", "%", "(", "header", ",", "field_width", ")", ")", "end", "=", "start", "+", "field_width", "+", "1", "field_ranges", ".", "append", "(", "(", "start", ",", "end", ")", ")", "start", "=", "end", "args", ".", "append", "(", "'-o'", ")", "args", ".", "append", "(", "','", ".", "join", "(", "fmt_strs", ")", ")", "lines", "=", "self", ".", "execProcCmd", "(", "*", "args", ")", "if", "len", "(", "lines", ")", ">", "0", ":", "stats", "=", "[", "]", "for", "line", "in", "lines", ":", "cols", "=", "[", "]", "for", "(", "start", ",", "end", ")", "in", "field_ranges", ":", "cols", ".", "append", "(", "line", "[", "start", ":", "end", "]", ".", "strip", "(", ")", ")", "stats", ".", "append", "(", "cols", ")", "return", "{", "'headers'", ":", "headers", ",", "'stats'", ":", "stats", "}", "else", ":", "return", "None" ]
Execute ps command with custom output format with columns from fields and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: List of fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @return: List of headers and list of rows and columns.
[ "Execute", "ps", "command", "with", "custom", "output", "format", "with", "columns", "from", "fields", "and", "return", "result", "as", "a", "nested", "list", ".", "The", "Standard", "Format", "Specifiers", "from", "ps", "man", "page", "must", "be", "used", "for", "the", "fields", "parameter", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/process.py#L58-L98
train
aouyar/PyMunin
pysysinfo/process.py
ProcessInfo.getProcList
def getProcList(self, fields=('pid', 'user', 'cmd',), threads=False, **kwargs): """Execute ps command with custom output format with columns columns from fields, select lines using the filters defined by kwargs and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: List of headers and list of rows and columns. """ field_list = list(fields) for key in kwargs: col = re.sub('(_ic)?(_regex)?$', '', key) if not col in field_list: field_list.append(col) pinfo = self.parseProcCmd(field_list, threads) if pinfo: if len(kwargs) > 0: pfilter = util.TableFilter() pfilter.registerFilters(**kwargs) stats = pfilter.applyFilters(pinfo['headers'], pinfo['stats']) return {'headers': pinfo['headers'], 'stats': stats} else: return pinfo else: return None
python
def getProcList(self, fields=('pid', 'user', 'cmd',), threads=False, **kwargs): """Execute ps command with custom output format with columns columns from fields, select lines using the filters defined by kwargs and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: List of headers and list of rows and columns. """ field_list = list(fields) for key in kwargs: col = re.sub('(_ic)?(_regex)?$', '', key) if not col in field_list: field_list.append(col) pinfo = self.parseProcCmd(field_list, threads) if pinfo: if len(kwargs) > 0: pfilter = util.TableFilter() pfilter.registerFilters(**kwargs) stats = pfilter.applyFilters(pinfo['headers'], pinfo['stats']) return {'headers': pinfo['headers'], 'stats': stats} else: return pinfo else: return None
[ "def", "getProcList", "(", "self", ",", "fields", "=", "(", "'pid'", ",", "'user'", ",", "'cmd'", ",", ")", ",", "threads", "=", "False", ",", "*", "*", "kwargs", ")", ":", "field_list", "=", "list", "(", "fields", ")", "for", "key", "in", "kwargs", ":", "col", "=", "re", ".", "sub", "(", "'(_ic)?(_regex)?$'", ",", "''", ",", "key", ")", "if", "not", "col", "in", "field_list", ":", "field_list", ".", "append", "(", "col", ")", "pinfo", "=", "self", ".", "parseProcCmd", "(", "field_list", ",", "threads", ")", "if", "pinfo", ":", "if", "len", "(", "kwargs", ")", ">", "0", ":", "pfilter", "=", "util", ".", "TableFilter", "(", ")", "pfilter", ".", "registerFilters", "(", "*", "*", "kwargs", ")", "stats", "=", "pfilter", ".", "applyFilters", "(", "pinfo", "[", "'headers'", "]", ",", "pinfo", "[", "'stats'", "]", ")", "return", "{", "'headers'", ":", "pinfo", "[", "'headers'", "]", ",", "'stats'", ":", "stats", "}", "else", ":", "return", "pinfo", "else", ":", "return", "None" ]
Execute ps command with custom output format with columns columns from fields, select lines using the filters defined by kwargs and return result as a nested list. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: pid, user, cmd @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: List of headers and list of rows and columns.
[ "Execute", "ps", "command", "with", "custom", "output", "format", "with", "columns", "columns", "from", "fields", "select", "lines", "using", "the", "filters", "defined", "by", "kwargs", "and", "return", "result", "as", "a", "nested", "list", ".", "The", "Standard", "Format", "Specifiers", "from", "ps", "man", "page", "must", "be", "used", "for", "the", "fields", "parameter", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/process.py#L100-L144
train
aouyar/PyMunin
pysysinfo/process.py
ProcessInfo.getProcDict
def getProcDict(self, fields=('user', 'cmd',), threads=False, **kwargs): """Execute ps command with custom output format with columns format with columns from fields, and return result as a nested dictionary with the key PID or SPID. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: user, cmd (PID or SPID column is included by default.) @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Nested dictionary indexed by: PID for process info. SPID for thread info. """ stats = {} field_list = list(fields) num_cols = len(field_list) if threads: key = 'spid' else: key = 'pid' try: key_idx = field_list.index(key) except ValueError: field_list.append(key) key_idx = len(field_list) - 1 result = self.getProcList(field_list, threads, **kwargs) if result is not None: headers = result['headers'][:num_cols] lines = result['stats'] if len(lines) > 1: for cols in lines: stats[cols[key_idx]] = dict(zip(headers, cols[:num_cols])) return stats else: return None
python
def getProcDict(self, fields=('user', 'cmd',), threads=False, **kwargs): """Execute ps command with custom output format with columns format with columns from fields, and return result as a nested dictionary with the key PID or SPID. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: user, cmd (PID or SPID column is included by default.) @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Nested dictionary indexed by: PID for process info. SPID for thread info. """ stats = {} field_list = list(fields) num_cols = len(field_list) if threads: key = 'spid' else: key = 'pid' try: key_idx = field_list.index(key) except ValueError: field_list.append(key) key_idx = len(field_list) - 1 result = self.getProcList(field_list, threads, **kwargs) if result is not None: headers = result['headers'][:num_cols] lines = result['stats'] if len(lines) > 1: for cols in lines: stats[cols[key_idx]] = dict(zip(headers, cols[:num_cols])) return stats else: return None
[ "def", "getProcDict", "(", "self", ",", "fields", "=", "(", "'user'", ",", "'cmd'", ",", ")", ",", "threads", "=", "False", ",", "*", "*", "kwargs", ")", ":", "stats", "=", "{", "}", "field_list", "=", "list", "(", "fields", ")", "num_cols", "=", "len", "(", "field_list", ")", "if", "threads", ":", "key", "=", "'spid'", "else", ":", "key", "=", "'pid'", "try", ":", "key_idx", "=", "field_list", ".", "index", "(", "key", ")", "except", "ValueError", ":", "field_list", ".", "append", "(", "key", ")", "key_idx", "=", "len", "(", "field_list", ")", "-", "1", "result", "=", "self", ".", "getProcList", "(", "field_list", ",", "threads", ",", "*", "*", "kwargs", ")", "if", "result", "is", "not", "None", ":", "headers", "=", "result", "[", "'headers'", "]", "[", ":", "num_cols", "]", "lines", "=", "result", "[", "'stats'", "]", "if", "len", "(", "lines", ")", ">", "1", ":", "for", "cols", "in", "lines", ":", "stats", "[", "cols", "[", "key_idx", "]", "]", "=", "dict", "(", "zip", "(", "headers", ",", "cols", "[", ":", "num_cols", "]", ")", ")", "return", "stats", "else", ":", "return", "None" ]
Execute ps command with custom output format with columns format with columns from fields, and return result as a nested dictionary with the key PID or SPID. The Standard Format Specifiers from ps man page must be used for the fields parameter. @param fields: Fields included in the output. Default: user, cmd (PID or SPID column is included by default.) @param threads: If True, include threads in output. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Nested dictionary indexed by: PID for process info. SPID for thread info.
[ "Execute", "ps", "command", "with", "custom", "output", "format", "with", "columns", "format", "with", "columns", "from", "fields", "and", "return", "result", "as", "a", "nested", "dictionary", "with", "the", "key", "PID", "or", "SPID", ".", "The", "Standard", "Format", "Specifiers", "from", "ps", "man", "page", "must", "be", "used", "for", "the", "fields", "parameter", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/process.py#L146-L198
train
aouyar/PyMunin
pysysinfo/process.py
ProcessInfo.getProcStatStatus
def getProcStatStatus(self, threads=False, **kwargs): """Return process counts per status and priority. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Dictionary of process counters. """ procs = self.getProcList(['stat',], threads=threads, **kwargs) status = dict(zip(procStatusNames.values(), [0,] * len(procStatusNames))) prio = {'high': 0, 'low': 0, 'norm': 0, 'locked_in_mem': 0} total = 0 locked_in_mem = 0 if procs is not None: for cols in procs['stats']: col_stat = cols[0] status[procStatusNames[col_stat[0]]] += 1 if '<' in col_stat[1:]: prio['high'] += 1 elif 'N' in col_stat[1:]: prio['low'] += 1 else: prio['norm'] += 1 if 'L' in col_stat[1:]: locked_in_mem += 1 total += 1 return {'status': status, 'prio': prio, 'locked_in_mem': locked_in_mem, 'total': total}
python
def getProcStatStatus(self, threads=False, **kwargs): """Return process counts per status and priority. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Dictionary of process counters. """ procs = self.getProcList(['stat',], threads=threads, **kwargs) status = dict(zip(procStatusNames.values(), [0,] * len(procStatusNames))) prio = {'high': 0, 'low': 0, 'norm': 0, 'locked_in_mem': 0} total = 0 locked_in_mem = 0 if procs is not None: for cols in procs['stats']: col_stat = cols[0] status[procStatusNames[col_stat[0]]] += 1 if '<' in col_stat[1:]: prio['high'] += 1 elif 'N' in col_stat[1:]: prio['low'] += 1 else: prio['norm'] += 1 if 'L' in col_stat[1:]: locked_in_mem += 1 total += 1 return {'status': status, 'prio': prio, 'locked_in_mem': locked_in_mem, 'total': total}
[ "def", "getProcStatStatus", "(", "self", ",", "threads", "=", "False", ",", "*", "*", "kwargs", ")", ":", "procs", "=", "self", ".", "getProcList", "(", "[", "'stat'", ",", "]", ",", "threads", "=", "threads", ",", "*", "*", "kwargs", ")", "status", "=", "dict", "(", "zip", "(", "procStatusNames", ".", "values", "(", ")", ",", "[", "0", ",", "]", "*", "len", "(", "procStatusNames", ")", ")", ")", "prio", "=", "{", "'high'", ":", "0", ",", "'low'", ":", "0", ",", "'norm'", ":", "0", ",", "'locked_in_mem'", ":", "0", "}", "total", "=", "0", "locked_in_mem", "=", "0", "if", "procs", "is", "not", "None", ":", "for", "cols", "in", "procs", "[", "'stats'", "]", ":", "col_stat", "=", "cols", "[", "0", "]", "status", "[", "procStatusNames", "[", "col_stat", "[", "0", "]", "]", "]", "+=", "1", "if", "'<'", "in", "col_stat", "[", "1", ":", "]", ":", "prio", "[", "'high'", "]", "+=", "1", "elif", "'N'", "in", "col_stat", "[", "1", ":", "]", ":", "prio", "[", "'low'", "]", "+=", "1", "else", ":", "prio", "[", "'norm'", "]", "+=", "1", "if", "'L'", "in", "col_stat", "[", "1", ":", "]", ":", "locked_in_mem", "+=", "1", "total", "+=", "1", "return", "{", "'status'", ":", "status", ",", "'prio'", ":", "prio", ",", "'locked_in_mem'", ":", "locked_in_mem", ",", "'total'", ":", "total", "}" ]
Return process counts per status and priority. @param **kwargs: Keyword variables are used for filtering the results depending on the values of the columns. Each keyword must correspond to a field name with an optional suffix: field: Field equal to value or in list of values. field_ic: Field equal to value or in list of values, using case insensitive comparison. field_regex: Field matches regex value or matches with any regex in list of values. field_ic_regex: Field matches regex value or matches with any regex in list of values using case insensitive match. @return: Dictionary of process counters.
[ "Return", "process", "counts", "per", "status", "and", "priority", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/process.py#L200-L242
train
aouyar/PyMunin
pymunin/plugins/ntpstats.py
MuninNTPstatsPlugin.retrieveVals
def retrieveVals(self): """Retrieve values for graphs.""" ntpinfo = NTPinfo() stats = ntpinfo.getPeerStats() if stats: if self.hasGraph('ntp_peer_stratum'): self.setGraphVal('ntp_peer_stratum', 'stratum', stats.get('stratum')) if self.hasGraph('ntp_peer_stats'): self.setGraphVal('ntp_peer_stats', 'offset', stats.get('offset')) self.setGraphVal('ntp_peer_stats', 'delay', stats.get('delay')) self.setGraphVal('ntp_peer_stats', 'jitter', stats.get('jitter'))
python
def retrieveVals(self): """Retrieve values for graphs.""" ntpinfo = NTPinfo() stats = ntpinfo.getPeerStats() if stats: if self.hasGraph('ntp_peer_stratum'): self.setGraphVal('ntp_peer_stratum', 'stratum', stats.get('stratum')) if self.hasGraph('ntp_peer_stats'): self.setGraphVal('ntp_peer_stats', 'offset', stats.get('offset')) self.setGraphVal('ntp_peer_stats', 'delay', stats.get('delay')) self.setGraphVal('ntp_peer_stats', 'jitter', stats.get('jitter'))
[ "def", "retrieveVals", "(", "self", ")", ":", "ntpinfo", "=", "NTPinfo", "(", ")", "stats", "=", "ntpinfo", ".", "getPeerStats", "(", ")", "if", "stats", ":", "if", "self", ".", "hasGraph", "(", "'ntp_peer_stratum'", ")", ":", "self", ".", "setGraphVal", "(", "'ntp_peer_stratum'", ",", "'stratum'", ",", "stats", ".", "get", "(", "'stratum'", ")", ")", "if", "self", ".", "hasGraph", "(", "'ntp_peer_stats'", ")", ":", "self", ".", "setGraphVal", "(", "'ntp_peer_stats'", ",", "'offset'", ",", "stats", ".", "get", "(", "'offset'", ")", ")", "self", ".", "setGraphVal", "(", "'ntp_peer_stats'", ",", "'delay'", ",", "stats", ".", "get", "(", "'delay'", ")", ")", "self", ".", "setGraphVal", "(", "'ntp_peer_stats'", ",", "'jitter'", ",", "stats", ".", "get", "(", "'jitter'", ")", ")" ]
Retrieve values for graphs.
[ "Retrieve", "values", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/plugins/ntpstats.py#L84-L98
train
aouyar/PyMunin
pymunin/__init__.py
muninMain
def muninMain(pluginClass, argv=None, env=None, debug=False): """Main Block for Munin Plugins. @param pluginClass: Child class of MuninPlugin that implements plugin. @param argv: List of command line arguments to Munin Plugin. @param env: Dictionary of environment variables passed to Munin Plugin. @param debug: Print debugging messages if True. (Default: False) """ if argv is None: argv = sys.argv if env is None: env = os.environ debug = debug or env.has_key('MUNIN_DEBUG') if len(argv) > 1 and argv[1] == 'autoconf': autoconf = True else: autoconf = False try: plugin = pluginClass(argv, env, debug) ret = plugin.run() if ret: return 0 else: return 1 except Exception: print >> sys.stderr, "ERROR: %s" % repr(sys.exc_info()[1]) if autoconf: print "no" if debug: raise else: if autoconf: return 0 else: return 1
python
def muninMain(pluginClass, argv=None, env=None, debug=False): """Main Block for Munin Plugins. @param pluginClass: Child class of MuninPlugin that implements plugin. @param argv: List of command line arguments to Munin Plugin. @param env: Dictionary of environment variables passed to Munin Plugin. @param debug: Print debugging messages if True. (Default: False) """ if argv is None: argv = sys.argv if env is None: env = os.environ debug = debug or env.has_key('MUNIN_DEBUG') if len(argv) > 1 and argv[1] == 'autoconf': autoconf = True else: autoconf = False try: plugin = pluginClass(argv, env, debug) ret = plugin.run() if ret: return 0 else: return 1 except Exception: print >> sys.stderr, "ERROR: %s" % repr(sys.exc_info()[1]) if autoconf: print "no" if debug: raise else: if autoconf: return 0 else: return 1
[ "def", "muninMain", "(", "pluginClass", ",", "argv", "=", "None", ",", "env", "=", "None", ",", "debug", "=", "False", ")", ":", "if", "argv", "is", "None", ":", "argv", "=", "sys", ".", "argv", "if", "env", "is", "None", ":", "env", "=", "os", ".", "environ", "debug", "=", "debug", "or", "env", ".", "has_key", "(", "'MUNIN_DEBUG'", ")", "if", "len", "(", "argv", ")", ">", "1", "and", "argv", "[", "1", "]", "==", "'autoconf'", ":", "autoconf", "=", "True", "else", ":", "autoconf", "=", "False", "try", ":", "plugin", "=", "pluginClass", "(", "argv", ",", "env", ",", "debug", ")", "ret", "=", "plugin", ".", "run", "(", ")", "if", "ret", ":", "return", "0", "else", ":", "return", "1", "except", "Exception", ":", "print", ">>", "sys", ".", "stderr", ",", "\"ERROR: %s\"", "%", "repr", "(", "sys", ".", "exc_info", "(", ")", "[", "1", "]", ")", "if", "autoconf", ":", "print", "\"no\"", "if", "debug", ":", "raise", "else", ":", "if", "autoconf", ":", "return", "0", "else", ":", "return", "1" ]
Main Block for Munin Plugins. @param pluginClass: Child class of MuninPlugin that implements plugin. @param argv: List of command line arguments to Munin Plugin. @param env: Dictionary of environment variables passed to Munin Plugin. @param debug: Print debugging messages if True. (Default: False)
[ "Main", "Block", "for", "Munin", "Plugins", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L938-L973
train
aouyar/PyMunin
pymunin/__init__.py
fixLabel
def fixLabel(label, maxlen, delim=None, repl='', truncend=True): """Truncate long graph and field labels. @param label: Label text. @param maxlen: Maximum field label length in characters. No maximum field label length is enforced by default. @param delim: Delimiter for field labels field labels longer than maxlen will preferably be truncated at delimiter. @param repl: Replacement string for truncated part. @param truncend: Truncate the end of label name if True. (Default) The beginning part of label will be truncated if False. """ if len(label) <= maxlen: return label else: maxlen -= len(repl) if delim is not None: if truncend: end = label.rfind(delim, 0, maxlen) if end > 0: return label[:end+1] + repl else: start = label.find(delim, len(label) - maxlen) if start > 0: return repl + label[start:] if truncend: return label[:maxlen] + repl else: return repl + label[-maxlen:]
python
def fixLabel(label, maxlen, delim=None, repl='', truncend=True): """Truncate long graph and field labels. @param label: Label text. @param maxlen: Maximum field label length in characters. No maximum field label length is enforced by default. @param delim: Delimiter for field labels field labels longer than maxlen will preferably be truncated at delimiter. @param repl: Replacement string for truncated part. @param truncend: Truncate the end of label name if True. (Default) The beginning part of label will be truncated if False. """ if len(label) <= maxlen: return label else: maxlen -= len(repl) if delim is not None: if truncend: end = label.rfind(delim, 0, maxlen) if end > 0: return label[:end+1] + repl else: start = label.find(delim, len(label) - maxlen) if start > 0: return repl + label[start:] if truncend: return label[:maxlen] + repl else: return repl + label[-maxlen:]
[ "def", "fixLabel", "(", "label", ",", "maxlen", ",", "delim", "=", "None", ",", "repl", "=", "''", ",", "truncend", "=", "True", ")", ":", "if", "len", "(", "label", ")", "<=", "maxlen", ":", "return", "label", "else", ":", "maxlen", "-=", "len", "(", "repl", ")", "if", "delim", "is", "not", "None", ":", "if", "truncend", ":", "end", "=", "label", ".", "rfind", "(", "delim", ",", "0", ",", "maxlen", ")", "if", "end", ">", "0", ":", "return", "label", "[", ":", "end", "+", "1", "]", "+", "repl", "else", ":", "start", "=", "label", ".", "find", "(", "delim", ",", "len", "(", "label", ")", "-", "maxlen", ")", "if", "start", ">", "0", ":", "return", "repl", "+", "label", "[", "start", ":", "]", "if", "truncend", ":", "return", "label", "[", ":", "maxlen", "]", "+", "repl", "else", ":", "return", "repl", "+", "label", "[", "-", "maxlen", ":", "]" ]
Truncate long graph and field labels. @param label: Label text. @param maxlen: Maximum field label length in characters. No maximum field label length is enforced by default. @param delim: Delimiter for field labels field labels longer than maxlen will preferably be truncated at delimiter. @param repl: Replacement string for truncated part. @param truncend: Truncate the end of label name if True. (Default) The beginning part of label will be truncated if False.
[ "Truncate", "long", "graph", "and", "field", "labels", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L975-L1004
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._parseEnv
def _parseEnv(self, env=None): """Private method for parsing through environment variables. Parses for environment variables common to all Munin Plugins: - MUNIN_STATEFILE - MUNIN_CAP_DIRTY_CONFIG - nested_graphs @param env: Dictionary of environment variables. (Only used for testing. initialized automatically by constructor. """ if not env: env = self._env if env.has_key('MUNIN_STATEFILE'): self._stateFile = env.get('MUNIN_STATEFILE') else: self._stateFile = '/tmp/munin-state-%s' % self.plugin_name if env.has_key('MUNIN_CAP_DIRTY_CONFIG'): self._dirtyConfig = True
python
def _parseEnv(self, env=None): """Private method for parsing through environment variables. Parses for environment variables common to all Munin Plugins: - MUNIN_STATEFILE - MUNIN_CAP_DIRTY_CONFIG - nested_graphs @param env: Dictionary of environment variables. (Only used for testing. initialized automatically by constructor. """ if not env: env = self._env if env.has_key('MUNIN_STATEFILE'): self._stateFile = env.get('MUNIN_STATEFILE') else: self._stateFile = '/tmp/munin-state-%s' % self.plugin_name if env.has_key('MUNIN_CAP_DIRTY_CONFIG'): self._dirtyConfig = True
[ "def", "_parseEnv", "(", "self", ",", "env", "=", "None", ")", ":", "if", "not", "env", ":", "env", "=", "self", ".", "_env", "if", "env", ".", "has_key", "(", "'MUNIN_STATEFILE'", ")", ":", "self", ".", "_stateFile", "=", "env", ".", "get", "(", "'MUNIN_STATEFILE'", ")", "else", ":", "self", ".", "_stateFile", "=", "'/tmp/munin-state-%s'", "%", "self", ".", "plugin_name", "if", "env", ".", "has_key", "(", "'MUNIN_CAP_DIRTY_CONFIG'", ")", ":", "self", ".", "_dirtyConfig", "=", "True" ]
Private method for parsing through environment variables. Parses for environment variables common to all Munin Plugins: - MUNIN_STATEFILE - MUNIN_CAP_DIRTY_CONFIG - nested_graphs @param env: Dictionary of environment variables. (Only used for testing. initialized automatically by constructor.
[ "Private", "method", "for", "parsing", "through", "environment", "variables", ".", "Parses", "for", "environment", "variables", "common", "to", "all", "Munin", "Plugins", ":", "-", "MUNIN_STATEFILE", "-", "MUNIN_CAP_DIRTY_CONFIG", "-", "nested_graphs" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L149-L169
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._getGraph
def _getGraph(self, graph_name, fail_noexist=False): """Private method for returning graph object with name graph_name. @param graph_name: Graph Name @param fail_noexist: If true throw exception if there is no graph with name graph_name. @return: Graph Object or None """ graph = self._graphDict.get(graph_name) if fail_noexist and graph is None: raise AttributeError("Invalid graph name: %s" % graph_name) else: return graph
python
def _getGraph(self, graph_name, fail_noexist=False): """Private method for returning graph object with name graph_name. @param graph_name: Graph Name @param fail_noexist: If true throw exception if there is no graph with name graph_name. @return: Graph Object or None """ graph = self._graphDict.get(graph_name) if fail_noexist and graph is None: raise AttributeError("Invalid graph name: %s" % graph_name) else: return graph
[ "def", "_getGraph", "(", "self", ",", "graph_name", ",", "fail_noexist", "=", "False", ")", ":", "graph", "=", "self", ".", "_graphDict", ".", "get", "(", "graph_name", ")", "if", "fail_noexist", "and", "graph", "is", "None", ":", "raise", "AttributeError", "(", "\"Invalid graph name: %s\"", "%", "graph_name", ")", "else", ":", "return", "graph" ]
Private method for returning graph object with name graph_name. @param graph_name: Graph Name @param fail_noexist: If true throw exception if there is no graph with name graph_name. @return: Graph Object or None
[ "Private", "method", "for", "returning", "graph", "object", "with", "name", "graph_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L171-L184
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._getSubGraph
def _getSubGraph(self, parent_name, graph_name, fail_noexist=False): """Private method for returning subgraph object with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param fail_noexist: If true throw exception if there is no subgraph with name graph_name. @return: Graph Object or None """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name) is not None: subgraphs = self._subgraphDict.get(parent_name) if subgraphs is not None: subgraph = subgraphs.get(graph_name) if fail_noexist and subgraph is None: raise AttributeError("Invalid subgraph name %s" "for graph %s." % (graph_name, parent_name)) else: return subgraph else: raise AttributeError("Parent graph %s has no subgraphs." % (parent_name,)) else: raise AttributeError("Invalid parent graph name %s " "for subgraph %s." % (parent_name, graph_name))
python
def _getSubGraph(self, parent_name, graph_name, fail_noexist=False): """Private method for returning subgraph object with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param fail_noexist: If true throw exception if there is no subgraph with name graph_name. @return: Graph Object or None """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name) is not None: subgraphs = self._subgraphDict.get(parent_name) if subgraphs is not None: subgraph = subgraphs.get(graph_name) if fail_noexist and subgraph is None: raise AttributeError("Invalid subgraph name %s" "for graph %s." % (graph_name, parent_name)) else: return subgraph else: raise AttributeError("Parent graph %s has no subgraphs." % (parent_name,)) else: raise AttributeError("Invalid parent graph name %s " "for subgraph %s." % (parent_name, graph_name))
[ "def", "_getSubGraph", "(", "self", ",", "parent_name", ",", "graph_name", ",", "fail_noexist", "=", "False", ")", ":", "if", "not", "self", ".", "isMultigraph", ":", "raise", "AttributeError", "(", "\"Simple Munin Plugins cannot have subgraphs.\"", ")", "if", "self", ".", "_graphDict", ".", "has_key", "(", "parent_name", ")", "is", "not", "None", ":", "subgraphs", "=", "self", ".", "_subgraphDict", ".", "get", "(", "parent_name", ")", "if", "subgraphs", "is", "not", "None", ":", "subgraph", "=", "subgraphs", ".", "get", "(", "graph_name", ")", "if", "fail_noexist", "and", "subgraph", "is", "None", ":", "raise", "AttributeError", "(", "\"Invalid subgraph name %s\"", "\"for graph %s.\"", "%", "(", "graph_name", ",", "parent_name", ")", ")", "else", ":", "return", "subgraph", "else", ":", "raise", "AttributeError", "(", "\"Parent graph %s has no subgraphs.\"", "%", "(", "parent_name", ",", ")", ")", "else", ":", "raise", "AttributeError", "(", "\"Invalid parent graph name %s \"", "\"for subgraph %s.\"", "%", "(", "parent_name", ",", "graph_name", ")", ")" ]
Private method for returning subgraph object with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param fail_noexist: If true throw exception if there is no subgraph with name graph_name. @return: Graph Object or None
[ "Private", "method", "for", "returning", "subgraph", "object", "with", "name", "graph_name", "and", "parent", "graph", "with", "name", "parent_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L186-L214
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._getMultigraphID
def _getMultigraphID(self, graph_name, subgraph_name=None): """Private method for generating Multigraph ID from graph name and subgraph name. @param graph_name: Graph Name. @param subgraph_name: Subgraph Name. @return: Multigraph ID. """ if self.isMultiInstance and self._instanceName is not None: if subgraph_name is None: return "%s_%s" % (graph_name, self._instanceName) else: return "%s_%s.%s_%s" % (graph_name, self._instanceName, subgraph_name, self._instanceName) else: if subgraph_name is None: return graph_name else: return "%s.%s" % (graph_name, subgraph_name)
python
def _getMultigraphID(self, graph_name, subgraph_name=None): """Private method for generating Multigraph ID from graph name and subgraph name. @param graph_name: Graph Name. @param subgraph_name: Subgraph Name. @return: Multigraph ID. """ if self.isMultiInstance and self._instanceName is not None: if subgraph_name is None: return "%s_%s" % (graph_name, self._instanceName) else: return "%s_%s.%s_%s" % (graph_name, self._instanceName, subgraph_name, self._instanceName) else: if subgraph_name is None: return graph_name else: return "%s.%s" % (graph_name, subgraph_name)
[ "def", "_getMultigraphID", "(", "self", ",", "graph_name", ",", "subgraph_name", "=", "None", ")", ":", "if", "self", ".", "isMultiInstance", "and", "self", ".", "_instanceName", "is", "not", "None", ":", "if", "subgraph_name", "is", "None", ":", "return", "\"%s_%s\"", "%", "(", "graph_name", ",", "self", ".", "_instanceName", ")", "else", ":", "return", "\"%s_%s.%s_%s\"", "%", "(", "graph_name", ",", "self", ".", "_instanceName", ",", "subgraph_name", ",", "self", ".", "_instanceName", ")", "else", ":", "if", "subgraph_name", "is", "None", ":", "return", "graph_name", "else", ":", "return", "\"%s.%s\"", "%", "(", "graph_name", ",", "subgraph_name", ")" ]
Private method for generating Multigraph ID from graph name and subgraph name. @param graph_name: Graph Name. @param subgraph_name: Subgraph Name. @return: Multigraph ID.
[ "Private", "method", "for", "generating", "Multigraph", "ID", "from", "graph", "name", "and", "subgraph", "name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L216-L235
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._formatConfig
def _formatConfig(self, conf_dict): """Formats configuration directory from Munin Graph and returns multi-line value entries for the plugin config cycle. @param conf_dict: Configuration directory. @return: Multi-line text. """ confs = [] graph_dict = conf_dict['graph'] field_list = conf_dict['fields'] # Order and format Graph Attributes title = graph_dict.get('title') if title is not None: if self.isMultiInstance and self._instanceLabel is not None: if self._instanceLabelType == 'suffix': confs.append("graph_%s %s - %s" % ('title', title, self._instanceLabel,)) elif self._instanceLabelType == 'prefix': confs.append("graph_%s %s - %s" % ('title', self._instanceLabel, title,)) else: confs.append("graph_%s %s" % ('title', title)) for key in ('category', 'vlabel', 'info', 'args', 'period', 'scale', 'total', 'order', 'printf', 'width', 'height'): val = graph_dict.get(key) if val is not None: if isinstance(val, bool): if val: val = "yes" else: val = "no" confs.append("graph_%s %s" % (key, val)) # Order and Format Field Attributes for (field_name, field_attrs) in field_list: for key in ('label', 'type', 'draw', 'info', 'extinfo', 'colour', 'negative', 'graph', 'min', 'max', 'cdef', 'line', 'warning', 'critical'): val = field_attrs.get(key) if val is not None: if isinstance(val, bool): if val: val = "yes" else: val = "no" confs.append("%s.%s %s" % (field_name, key, val)) return "\n".join(confs)
python
def _formatConfig(self, conf_dict): """Formats configuration directory from Munin Graph and returns multi-line value entries for the plugin config cycle. @param conf_dict: Configuration directory. @return: Multi-line text. """ confs = [] graph_dict = conf_dict['graph'] field_list = conf_dict['fields'] # Order and format Graph Attributes title = graph_dict.get('title') if title is not None: if self.isMultiInstance and self._instanceLabel is not None: if self._instanceLabelType == 'suffix': confs.append("graph_%s %s - %s" % ('title', title, self._instanceLabel,)) elif self._instanceLabelType == 'prefix': confs.append("graph_%s %s - %s" % ('title', self._instanceLabel, title,)) else: confs.append("graph_%s %s" % ('title', title)) for key in ('category', 'vlabel', 'info', 'args', 'period', 'scale', 'total', 'order', 'printf', 'width', 'height'): val = graph_dict.get(key) if val is not None: if isinstance(val, bool): if val: val = "yes" else: val = "no" confs.append("graph_%s %s" % (key, val)) # Order and Format Field Attributes for (field_name, field_attrs) in field_list: for key in ('label', 'type', 'draw', 'info', 'extinfo', 'colour', 'negative', 'graph', 'min', 'max', 'cdef', 'line', 'warning', 'critical'): val = field_attrs.get(key) if val is not None: if isinstance(val, bool): if val: val = "yes" else: val = "no" confs.append("%s.%s %s" % (field_name, key, val)) return "\n".join(confs)
[ "def", "_formatConfig", "(", "self", ",", "conf_dict", ")", ":", "confs", "=", "[", "]", "graph_dict", "=", "conf_dict", "[", "'graph'", "]", "field_list", "=", "conf_dict", "[", "'fields'", "]", "# Order and format Graph Attributes", "title", "=", "graph_dict", ".", "get", "(", "'title'", ")", "if", "title", "is", "not", "None", ":", "if", "self", ".", "isMultiInstance", "and", "self", ".", "_instanceLabel", "is", "not", "None", ":", "if", "self", ".", "_instanceLabelType", "==", "'suffix'", ":", "confs", ".", "append", "(", "\"graph_%s %s - %s\"", "%", "(", "'title'", ",", "title", ",", "self", ".", "_instanceLabel", ",", ")", ")", "elif", "self", ".", "_instanceLabelType", "==", "'prefix'", ":", "confs", ".", "append", "(", "\"graph_%s %s - %s\"", "%", "(", "'title'", ",", "self", ".", "_instanceLabel", ",", "title", ",", ")", ")", "else", ":", "confs", ".", "append", "(", "\"graph_%s %s\"", "%", "(", "'title'", ",", "title", ")", ")", "for", "key", "in", "(", "'category'", ",", "'vlabel'", ",", "'info'", ",", "'args'", ",", "'period'", ",", "'scale'", ",", "'total'", ",", "'order'", ",", "'printf'", ",", "'width'", ",", "'height'", ")", ":", "val", "=", "graph_dict", ".", "get", "(", "key", ")", "if", "val", "is", "not", "None", ":", "if", "isinstance", "(", "val", ",", "bool", ")", ":", "if", "val", ":", "val", "=", "\"yes\"", "else", ":", "val", "=", "\"no\"", "confs", ".", "append", "(", "\"graph_%s %s\"", "%", "(", "key", ",", "val", ")", ")", "# Order and Format Field Attributes", "for", "(", "field_name", ",", "field_attrs", ")", "in", "field_list", ":", "for", "key", "in", "(", "'label'", ",", "'type'", ",", "'draw'", ",", "'info'", ",", "'extinfo'", ",", "'colour'", ",", "'negative'", ",", "'graph'", ",", "'min'", ",", "'max'", ",", "'cdef'", ",", "'line'", ",", "'warning'", ",", "'critical'", ")", ":", "val", "=", "field_attrs", ".", "get", "(", "key", ")", "if", "val", "is", "not", "None", ":", "if", "isinstance", "(", "val", ",", "bool", ")", ":", "if", "val", ":", "val", "=", "\"yes\"", "else", ":", "val", "=", "\"no\"", "confs", ".", "append", "(", "\"%s.%s %s\"", "%", "(", "field_name", ",", "key", ",", "val", ")", ")", "return", "\"\\n\"", ".", "join", "(", "confs", ")" ]
Formats configuration directory from Munin Graph and returns multi-line value entries for the plugin config cycle. @param conf_dict: Configuration directory. @return: Multi-line text.
[ "Formats", "configuration", "directory", "from", "Munin", "Graph", "and", "returns", "multi", "-", "line", "value", "entries", "for", "the", "plugin", "config", "cycle", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L237-L287
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin._formatVals
def _formatVals(self, val_list): """Formats value list from Munin Graph and returns multi-line value entries for the plugin fetch cycle. @param val_list: List of name-value pairs. @return: Multi-line text. """ vals = [] for (name, val) in val_list: if val is not None: if isinstance(val, float): vals.append("%s.value %f" % (name, val)) else: vals.append("%s.value %s" % (name, val)) else: vals.append("%s.value U" % (name,)) return "\n".join(vals)
python
def _formatVals(self, val_list): """Formats value list from Munin Graph and returns multi-line value entries for the plugin fetch cycle. @param val_list: List of name-value pairs. @return: Multi-line text. """ vals = [] for (name, val) in val_list: if val is not None: if isinstance(val, float): vals.append("%s.value %f" % (name, val)) else: vals.append("%s.value %s" % (name, val)) else: vals.append("%s.value U" % (name,)) return "\n".join(vals)
[ "def", "_formatVals", "(", "self", ",", "val_list", ")", ":", "vals", "=", "[", "]", "for", "(", "name", ",", "val", ")", "in", "val_list", ":", "if", "val", "is", "not", "None", ":", "if", "isinstance", "(", "val", ",", "float", ")", ":", "vals", ".", "append", "(", "\"%s.value %f\"", "%", "(", "name", ",", "val", ")", ")", "else", ":", "vals", ".", "append", "(", "\"%s.value %s\"", "%", "(", "name", ",", "val", ")", ")", "else", ":", "vals", ".", "append", "(", "\"%s.value U\"", "%", "(", "name", ",", ")", ")", "return", "\"\\n\"", ".", "join", "(", "vals", ")" ]
Formats value list from Munin Graph and returns multi-line value entries for the plugin fetch cycle. @param val_list: List of name-value pairs. @return: Multi-line text.
[ "Formats", "value", "list", "from", "Munin", "Graph", "and", "returns", "multi", "-", "line", "value", "entries", "for", "the", "plugin", "fetch", "cycle", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L289-L306
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.envGet
def envGet(self, name, default=None, conv=None): """Return value for environment variable or None. @param name: Name of environment variable. @param default: Default value if variable is undefined. @param conv: Function for converting value to desired type. @return: Value of environment variable. """ if self._env.has_key(name): if conv is not None: return conv(self._env.get(name)) else: return self._env.get(name) else: return default
python
def envGet(self, name, default=None, conv=None): """Return value for environment variable or None. @param name: Name of environment variable. @param default: Default value if variable is undefined. @param conv: Function for converting value to desired type. @return: Value of environment variable. """ if self._env.has_key(name): if conv is not None: return conv(self._env.get(name)) else: return self._env.get(name) else: return default
[ "def", "envGet", "(", "self", ",", "name", ",", "default", "=", "None", ",", "conv", "=", "None", ")", ":", "if", "self", ".", "_env", ".", "has_key", "(", "name", ")", ":", "if", "conv", "is", "not", "None", ":", "return", "conv", "(", "self", ".", "_env", ".", "get", "(", "name", ")", ")", "else", ":", "return", "self", ".", "_env", ".", "get", "(", "name", ")", "else", ":", "return", "default" ]
Return value for environment variable or None. @param name: Name of environment variable. @param default: Default value if variable is undefined. @param conv: Function for converting value to desired type. @return: Value of environment variable.
[ "Return", "value", "for", "environment", "variable", "or", "None", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L317-L332
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.envGetList
def envGetList(self, name, attr_regex = '^\w+$', conv=None): """Parse the plugin environment variables to return list from variable with name list_<name>. The value of the variable must be a comma separated list of items. @param name: Name of list. (Also determines suffix for environment variable name.) @param attr_regex: If the regex is defined, the items in the list are ignored unless they comply with the format dictated by the match regex. @param conv: Function for converting value to desired type. @return: List of items. """ key = "list_%s" % name item_list = [] if self._env.has_key(key): if attr_regex: recomp = re.compile(attr_regex) else: recomp = None for attr in self._env[key].split(','): attr = attr.strip() if recomp is None or recomp.search(attr): if conv is not None: item_list.append(conv(attr)) else: item_list.append(attr) return item_list
python
def envGetList(self, name, attr_regex = '^\w+$', conv=None): """Parse the plugin environment variables to return list from variable with name list_<name>. The value of the variable must be a comma separated list of items. @param name: Name of list. (Also determines suffix for environment variable name.) @param attr_regex: If the regex is defined, the items in the list are ignored unless they comply with the format dictated by the match regex. @param conv: Function for converting value to desired type. @return: List of items. """ key = "list_%s" % name item_list = [] if self._env.has_key(key): if attr_regex: recomp = re.compile(attr_regex) else: recomp = None for attr in self._env[key].split(','): attr = attr.strip() if recomp is None or recomp.search(attr): if conv is not None: item_list.append(conv(attr)) else: item_list.append(attr) return item_list
[ "def", "envGetList", "(", "self", ",", "name", ",", "attr_regex", "=", "'^\\w+$'", ",", "conv", "=", "None", ")", ":", "key", "=", "\"list_%s\"", "%", "name", "item_list", "=", "[", "]", "if", "self", ".", "_env", ".", "has_key", "(", "key", ")", ":", "if", "attr_regex", ":", "recomp", "=", "re", ".", "compile", "(", "attr_regex", ")", "else", ":", "recomp", "=", "None", "for", "attr", "in", "self", ".", "_env", "[", "key", "]", ".", "split", "(", "','", ")", ":", "attr", "=", "attr", ".", "strip", "(", ")", "if", "recomp", "is", "None", "or", "recomp", ".", "search", "(", "attr", ")", ":", "if", "conv", "is", "not", "None", ":", "item_list", ".", "append", "(", "conv", "(", "attr", ")", ")", "else", ":", "item_list", ".", "append", "(", "attr", ")", "return", "item_list" ]
Parse the plugin environment variables to return list from variable with name list_<name>. The value of the variable must be a comma separated list of items. @param name: Name of list. (Also determines suffix for environment variable name.) @param attr_regex: If the regex is defined, the items in the list are ignored unless they comply with the format dictated by the match regex. @param conv: Function for converting value to desired type. @return: List of items.
[ "Parse", "the", "plugin", "environment", "variables", "to", "return", "list", "from", "variable", "with", "name", "list_<name", ">", ".", "The", "value", "of", "the", "variable", "must", "be", "a", "comma", "separated", "list", "of", "items", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L335-L364
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.envRegisterFilter
def envRegisterFilter(self, name, attr_regex = '^\w+$', default = True): """Register filter for including, excluding attributes in graphs through the use of include_<name> and exclude_<name> environment variables. The value of the variables must be a comma separated list of items. @param name: Name of filter. (Also determines suffix for environment variable name.) @param attr_regex: Regular expression string for checking valid items. @param default: Filter default. Applies when the include list is not defined and the attribute is not in the exclude list. """ attrs = {} for prefix in ('include', 'exclude'): key = "%s_%s" % (prefix, name) val = self._env.get(key) if val: attrs[prefix] = [attr.strip() for attr in val.split(',')] else: attrs[prefix] = [] self._filters[name] = MuninAttrFilter(attrs['include'], attrs['exclude'], attr_regex, default)
python
def envRegisterFilter(self, name, attr_regex = '^\w+$', default = True): """Register filter for including, excluding attributes in graphs through the use of include_<name> and exclude_<name> environment variables. The value of the variables must be a comma separated list of items. @param name: Name of filter. (Also determines suffix for environment variable name.) @param attr_regex: Regular expression string for checking valid items. @param default: Filter default. Applies when the include list is not defined and the attribute is not in the exclude list. """ attrs = {} for prefix in ('include', 'exclude'): key = "%s_%s" % (prefix, name) val = self._env.get(key) if val: attrs[prefix] = [attr.strip() for attr in val.split(',')] else: attrs[prefix] = [] self._filters[name] = MuninAttrFilter(attrs['include'], attrs['exclude'], attr_regex, default)
[ "def", "envRegisterFilter", "(", "self", ",", "name", ",", "attr_regex", "=", "'^\\w+$'", ",", "default", "=", "True", ")", ":", "attrs", "=", "{", "}", "for", "prefix", "in", "(", "'include'", ",", "'exclude'", ")", ":", "key", "=", "\"%s_%s\"", "%", "(", "prefix", ",", "name", ")", "val", "=", "self", ".", "_env", ".", "get", "(", "key", ")", "if", "val", ":", "attrs", "[", "prefix", "]", "=", "[", "attr", ".", "strip", "(", ")", "for", "attr", "in", "val", ".", "split", "(", "','", ")", "]", "else", ":", "attrs", "[", "prefix", "]", "=", "[", "]", "self", ".", "_filters", "[", "name", "]", "=", "MuninAttrFilter", "(", "attrs", "[", "'include'", "]", ",", "attrs", "[", "'exclude'", "]", ",", "attr_regex", ",", "default", ")" ]
Register filter for including, excluding attributes in graphs through the use of include_<name> and exclude_<name> environment variables. The value of the variables must be a comma separated list of items. @param name: Name of filter. (Also determines suffix for environment variable name.) @param attr_regex: Regular expression string for checking valid items. @param default: Filter default. Applies when the include list is not defined and the attribute is not in the exclude list.
[ "Register", "filter", "for", "including", "excluding", "attributes", "in", "graphs", "through", "the", "use", "of", "include_<name", ">", "and", "exclude_<name", ">", "environment", "variables", ".", "The", "value", "of", "the", "variables", "must", "be", "a", "comma", "separated", "list", "of", "items", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L366-L387
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.envCheckFilter
def envCheckFilter(self, name, attr): """Check if a specific graph attribute is enabled or disabled through the use of a filter based on include_<name> and exclude_<name> environment variables. @param name: Name of the Filter. @param attr: Name of the Attribute. @return: Return True if the attribute is enabled. """ flt = self._filters.get(name) if flt: return flt.check(attr) else: raise AttributeError("Undefined filter: %s" % name)
python
def envCheckFilter(self, name, attr): """Check if a specific graph attribute is enabled or disabled through the use of a filter based on include_<name> and exclude_<name> environment variables. @param name: Name of the Filter. @param attr: Name of the Attribute. @return: Return True if the attribute is enabled. """ flt = self._filters.get(name) if flt: return flt.check(attr) else: raise AttributeError("Undefined filter: %s" % name)
[ "def", "envCheckFilter", "(", "self", ",", "name", ",", "attr", ")", ":", "flt", "=", "self", ".", "_filters", ".", "get", "(", "name", ")", "if", "flt", ":", "return", "flt", ".", "check", "(", "attr", ")", "else", ":", "raise", "AttributeError", "(", "\"Undefined filter: %s\"", "%", "name", ")" ]
Check if a specific graph attribute is enabled or disabled through the use of a filter based on include_<name> and exclude_<name> environment variables. @param name: Name of the Filter. @param attr: Name of the Attribute. @return: Return True if the attribute is enabled.
[ "Check", "if", "a", "specific", "graph", "attribute", "is", "enabled", "or", "disabled", "through", "the", "use", "of", "a", "filter", "based", "on", "include_<name", ">", "and", "exclude_<name", ">", "environment", "variables", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L389-L403
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.envCheckFlag
def envCheckFlag(self, name, default = False): """Check graph flag for enabling / disabling attributes through the use of <name> environment variable. @param name: Name of flag. (Also determines the environment variable name.) @param default: Boolean (True or False). Default value for flag. @return: Return True if the flag is enabled. """ if self._flags.has_key(name): return self._flags[name] else: val = self._env.get(name) if val is None: return default elif val.lower() in ['yes', 'on']: self._flags[name] = True return True elif val.lower() in ['no', 'off']: self._flags[name] = False return False else: raise AttributeError("Value for flag %s, must be yes, no, on or off" % name)
python
def envCheckFlag(self, name, default = False): """Check graph flag for enabling / disabling attributes through the use of <name> environment variable. @param name: Name of flag. (Also determines the environment variable name.) @param default: Boolean (True or False). Default value for flag. @return: Return True if the flag is enabled. """ if self._flags.has_key(name): return self._flags[name] else: val = self._env.get(name) if val is None: return default elif val.lower() in ['yes', 'on']: self._flags[name] = True return True elif val.lower() in ['no', 'off']: self._flags[name] = False return False else: raise AttributeError("Value for flag %s, must be yes, no, on or off" % name)
[ "def", "envCheckFlag", "(", "self", ",", "name", ",", "default", "=", "False", ")", ":", "if", "self", ".", "_flags", ".", "has_key", "(", "name", ")", ":", "return", "self", ".", "_flags", "[", "name", "]", "else", ":", "val", "=", "self", ".", "_env", ".", "get", "(", "name", ")", "if", "val", "is", "None", ":", "return", "default", "elif", "val", ".", "lower", "(", ")", "in", "[", "'yes'", ",", "'on'", "]", ":", "self", ".", "_flags", "[", "name", "]", "=", "True", "return", "True", "elif", "val", ".", "lower", "(", ")", "in", "[", "'no'", ",", "'off'", "]", ":", "self", ".", "_flags", "[", "name", "]", "=", "False", "return", "False", "else", ":", "raise", "AttributeError", "(", "\"Value for flag %s, must be yes, no, on or off\"", "%", "name", ")" ]
Check graph flag for enabling / disabling attributes through the use of <name> environment variable. @param name: Name of flag. (Also determines the environment variable name.) @param default: Boolean (True or False). Default value for flag. @return: Return True if the flag is enabled.
[ "Check", "graph", "flag", "for", "enabling", "/", "disabling", "attributes", "through", "the", "use", "of", "<name", ">", "environment", "variable", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L405-L429
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.saveState
def saveState(self, stateObj): """Utility methos to save plugin state stored in stateObj to persistent storage to permit access to previous state in subsequent plugin runs. Any object that can be pickled and unpickled can be used to store the plugin state. @param stateObj: Object that stores plugin state. """ try: fp = open(self._stateFile, 'w') pickle.dump(stateObj, fp) except: raise IOError("Failure in storing plugin state in file: %s" % self._stateFile) return True
python
def saveState(self, stateObj): """Utility methos to save plugin state stored in stateObj to persistent storage to permit access to previous state in subsequent plugin runs. Any object that can be pickled and unpickled can be used to store the plugin state. @param stateObj: Object that stores plugin state. """ try: fp = open(self._stateFile, 'w') pickle.dump(stateObj, fp) except: raise IOError("Failure in storing plugin state in file: %s" % self._stateFile) return True
[ "def", "saveState", "(", "self", ",", "stateObj", ")", ":", "try", ":", "fp", "=", "open", "(", "self", ".", "_stateFile", ",", "'w'", ")", "pickle", ".", "dump", "(", "stateObj", ",", "fp", ")", "except", ":", "raise", "IOError", "(", "\"Failure in storing plugin state in file: %s\"", "%", "self", ".", "_stateFile", ")", "return", "True" ]
Utility methos to save plugin state stored in stateObj to persistent storage to permit access to previous state in subsequent plugin runs. Any object that can be pickled and unpickled can be used to store the plugin state. @param stateObj: Object that stores plugin state.
[ "Utility", "methos", "to", "save", "plugin", "state", "stored", "in", "stateObj", "to", "persistent", "storage", "to", "permit", "access", "to", "previous", "state", "in", "subsequent", "plugin", "runs", ".", "Any", "object", "that", "can", "be", "pickled", "and", "unpickled", "can", "be", "used", "to", "store", "the", "plugin", "state", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L448-L464
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.restoreState
def restoreState(self): """Utility method to restore plugin state from persistent storage to permit access to previous plugin state. @return: Object that stores plugin state. """ if os.path.exists(self._stateFile): try: fp = open(self._stateFile, 'r') stateObj = pickle.load(fp) except: raise IOError("Failure in reading plugin state from file: %s" % self._stateFile) return stateObj return None
python
def restoreState(self): """Utility method to restore plugin state from persistent storage to permit access to previous plugin state. @return: Object that stores plugin state. """ if os.path.exists(self._stateFile): try: fp = open(self._stateFile, 'r') stateObj = pickle.load(fp) except: raise IOError("Failure in reading plugin state from file: %s" % self._stateFile) return stateObj return None
[ "def", "restoreState", "(", "self", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "_stateFile", ")", ":", "try", ":", "fp", "=", "open", "(", "self", ".", "_stateFile", ",", "'r'", ")", "stateObj", "=", "pickle", ".", "load", "(", "fp", ")", "except", ":", "raise", "IOError", "(", "\"Failure in reading plugin state from file: %s\"", "%", "self", ".", "_stateFile", ")", "return", "stateObj", "return", "None" ]
Utility method to restore plugin state from persistent storage to permit access to previous plugin state. @return: Object that stores plugin state.
[ "Utility", "method", "to", "restore", "plugin", "state", "from", "persistent", "storage", "to", "permit", "access", "to", "previous", "plugin", "state", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L466-L481
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.appendGraph
def appendGraph(self, graph_name, graph): """Utility method to associate Graph Object to Plugin. This utility method is for use in constructor of child classes for associating a MuninGraph instances to the plugin. @param graph_name: Graph Name @param graph: MuninGraph Instance """ self._graphDict[graph_name] = graph self._graphNames.append(graph_name) if not self.isMultigraph and len(self._graphNames) > 1: raise AttributeError("Simple Munin Plugins cannot have more than one graph.")
python
def appendGraph(self, graph_name, graph): """Utility method to associate Graph Object to Plugin. This utility method is for use in constructor of child classes for associating a MuninGraph instances to the plugin. @param graph_name: Graph Name @param graph: MuninGraph Instance """ self._graphDict[graph_name] = graph self._graphNames.append(graph_name) if not self.isMultigraph and len(self._graphNames) > 1: raise AttributeError("Simple Munin Plugins cannot have more than one graph.")
[ "def", "appendGraph", "(", "self", ",", "graph_name", ",", "graph", ")", ":", "self", ".", "_graphDict", "[", "graph_name", "]", "=", "graph", "self", ".", "_graphNames", ".", "append", "(", "graph_name", ")", "if", "not", "self", ".", "isMultigraph", "and", "len", "(", "self", ".", "_graphNames", ")", ">", "1", ":", "raise", "AttributeError", "(", "\"Simple Munin Plugins cannot have more than one graph.\"", ")" ]
Utility method to associate Graph Object to Plugin. This utility method is for use in constructor of child classes for associating a MuninGraph instances to the plugin. @param graph_name: Graph Name @param graph: MuninGraph Instance
[ "Utility", "method", "to", "associate", "Graph", "Object", "to", "Plugin", ".", "This", "utility", "method", "is", "for", "use", "in", "constructor", "of", "child", "classes", "for", "associating", "a", "MuninGraph", "instances", "to", "the", "plugin", ".", "@param", "graph_name", ":", "Graph", "Name", "@param", "graph", ":", "MuninGraph", "Instance" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L483-L496
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.appendSubgraph
def appendSubgraph(self, parent_name, graph_name, graph): """Utility method to associate Subgraph Instance to Root Graph Instance. This utility method is for use in constructor of child classes for associating a MuninGraph Subgraph instance with a Root Graph instance. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param graph: MuninGraph Instance """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name): if not self._subgraphDict.has_key(parent_name): self._subgraphDict[parent_name] = {} self._subgraphNames[parent_name] = [] self._subgraphDict[parent_name][graph_name] = graph self._subgraphNames[parent_name].append(graph_name) else: raise AttributeError("Invalid parent graph name %s used for subgraph %s." % (parent_name, graph_name))
python
def appendSubgraph(self, parent_name, graph_name, graph): """Utility method to associate Subgraph Instance to Root Graph Instance. This utility method is for use in constructor of child classes for associating a MuninGraph Subgraph instance with a Root Graph instance. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param graph: MuninGraph Instance """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name): if not self._subgraphDict.has_key(parent_name): self._subgraphDict[parent_name] = {} self._subgraphNames[parent_name] = [] self._subgraphDict[parent_name][graph_name] = graph self._subgraphNames[parent_name].append(graph_name) else: raise AttributeError("Invalid parent graph name %s used for subgraph %s." % (parent_name, graph_name))
[ "def", "appendSubgraph", "(", "self", ",", "parent_name", ",", "graph_name", ",", "graph", ")", ":", "if", "not", "self", ".", "isMultigraph", ":", "raise", "AttributeError", "(", "\"Simple Munin Plugins cannot have subgraphs.\"", ")", "if", "self", ".", "_graphDict", ".", "has_key", "(", "parent_name", ")", ":", "if", "not", "self", ".", "_subgraphDict", ".", "has_key", "(", "parent_name", ")", ":", "self", ".", "_subgraphDict", "[", "parent_name", "]", "=", "{", "}", "self", ".", "_subgraphNames", "[", "parent_name", "]", "=", "[", "]", "self", ".", "_subgraphDict", "[", "parent_name", "]", "[", "graph_name", "]", "=", "graph", "self", ".", "_subgraphNames", "[", "parent_name", "]", ".", "append", "(", "graph_name", ")", "else", ":", "raise", "AttributeError", "(", "\"Invalid parent graph name %s used for subgraph %s.\"", "%", "(", "parent_name", ",", "graph_name", ")", ")" ]
Utility method to associate Subgraph Instance to Root Graph Instance. This utility method is for use in constructor of child classes for associating a MuninGraph Subgraph instance with a Root Graph instance. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param graph: MuninGraph Instance
[ "Utility", "method", "to", "associate", "Subgraph", "Instance", "to", "Root", "Graph", "Instance", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L498-L519
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.setGraphVal
def setGraphVal(self, graph_name, field_name, val): """Utility method to set Value for Field in Graph. The private method is for use in retrieveVals() method of child classes. @param graph_name: Graph Name @param field_name: Field Name. @param val: Value for field. """ graph = self._getGraph(graph_name, True) if graph.hasField(field_name): graph.setVal(field_name, val) else: raise AttributeError("Invalid field name %s for graph %s." % (field_name, graph_name))
python
def setGraphVal(self, graph_name, field_name, val): """Utility method to set Value for Field in Graph. The private method is for use in retrieveVals() method of child classes. @param graph_name: Graph Name @param field_name: Field Name. @param val: Value for field. """ graph = self._getGraph(graph_name, True) if graph.hasField(field_name): graph.setVal(field_name, val) else: raise AttributeError("Invalid field name %s for graph %s." % (field_name, graph_name))
[ "def", "setGraphVal", "(", "self", ",", "graph_name", ",", "field_name", ",", "val", ")", ":", "graph", "=", "self", ".", "_getGraph", "(", "graph_name", ",", "True", ")", "if", "graph", ".", "hasField", "(", "field_name", ")", ":", "graph", ".", "setVal", "(", "field_name", ",", "val", ")", "else", ":", "raise", "AttributeError", "(", "\"Invalid field name %s for graph %s.\"", "%", "(", "field_name", ",", "graph_name", ")", ")" ]
Utility method to set Value for Field in Graph. The private method is for use in retrieveVals() method of child classes. @param graph_name: Graph Name @param field_name: Field Name. @param val: Value for field.
[ "Utility", "method", "to", "set", "Value", "for", "Field", "in", "Graph", ".", "The", "private", "method", "is", "for", "use", "in", "retrieveVals", "()", "method", "of", "child", "classes", ".", "@param", "graph_name", ":", "Graph", "Name", "@param", "field_name", ":", "Field", "Name", ".", "@param", "val", ":", "Value", "for", "field", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L521-L536
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.setSubgraphVal
def setSubgraphVal(self, parent_name, graph_name, field_name, val): """Set Value for Field in Subgraph. The private method is for use in retrieveVals() method of child classes. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @param val: Value for field. """ subgraph = self._getSubGraph(parent_name, graph_name, True) if subgraph.hasField(field_name): subgraph.setVal(field_name, val) else: raise AttributeError("Invalid field name %s for subgraph %s " "of parent graph %s." % (field_name, graph_name, parent_name))
python
def setSubgraphVal(self, parent_name, graph_name, field_name, val): """Set Value for Field in Subgraph. The private method is for use in retrieveVals() method of child classes. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @param val: Value for field. """ subgraph = self._getSubGraph(parent_name, graph_name, True) if subgraph.hasField(field_name): subgraph.setVal(field_name, val) else: raise AttributeError("Invalid field name %s for subgraph %s " "of parent graph %s." % (field_name, graph_name, parent_name))
[ "def", "setSubgraphVal", "(", "self", ",", "parent_name", ",", "graph_name", ",", "field_name", ",", "val", ")", ":", "subgraph", "=", "self", ".", "_getSubGraph", "(", "parent_name", ",", "graph_name", ",", "True", ")", "if", "subgraph", ".", "hasField", "(", "field_name", ")", ":", "subgraph", ".", "setVal", "(", "field_name", ",", "val", ")", "else", ":", "raise", "AttributeError", "(", "\"Invalid field name %s for subgraph %s \"", "\"of parent graph %s.\"", "%", "(", "field_name", ",", "graph_name", ",", "parent_name", ")", ")" ]
Set Value for Field in Subgraph. The private method is for use in retrieveVals() method of child classes. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @param val: Value for field.
[ "Set", "Value", "for", "Field", "in", "Subgraph", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L538-L556
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.getSubgraphList
def getSubgraphList(self, parent_name): """Returns list of names of subgraphs for Root Graph with name parent_name. @param parent_name: Name of Root Graph. @return: List of subgraph names. """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name): return self._subgraphNames[parent_name] or [] else: raise AttributeError("Invalid parent graph name %s." % (parent_name,))
python
def getSubgraphList(self, parent_name): """Returns list of names of subgraphs for Root Graph with name parent_name. @param parent_name: Name of Root Graph. @return: List of subgraph names. """ if not self.isMultigraph: raise AttributeError("Simple Munin Plugins cannot have subgraphs.") if self._graphDict.has_key(parent_name): return self._subgraphNames[parent_name] or [] else: raise AttributeError("Invalid parent graph name %s." % (parent_name,))
[ "def", "getSubgraphList", "(", "self", ",", "parent_name", ")", ":", "if", "not", "self", ".", "isMultigraph", ":", "raise", "AttributeError", "(", "\"Simple Munin Plugins cannot have subgraphs.\"", ")", "if", "self", ".", "_graphDict", ".", "has_key", "(", "parent_name", ")", ":", "return", "self", ".", "_subgraphNames", "[", "parent_name", "]", "or", "[", "]", "else", ":", "raise", "AttributeError", "(", "\"Invalid parent graph name %s.\"", "%", "(", "parent_name", ",", ")", ")" ]
Returns list of names of subgraphs for Root Graph with name parent_name. @param parent_name: Name of Root Graph. @return: List of subgraph names.
[ "Returns", "list", "of", "names", "of", "subgraphs", "for", "Root", "Graph", "with", "name", "parent_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L594-L607
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.graphHasField
def graphHasField(self, graph_name, field_name): """Return true if graph with name graph_name has field with name field_name. @param graph_name: Graph Name @param field_name: Field Name. @return: Boolean """ graph = self._graphDict.get(graph_name, True) return graph.hasField(field_name)
python
def graphHasField(self, graph_name, field_name): """Return true if graph with name graph_name has field with name field_name. @param graph_name: Graph Name @param field_name: Field Name. @return: Boolean """ graph = self._graphDict.get(graph_name, True) return graph.hasField(field_name)
[ "def", "graphHasField", "(", "self", ",", "graph_name", ",", "field_name", ")", ":", "graph", "=", "self", ".", "_graphDict", ".", "get", "(", "graph_name", ",", "True", ")", "return", "graph", ".", "hasField", "(", "field_name", ")" ]
Return true if graph with name graph_name has field with name field_name. @param graph_name: Graph Name @param field_name: Field Name. @return: Boolean
[ "Return", "true", "if", "graph", "with", "name", "graph_name", "has", "field", "with", "name", "field_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L618-L628
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.subGraphHasField
def subGraphHasField(self, parent_name, graph_name, field_name): """Return true if subgraph with name graph_name with parent graph with name parent_name has field with name field_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @return: Boolean """ subgraph = self._getSubGraph(parent_name, graph_name, True) return subgraph.hasField(field_name)
python
def subGraphHasField(self, parent_name, graph_name, field_name): """Return true if subgraph with name graph_name with parent graph with name parent_name has field with name field_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @return: Boolean """ subgraph = self._getSubGraph(parent_name, graph_name, True) return subgraph.hasField(field_name)
[ "def", "subGraphHasField", "(", "self", ",", "parent_name", ",", "graph_name", ",", "field_name", ")", ":", "subgraph", "=", "self", ".", "_getSubGraph", "(", "parent_name", ",", "graph_name", ",", "True", ")", "return", "subgraph", ".", "hasField", "(", "field_name", ")" ]
Return true if subgraph with name graph_name with parent graph with name parent_name has field with name field_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @param field_name: Field Name. @return: Boolean
[ "Return", "true", "if", "subgraph", "with", "name", "graph_name", "with", "parent", "graph", "with", "name", "parent_name", "has", "field", "with", "name", "field_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L630-L641
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.getGraphFieldList
def getGraphFieldList(self, graph_name): """Returns list of names of fields for graph with name graph_name. @param graph_name: Graph Name @return: List of field names for graph. """ graph = self._getGraph(graph_name, True) return graph.getFieldList()
python
def getGraphFieldList(self, graph_name): """Returns list of names of fields for graph with name graph_name. @param graph_name: Graph Name @return: List of field names for graph. """ graph = self._getGraph(graph_name, True) return graph.getFieldList()
[ "def", "getGraphFieldList", "(", "self", ",", "graph_name", ")", ":", "graph", "=", "self", ".", "_getGraph", "(", "graph_name", ",", "True", ")", "return", "graph", ".", "getFieldList", "(", ")" ]
Returns list of names of fields for graph with name graph_name. @param graph_name: Graph Name @return: List of field names for graph.
[ "Returns", "list", "of", "names", "of", "fields", "for", "graph", "with", "name", "graph_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L643-L651
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.getGraphFieldCount
def getGraphFieldCount(self, graph_name): """Returns number of fields for graph with name graph_name. @param graph_name: Graph Name @return: Number of fields for graph. """ graph = self._getGraph(graph_name, True) return graph.getFieldCount()
python
def getGraphFieldCount(self, graph_name): """Returns number of fields for graph with name graph_name. @param graph_name: Graph Name @return: Number of fields for graph. """ graph = self._getGraph(graph_name, True) return graph.getFieldCount()
[ "def", "getGraphFieldCount", "(", "self", ",", "graph_name", ")", ":", "graph", "=", "self", ".", "_getGraph", "(", "graph_name", ",", "True", ")", "return", "graph", ".", "getFieldCount", "(", ")" ]
Returns number of fields for graph with name graph_name. @param graph_name: Graph Name @return: Number of fields for graph.
[ "Returns", "number", "of", "fields", "for", "graph", "with", "name", "graph_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L653-L661
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.getSubgraphFieldList
def getSubgraphFieldList(self, parent_name, graph_name): """Returns list of names of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: List of field names for subgraph. """ graph = self._getSubGraph(parent_name, graph_name, True) return graph.getFieldList()
python
def getSubgraphFieldList(self, parent_name, graph_name): """Returns list of names of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: List of field names for subgraph. """ graph = self._getSubGraph(parent_name, graph_name, True) return graph.getFieldList()
[ "def", "getSubgraphFieldList", "(", "self", ",", "parent_name", ",", "graph_name", ")", ":", "graph", "=", "self", ".", "_getSubGraph", "(", "parent_name", ",", "graph_name", ",", "True", ")", "return", "graph", ".", "getFieldList", "(", ")" ]
Returns list of names of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: List of field names for subgraph.
[ "Returns", "list", "of", "names", "of", "fields", "for", "subgraph", "with", "name", "graph_name", "and", "parent", "graph", "with", "name", "parent_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L663-L673
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.getSubgraphFieldCount
def getSubgraphFieldCount(self, parent_name, graph_name): """Returns number of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: Number of fields for subgraph. """ graph = self._getSubGraph(parent_name, graph_name, True) return graph.getFieldCount()
python
def getSubgraphFieldCount(self, parent_name, graph_name): """Returns number of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: Number of fields for subgraph. """ graph = self._getSubGraph(parent_name, graph_name, True) return graph.getFieldCount()
[ "def", "getSubgraphFieldCount", "(", "self", ",", "parent_name", ",", "graph_name", ")", ":", "graph", "=", "self", ".", "_getSubGraph", "(", "parent_name", ",", "graph_name", ",", "True", ")", "return", "graph", ".", "getFieldCount", "(", ")" ]
Returns number of fields for subgraph with name graph_name and parent graph with name parent_name. @param parent_name: Root Graph Name @param graph_name: Subgraph Name @return: Number of fields for subgraph.
[ "Returns", "number", "of", "fields", "for", "subgraph", "with", "name", "graph_name", "and", "parent", "graph", "with", "name", "parent_name", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L675-L685
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.config
def config(self): """Implements Munin Plugin Graph Configuration. Prints out configuration for graphs. Use as is. Not required to be overwritten in child classes. The plugin will work correctly as long as the Munin Graph objects have been populated. """ for parent_name in self._graphNames: graph = self._graphDict[parent_name] if self.isMultigraph: print "multigraph %s" % self._getMultigraphID(parent_name) print self._formatConfig(graph.getConfig()) print if (self.isMultigraph and self._nestedGraphs and self._subgraphDict and self._subgraphNames): for (parent_name, subgraph_names) in self._subgraphNames.iteritems(): for graph_name in subgraph_names: graph = self._subgraphDict[parent_name][graph_name] print "multigraph %s" % self.getMultigraphID(parent_name, graph_name) print self._formatConfig(graph.getConfig()) print return True
python
def config(self): """Implements Munin Plugin Graph Configuration. Prints out configuration for graphs. Use as is. Not required to be overwritten in child classes. The plugin will work correctly as long as the Munin Graph objects have been populated. """ for parent_name in self._graphNames: graph = self._graphDict[parent_name] if self.isMultigraph: print "multigraph %s" % self._getMultigraphID(parent_name) print self._formatConfig(graph.getConfig()) print if (self.isMultigraph and self._nestedGraphs and self._subgraphDict and self._subgraphNames): for (parent_name, subgraph_names) in self._subgraphNames.iteritems(): for graph_name in subgraph_names: graph = self._subgraphDict[parent_name][graph_name] print "multigraph %s" % self.getMultigraphID(parent_name, graph_name) print self._formatConfig(graph.getConfig()) print return True
[ "def", "config", "(", "self", ")", ":", "for", "parent_name", "in", "self", ".", "_graphNames", ":", "graph", "=", "self", ".", "_graphDict", "[", "parent_name", "]", "if", "self", ".", "isMultigraph", ":", "print", "\"multigraph %s\"", "%", "self", ".", "_getMultigraphID", "(", "parent_name", ")", "print", "self", ".", "_formatConfig", "(", "graph", ".", "getConfig", "(", ")", ")", "print", "if", "(", "self", ".", "isMultigraph", "and", "self", ".", "_nestedGraphs", "and", "self", ".", "_subgraphDict", "and", "self", ".", "_subgraphNames", ")", ":", "for", "(", "parent_name", ",", "subgraph_names", ")", "in", "self", ".", "_subgraphNames", ".", "iteritems", "(", ")", ":", "for", "graph_name", "in", "subgraph_names", ":", "graph", "=", "self", ".", "_subgraphDict", "[", "parent_name", "]", "[", "graph_name", "]", "print", "\"multigraph %s\"", "%", "self", ".", "getMultigraphID", "(", "parent_name", ",", "graph_name", ")", "print", "self", ".", "_formatConfig", "(", "graph", ".", "getConfig", "(", ")", ")", "print", "return", "True" ]
Implements Munin Plugin Graph Configuration. Prints out configuration for graphs. Use as is. Not required to be overwritten in child classes. The plugin will work correctly as long as the Munin Graph objects have been populated.
[ "Implements", "Munin", "Plugin", "Graph", "Configuration", ".", "Prints", "out", "configuration", "for", "graphs", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L708-L733
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.fetch
def fetch(self): """Implements Munin Plugin Fetch Option. Prints out measured values. """ self.retrieveVals() for parent_name in self._graphNames: graph = self._graphDict[parent_name] if self.isMultigraph: print "multigraph %s" % self._getMultigraphID(parent_name) print self._formatVals(graph.getVals()) print if (self.isMultigraph and self._nestedGraphs and self._subgraphDict and self._subgraphNames): for (parent_name, subgraph_names) in self._subgraphNames.iteritems(): for graph_name in subgraph_names: graph = self._subgraphDict[parent_name][graph_name] print "multigraph %s" % self.getMultigraphID(parent_name, graph_name) print self._formatVals(graph.getVals()) print return True
python
def fetch(self): """Implements Munin Plugin Fetch Option. Prints out measured values. """ self.retrieveVals() for parent_name in self._graphNames: graph = self._graphDict[parent_name] if self.isMultigraph: print "multigraph %s" % self._getMultigraphID(parent_name) print self._formatVals(graph.getVals()) print if (self.isMultigraph and self._nestedGraphs and self._subgraphDict and self._subgraphNames): for (parent_name, subgraph_names) in self._subgraphNames.iteritems(): for graph_name in subgraph_names: graph = self._subgraphDict[parent_name][graph_name] print "multigraph %s" % self.getMultigraphID(parent_name, graph_name) print self._formatVals(graph.getVals()) print return True
[ "def", "fetch", "(", "self", ")", ":", "self", ".", "retrieveVals", "(", ")", "for", "parent_name", "in", "self", ".", "_graphNames", ":", "graph", "=", "self", ".", "_graphDict", "[", "parent_name", "]", "if", "self", ".", "isMultigraph", ":", "print", "\"multigraph %s\"", "%", "self", ".", "_getMultigraphID", "(", "parent_name", ")", "print", "self", ".", "_formatVals", "(", "graph", ".", "getVals", "(", ")", ")", "print", "if", "(", "self", ".", "isMultigraph", "and", "self", ".", "_nestedGraphs", "and", "self", ".", "_subgraphDict", "and", "self", ".", "_subgraphNames", ")", ":", "for", "(", "parent_name", ",", "subgraph_names", ")", "in", "self", ".", "_subgraphNames", ".", "iteritems", "(", ")", ":", "for", "graph_name", "in", "subgraph_names", ":", "graph", "=", "self", ".", "_subgraphDict", "[", "parent_name", "]", "[", "graph_name", "]", "print", "\"multigraph %s\"", "%", "self", ".", "getMultigraphID", "(", "parent_name", ",", "graph_name", ")", "print", "self", ".", "_formatVals", "(", "graph", ".", "getVals", "(", ")", ")", "print", "return", "True" ]
Implements Munin Plugin Fetch Option. Prints out measured values.
[ "Implements", "Munin", "Plugin", "Fetch", "Option", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L744-L766
train
aouyar/PyMunin
pymunin/__init__.py
MuninPlugin.run
def run(self): """Implements main entry point for plugin execution.""" if len(self._argv) > 1 and len(self._argv[1]) > 0: oper = self._argv[1] else: oper = 'fetch' if oper == 'fetch': ret = self.fetch() elif oper == 'config': ret = self.config() if ret and self._dirtyConfig: ret = self.fetch() elif oper == 'autoconf': ret = self.autoconf() if ret: print "yes" else: print "no" ret = True elif oper == 'suggest': ret = self.suggest() else: raise AttributeError("Invalid command argument: %s" % oper) return ret
python
def run(self): """Implements main entry point for plugin execution.""" if len(self._argv) > 1 and len(self._argv[1]) > 0: oper = self._argv[1] else: oper = 'fetch' if oper == 'fetch': ret = self.fetch() elif oper == 'config': ret = self.config() if ret and self._dirtyConfig: ret = self.fetch() elif oper == 'autoconf': ret = self.autoconf() if ret: print "yes" else: print "no" ret = True elif oper == 'suggest': ret = self.suggest() else: raise AttributeError("Invalid command argument: %s" % oper) return ret
[ "def", "run", "(", "self", ")", ":", "if", "len", "(", "self", ".", "_argv", ")", ">", "1", "and", "len", "(", "self", ".", "_argv", "[", "1", "]", ")", ">", "0", ":", "oper", "=", "self", ".", "_argv", "[", "1", "]", "else", ":", "oper", "=", "'fetch'", "if", "oper", "==", "'fetch'", ":", "ret", "=", "self", ".", "fetch", "(", ")", "elif", "oper", "==", "'config'", ":", "ret", "=", "self", ".", "config", "(", ")", "if", "ret", "and", "self", ".", "_dirtyConfig", ":", "ret", "=", "self", ".", "fetch", "(", ")", "elif", "oper", "==", "'autoconf'", ":", "ret", "=", "self", ".", "autoconf", "(", ")", "if", "ret", ":", "print", "\"yes\"", "else", ":", "print", "\"no\"", "ret", "=", "True", "elif", "oper", "==", "'suggest'", ":", "ret", "=", "self", ".", "suggest", "(", ")", "else", ":", "raise", "AttributeError", "(", "\"Invalid command argument: %s\"", "%", "oper", ")", "return", "ret" ]
Implements main entry point for plugin execution.
[ "Implements", "main", "entry", "point", "for", "plugin", "execution", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L768-L791
train
aouyar/PyMunin
pymunin/__init__.py
MuninGraph.addField
def addField(self, name, label, type=None, draw=None, info=None, #@ReservedAssignment extinfo=None, colour=None, negative=None, graph=None, min=None, max=None, cdef=None, line=None, #@ReservedAssignment warning=None, critical=None): """Add field to Munin Graph @param name: Field Name @param label: Field Label @param type: Stat Type: 'COUNTER' / 'ABSOLUTE' / 'DERIVE' / 'GAUGE' @param draw: Graph Type: 'AREA' / 'LINE{1,2,3}' / 'STACK' / 'LINESTACK{1,2,3}' / 'AREASTACK' @param info: Detailed Field Info @param extinfo: Extended Field Info @param colour: Field Colour @param negative: Mirror Value @param graph: Draw on Graph - True / False (Default: True) @param min: Minimum Valid Value @param max: Maximum Valid Value @param cdef: CDEF @param line: Adds horizontal line at value defined for field. @param warning: Warning Value @param critical: Critical Value """ if self._autoFixNames: name = self._fixName(name) if negative is not None: negative = self._fixName(negative) self._fieldAttrDict[name] = dict(((k,v) for (k,v) in locals().iteritems() if (v is not None and k not in ('self',)))) self._fieldNameList.append(name)
python
def addField(self, name, label, type=None, draw=None, info=None, #@ReservedAssignment extinfo=None, colour=None, negative=None, graph=None, min=None, max=None, cdef=None, line=None, #@ReservedAssignment warning=None, critical=None): """Add field to Munin Graph @param name: Field Name @param label: Field Label @param type: Stat Type: 'COUNTER' / 'ABSOLUTE' / 'DERIVE' / 'GAUGE' @param draw: Graph Type: 'AREA' / 'LINE{1,2,3}' / 'STACK' / 'LINESTACK{1,2,3}' / 'AREASTACK' @param info: Detailed Field Info @param extinfo: Extended Field Info @param colour: Field Colour @param negative: Mirror Value @param graph: Draw on Graph - True / False (Default: True) @param min: Minimum Valid Value @param max: Maximum Valid Value @param cdef: CDEF @param line: Adds horizontal line at value defined for field. @param warning: Warning Value @param critical: Critical Value """ if self._autoFixNames: name = self._fixName(name) if negative is not None: negative = self._fixName(negative) self._fieldAttrDict[name] = dict(((k,v) for (k,v) in locals().iteritems() if (v is not None and k not in ('self',)))) self._fieldNameList.append(name)
[ "def", "addField", "(", "self", ",", "name", ",", "label", ",", "type", "=", "None", ",", "draw", "=", "None", ",", "info", "=", "None", ",", "#@ReservedAssignment", "extinfo", "=", "None", ",", "colour", "=", "None", ",", "negative", "=", "None", ",", "graph", "=", "None", ",", "min", "=", "None", ",", "max", "=", "None", ",", "cdef", "=", "None", ",", "line", "=", "None", ",", "#@ReservedAssignment", "warning", "=", "None", ",", "critical", "=", "None", ")", ":", "if", "self", ".", "_autoFixNames", ":", "name", "=", "self", ".", "_fixName", "(", "name", ")", "if", "negative", "is", "not", "None", ":", "negative", "=", "self", ".", "_fixName", "(", "negative", ")", "self", ".", "_fieldAttrDict", "[", "name", "]", "=", "dict", "(", "(", "(", "k", ",", "v", ")", "for", "(", "k", ",", "v", ")", "in", "locals", "(", ")", ".", "iteritems", "(", ")", "if", "(", "v", "is", "not", "None", "and", "k", "not", "in", "(", "'self'", ",", ")", ")", ")", ")", "self", ".", "_fieldNameList", ".", "append", "(", "name", ")" ]
Add field to Munin Graph @param name: Field Name @param label: Field Label @param type: Stat Type: 'COUNTER' / 'ABSOLUTE' / 'DERIVE' / 'GAUGE' @param draw: Graph Type: 'AREA' / 'LINE{1,2,3}' / 'STACK' / 'LINESTACK{1,2,3}' / 'AREASTACK' @param info: Detailed Field Info @param extinfo: Extended Field Info @param colour: Field Colour @param negative: Mirror Value @param graph: Draw on Graph - True / False (Default: True) @param min: Minimum Valid Value @param max: Maximum Valid Value @param cdef: CDEF @param line: Adds horizontal line at value defined for field. @param warning: Warning Value @param critical: Critical Value
[ "Add", "field", "to", "Munin", "Graph" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L836-L869
train
aouyar/PyMunin
pymunin/__init__.py
MuninGraph.hasField
def hasField(self, name): """Returns true if field with field_name exists. @param name: Field Name @return: Boolean """ if self._autoFixNames: name = self._fixName(name) return self._fieldAttrDict.has_key(name)
python
def hasField(self, name): """Returns true if field with field_name exists. @param name: Field Name @return: Boolean """ if self._autoFixNames: name = self._fixName(name) return self._fieldAttrDict.has_key(name)
[ "def", "hasField", "(", "self", ",", "name", ")", ":", "if", "self", ".", "_autoFixNames", ":", "name", "=", "self", ".", "_fixName", "(", "name", ")", "return", "self", ".", "_fieldAttrDict", ".", "has_key", "(", "name", ")" ]
Returns true if field with field_name exists. @param name: Field Name @return: Boolean
[ "Returns", "true", "if", "field", "with", "field_name", "exists", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L871-L880
train
aouyar/PyMunin
pymunin/__init__.py
MuninGraph.getConfig
def getConfig(self): """Returns dictionary of config entries for Munin Graph. @return: Dictionary of config entries. """ return {'graph': self._graphAttrDict, 'fields': [(field_name, self._fieldAttrDict.get(field_name)) for field_name in self._fieldNameList]}
python
def getConfig(self): """Returns dictionary of config entries for Munin Graph. @return: Dictionary of config entries. """ return {'graph': self._graphAttrDict, 'fields': [(field_name, self._fieldAttrDict.get(field_name)) for field_name in self._fieldNameList]}
[ "def", "getConfig", "(", "self", ")", ":", "return", "{", "'graph'", ":", "self", ".", "_graphAttrDict", ",", "'fields'", ":", "[", "(", "field_name", ",", "self", ".", "_fieldAttrDict", ".", "get", "(", "field_name", ")", ")", "for", "field_name", "in", "self", ".", "_fieldNameList", "]", "}" ]
Returns dictionary of config entries for Munin Graph. @return: Dictionary of config entries.
[ "Returns", "dictionary", "of", "config", "entries", "for", "Munin", "Graph", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L898-L906
train
aouyar/PyMunin
pymunin/__init__.py
MuninGraph.setVal
def setVal(self, name, val): """Set value for field in graph. @param name : Graph Name @param value : Value for field. """ if self._autoFixNames: name = self._fixName(name) self._fieldValDict[name] = val
python
def setVal(self, name, val): """Set value for field in graph. @param name : Graph Name @param value : Value for field. """ if self._autoFixNames: name = self._fixName(name) self._fieldValDict[name] = val
[ "def", "setVal", "(", "self", ",", "name", ",", "val", ")", ":", "if", "self", ".", "_autoFixNames", ":", "name", "=", "self", ".", "_fixName", "(", "name", ")", "self", ".", "_fieldValDict", "[", "name", "]", "=", "val" ]
Set value for field in graph. @param name : Graph Name @param value : Value for field.
[ "Set", "value", "for", "field", "in", "graph", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L908-L917
train
aouyar/PyMunin
pymunin/__init__.py
MuninGraph.getVals
def getVals(self): """Returns value list for Munin Graph @return: List of name-value pairs. """ return [(name, self._fieldValDict.get(name)) for name in self._fieldNameList]
python
def getVals(self): """Returns value list for Munin Graph @return: List of name-value pairs. """ return [(name, self._fieldValDict.get(name)) for name in self._fieldNameList]
[ "def", "getVals", "(", "self", ")", ":", "return", "[", "(", "name", ",", "self", ".", "_fieldValDict", ".", "get", "(", "name", ")", ")", "for", "name", "in", "self", ".", "_fieldNameList", "]" ]
Returns value list for Munin Graph @return: List of name-value pairs.
[ "Returns", "value", "list", "for", "Munin", "Graph" ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pymunin/__init__.py#L919-L926
train
aouyar/PyMunin
pysysinfo/phpapc.py
APCinfo.initStats
def initStats(self, extras=None): """Query and parse Web Server Status Page. @param extras: Include extra metrics, which can be computationally more expensive. """ if extras is not None: self._extras = extras if self._extras: detail = 1 else: detail = 0 url = "%s://%s:%d/%s?detail=%s" % (self._proto, self._host, self._port, self._monpath, detail) response = util.get_url(url, self._user, self._password) self._statusDict = {} for line in response.splitlines(): cols = line.split(':') if not self._statusDict.has_key(cols[0]): self._statusDict[cols[0]] = {} self._statusDict[cols[0]][cols[1]] = util.parse_value(cols[2])
python
def initStats(self, extras=None): """Query and parse Web Server Status Page. @param extras: Include extra metrics, which can be computationally more expensive. """ if extras is not None: self._extras = extras if self._extras: detail = 1 else: detail = 0 url = "%s://%s:%d/%s?detail=%s" % (self._proto, self._host, self._port, self._monpath, detail) response = util.get_url(url, self._user, self._password) self._statusDict = {} for line in response.splitlines(): cols = line.split(':') if not self._statusDict.has_key(cols[0]): self._statusDict[cols[0]] = {} self._statusDict[cols[0]][cols[1]] = util.parse_value(cols[2])
[ "def", "initStats", "(", "self", ",", "extras", "=", "None", ")", ":", "if", "extras", "is", "not", "None", ":", "self", ".", "_extras", "=", "extras", "if", "self", ".", "_extras", ":", "detail", "=", "1", "else", ":", "detail", "=", "0", "url", "=", "\"%s://%s:%d/%s?detail=%s\"", "%", "(", "self", ".", "_proto", ",", "self", ".", "_host", ",", "self", ".", "_port", ",", "self", ".", "_monpath", ",", "detail", ")", "response", "=", "util", ".", "get_url", "(", "url", ",", "self", ".", "_user", ",", "self", ".", "_password", ")", "self", ".", "_statusDict", "=", "{", "}", "for", "line", "in", "response", ".", "splitlines", "(", ")", ":", "cols", "=", "line", ".", "split", "(", "':'", ")", "if", "not", "self", ".", "_statusDict", ".", "has_key", "(", "cols", "[", "0", "]", ")", ":", "self", ".", "_statusDict", "[", "cols", "[", "0", "]", "]", "=", "{", "}", "self", ".", "_statusDict", "[", "cols", "[", "0", "]", "]", "[", "cols", "[", "1", "]", "]", "=", "util", ".", "parse_value", "(", "cols", "[", "2", "]", ")" ]
Query and parse Web Server Status Page. @param extras: Include extra metrics, which can be computationally more expensive.
[ "Query", "and", "parse", "Web", "Server", "Status", "Page", "." ]
4f58a64b6b37c85a84cc7e1e07aafaa0321b249d
https://github.com/aouyar/PyMunin/blob/4f58a64b6b37c85a84cc7e1e07aafaa0321b249d/pysysinfo/phpapc.py#L71-L92
train