repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
python-diamond/Diamond | src/collectors/processresources/processresources.py | ProcessResourcesCollector.collect | def collect(self):
"""
Collects resources usage of each process defined under the
`process` subsection of the config file
"""
if not psutil:
self.log.error('Unable to import psutil')
self.log.error('No process resource metrics retrieved')
retur... | python | def collect(self):
"""
Collects resources usage of each process defined under the
`process` subsection of the config file
"""
if not psutil:
self.log.error('Unable to import psutil')
self.log.error('No process resource metrics retrieved')
retur... | [
"def",
"collect",
"(",
"self",
")",
":",
"if",
"not",
"psutil",
":",
"self",
".",
"log",
".",
"error",
"(",
"'Unable to import psutil'",
")",
"self",
".",
"log",
".",
"error",
"(",
"'No process resource metrics retrieved'",
")",
"return",
"None",
"for",
"pro... | Collects resources usage of each process defined under the
`process` subsection of the config file | [
"Collects",
"resources",
"usage",
"of",
"each",
"process",
"defined",
"under",
"the",
"process",
"subsection",
"of",
"the",
"config",
"file"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/processresources/processresources.py#L187-L214 | train |
python-diamond/Diamond | src/diamond/metric.py | Metric.parse | def parse(cls, string):
"""
Parse a string and create a metric
"""
match = re.match(r'^(?P<name>[A-Za-z0-9\.\-_]+)\s+' +
'(?P<value>[0-9\.]+)\s+' +
'(?P<timestamp>[0-9\.]+)(\n?)$',
string)
try:
... | python | def parse(cls, string):
"""
Parse a string and create a metric
"""
match = re.match(r'^(?P<name>[A-Za-z0-9\.\-_]+)\s+' +
'(?P<value>[0-9\.]+)\s+' +
'(?P<timestamp>[0-9\.]+)(\n?)$',
string)
try:
... | [
"def",
"parse",
"(",
"cls",
",",
"string",
")",
":",
"match",
"=",
"re",
".",
"match",
"(",
"r'^(?P<name>[A-Za-z0-9\\.\\-_]+)\\s+'",
"+",
"'(?P<value>[0-9\\.]+)\\s+'",
"+",
"'(?P<timestamp>[0-9\\.]+)(\\n?)$'",
",",
"string",
")",
"try",
":",
"groups",
"=",
"match"... | Parse a string and create a metric | [
"Parse",
"a",
"string",
"and",
"create",
"a",
"metric"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/metric.py#L100-L116 | train |
python-diamond/Diamond | src/diamond/metric.py | Metric.getPathPrefix | def getPathPrefix(self):
"""
Returns the path prefix path
servers.host.cpu.total.idle
return "servers"
"""
# If we don't have a host name, assume it's just the first part of the
# metric path
if self.host is None:
return self.path.s... | python | def getPathPrefix(self):
"""
Returns the path prefix path
servers.host.cpu.total.idle
return "servers"
"""
# If we don't have a host name, assume it's just the first part of the
# metric path
if self.host is None:
return self.path.s... | [
"def",
"getPathPrefix",
"(",
"self",
")",
":",
"# If we don't have a host name, assume it's just the first part of the",
"# metric path",
"if",
"self",
".",
"host",
"is",
"None",
":",
"return",
"self",
".",
"path",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"... | Returns the path prefix path
servers.host.cpu.total.idle
return "servers" | [
"Returns",
"the",
"path",
"prefix",
"path",
"servers",
".",
"host",
".",
"cpu",
".",
"total",
".",
"idle",
"return",
"servers"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/metric.py#L118-L130 | train |
python-diamond/Diamond | src/diamond/metric.py | Metric.getCollectorPath | def getCollectorPath(self):
"""
Returns collector path
servers.host.cpu.total.idle
return "cpu"
"""
# If we don't have a host name, assume it's just the third part of the
# metric path
if self.host is None:
return self.path.split('.... | python | def getCollectorPath(self):
"""
Returns collector path
servers.host.cpu.total.idle
return "cpu"
"""
# If we don't have a host name, assume it's just the third part of the
# metric path
if self.host is None:
return self.path.split('.... | [
"def",
"getCollectorPath",
"(",
"self",
")",
":",
"# If we don't have a host name, assume it's just the third part of the",
"# metric path",
"if",
"self",
".",
"host",
"is",
"None",
":",
"return",
"self",
".",
"path",
".",
"split",
"(",
"'.'",
")",
"[",
"2",
"]",
... | Returns collector path
servers.host.cpu.total.idle
return "cpu" | [
"Returns",
"collector",
"path",
"servers",
".",
"host",
".",
"cpu",
".",
"total",
".",
"idle",
"return",
"cpu"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/metric.py#L132-L146 | train |
python-diamond/Diamond | src/diamond/metric.py | Metric.getMetricPath | def getMetricPath(self):
"""
Returns the metric path after the collector name
servers.host.cpu.total.idle
return "total.idle"
"""
# If we don't have a host name, assume it's just the fourth+ part of the
# metric path
if self.host is None:
... | python | def getMetricPath(self):
"""
Returns the metric path after the collector name
servers.host.cpu.total.idle
return "total.idle"
"""
# If we don't have a host name, assume it's just the fourth+ part of the
# metric path
if self.host is None:
... | [
"def",
"getMetricPath",
"(",
"self",
")",
":",
"# If we don't have a host name, assume it's just the fourth+ part of the",
"# metric path",
"if",
"self",
".",
"host",
"is",
"None",
":",
"path",
"=",
"self",
".",
"path",
".",
"split",
"(",
"'.'",
")",
"[",
"3",
"... | Returns the metric path after the collector name
servers.host.cpu.total.idle
return "total.idle" | [
"Returns",
"the",
"metric",
"path",
"after",
"the",
"collector",
"name",
"servers",
".",
"host",
".",
"cpu",
".",
"total",
".",
"idle",
"return",
"total",
".",
"idle"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/metric.py#L148-L164 | train |
python-diamond/Diamond | src/diamond/handler/Handler.py | Handler._process | def _process(self, metric):
"""
Decorator for processing handlers with a lock, catching exceptions
"""
if not self.enabled:
return
try:
try:
self.lock.acquire()
self.process(metric)
except Exception:
... | python | def _process(self, metric):
"""
Decorator for processing handlers with a lock, catching exceptions
"""
if not self.enabled:
return
try:
try:
self.lock.acquire()
self.process(metric)
except Exception:
... | [
"def",
"_process",
"(",
"self",
",",
"metric",
")",
":",
"if",
"not",
"self",
".",
"enabled",
":",
"return",
"try",
":",
"try",
":",
"self",
".",
"lock",
".",
"acquire",
"(",
")",
"self",
".",
"process",
"(",
"metric",
")",
"except",
"Exception",
"... | Decorator for processing handlers with a lock, catching exceptions | [
"Decorator",
"for",
"processing",
"handlers",
"with",
"a",
"lock",
"catching",
"exceptions"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/Handler.py#L65-L79 | train |
python-diamond/Diamond | src/diamond/handler/Handler.py | Handler._flush | def _flush(self):
"""
Decorator for flushing handlers with an lock, catching exceptions
"""
if not self.enabled:
return
try:
try:
self.lock.acquire()
self.flush()
except Exception:
self.log.error(... | python | def _flush(self):
"""
Decorator for flushing handlers with an lock, catching exceptions
"""
if not self.enabled:
return
try:
try:
self.lock.acquire()
self.flush()
except Exception:
self.log.error(... | [
"def",
"_flush",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"enabled",
":",
"return",
"try",
":",
"try",
":",
"self",
".",
"lock",
".",
"acquire",
"(",
")",
"self",
".",
"flush",
"(",
")",
"except",
"Exception",
":",
"self",
".",
"log",
"."... | Decorator for flushing handlers with an lock, catching exceptions | [
"Decorator",
"for",
"flushing",
"handlers",
"with",
"an",
"lock",
"catching",
"exceptions"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/Handler.py#L89-L103 | train |
python-diamond/Diamond | src/diamond/handler/Handler.py | Handler._throttle_error | def _throttle_error(self, msg, *args, **kwargs):
"""
Avoids sending errors repeatedly. Waits at least
`self.server_error_interval` seconds before sending the same error
string to the error logging facility. If not enough time has passed,
it calls `log.debug` instead
Rece... | python | def _throttle_error(self, msg, *args, **kwargs):
"""
Avoids sending errors repeatedly. Waits at least
`self.server_error_interval` seconds before sending the same error
string to the error logging facility. If not enough time has passed,
it calls `log.debug` instead
Rece... | [
"def",
"_throttle_error",
"(",
"self",
",",
"msg",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"msg",
"in",
"self",
".",
"_errors",
":",
"if",
"(",
"(",
"now",
"-",
"self",
".",
"_errors... | Avoids sending errors repeatedly. Waits at least
`self.server_error_interval` seconds before sending the same error
string to the error logging facility. If not enough time has passed,
it calls `log.debug` instead
Receives the same parameters as `Logger.error` an passes them on to the
... | [
"Avoids",
"sending",
"errors",
"repeatedly",
".",
"Waits",
"at",
"least",
"self",
".",
"server_error_interval",
"seconds",
"before",
"sending",
"the",
"same",
"error",
"string",
"to",
"the",
"error",
"logging",
"facility",
".",
"If",
"not",
"enough",
"time",
"... | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/Handler.py#L113-L138 | train |
python-diamond/Diamond | src/diamond/handler/Handler.py | Handler._reset_errors | def _reset_errors(self, msg=None):
"""
Resets the logging throttle cache, so the next error is emitted
regardless of the value in `self.server_error_interval`
:param msg: if present, only this key is reset. Otherwise, the whole
cache is cleaned.
"""
if msg is... | python | def _reset_errors(self, msg=None):
"""
Resets the logging throttle cache, so the next error is emitted
regardless of the value in `self.server_error_interval`
:param msg: if present, only this key is reset. Otherwise, the whole
cache is cleaned.
"""
if msg is... | [
"def",
"_reset_errors",
"(",
"self",
",",
"msg",
"=",
"None",
")",
":",
"if",
"msg",
"is",
"not",
"None",
"and",
"msg",
"in",
"self",
".",
"_errors",
":",
"del",
"self",
".",
"_errors",
"[",
"msg",
"]",
"else",
":",
"self",
".",
"_errors",
"=",
"... | Resets the logging throttle cache, so the next error is emitted
regardless of the value in `self.server_error_interval`
:param msg: if present, only this key is reset. Otherwise, the whole
cache is cleaned. | [
"Resets",
"the",
"logging",
"throttle",
"cache",
"so",
"the",
"next",
"error",
"is",
"emitted",
"regardless",
"of",
"the",
"value",
"in",
"self",
".",
"server_error_interval"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/Handler.py#L140-L151 | train |
python-diamond/Diamond | src/diamond/utils/signals.py | signal_to_exception | def signal_to_exception(signum, frame):
"""
Called by the timeout alarm during the collector run time
"""
if signum == signal.SIGALRM:
raise SIGALRMException()
if signum == signal.SIGHUP:
raise SIGHUPException()
if signum == signal.SIGUSR1:
raise SIGUSR1Exception()
if... | python | def signal_to_exception(signum, frame):
"""
Called by the timeout alarm during the collector run time
"""
if signum == signal.SIGALRM:
raise SIGALRMException()
if signum == signal.SIGHUP:
raise SIGHUPException()
if signum == signal.SIGUSR1:
raise SIGUSR1Exception()
if... | [
"def",
"signal_to_exception",
"(",
"signum",
",",
"frame",
")",
":",
"if",
"signum",
"==",
"signal",
".",
"SIGALRM",
":",
"raise",
"SIGALRMException",
"(",
")",
"if",
"signum",
"==",
"signal",
".",
"SIGHUP",
":",
"raise",
"SIGHUPException",
"(",
")",
"if",... | Called by the timeout alarm during the collector run time | [
"Called",
"by",
"the",
"timeout",
"alarm",
"during",
"the",
"collector",
"run",
"time"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/utils/signals.py#L6-L18 | train |
python-diamond/Diamond | src/collectors/servertechpdu/servertechpdu.py | ServerTechPDUCollector.collect_snmp | def collect_snmp(self, device, host, port, community):
"""
Collect stats from device
"""
# Log
self.log.info("Collecting ServerTech PDU statistics from: %s" % device)
# Set timestamp
timestamp = time.time()
inputFeeds = {}
# Collect PDU input ga... | python | def collect_snmp(self, device, host, port, community):
"""
Collect stats from device
"""
# Log
self.log.info("Collecting ServerTech PDU statistics from: %s" % device)
# Set timestamp
timestamp = time.time()
inputFeeds = {}
# Collect PDU input ga... | [
"def",
"collect_snmp",
"(",
"self",
",",
"device",
",",
"host",
",",
"port",
",",
"community",
")",
":",
"# Log",
"self",
".",
"log",
".",
"info",
"(",
"\"Collecting ServerTech PDU statistics from: %s\"",
"%",
"device",
")",
"# Set timestamp",
"timestamp",
"=",
... | Collect stats from device | [
"Collect",
"stats",
"from",
"device"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/servertechpdu/servertechpdu.py#L66-L129 | train |
python-diamond/Diamond | src/collectors/users/users.py | UsersCollector.get_default_config_help | def get_default_config_help(self):
"""
Returns the default collector help text
"""
config_help = super(UsersCollector, self).get_default_config_help()
config_help.update({
})
return config_help | python | def get_default_config_help(self):
"""
Returns the default collector help text
"""
config_help = super(UsersCollector, self).get_default_config_help()
config_help.update({
})
return config_help | [
"def",
"get_default_config_help",
"(",
"self",
")",
":",
"config_help",
"=",
"super",
"(",
"UsersCollector",
",",
"self",
")",
".",
"get_default_config_help",
"(",
")",
"config_help",
".",
"update",
"(",
"{",
"}",
")",
"return",
"config_help"
] | Returns the default collector help text | [
"Returns",
"the",
"default",
"collector",
"help",
"text"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/users/users.py#L29-L36 | train |
python-diamond/Diamond | src/diamond/handler/stats_d.py | StatsdHandler._send | def _send(self):
"""
Send data to statsd. Fire and forget. Cross fingers and it'll arrive.
"""
if not statsd:
return
for metric in self.metrics:
# Split the path into a prefix and a name
# to work with the statsd module's view of the world.
... | python | def _send(self):
"""
Send data to statsd. Fire and forget. Cross fingers and it'll arrive.
"""
if not statsd:
return
for metric in self.metrics:
# Split the path into a prefix and a name
# to work with the statsd module's view of the world.
... | [
"def",
"_send",
"(",
"self",
")",
":",
"if",
"not",
"statsd",
":",
"return",
"for",
"metric",
"in",
"self",
".",
"metrics",
":",
"# Split the path into a prefix and a name",
"# to work with the statsd module's view of the world.",
"# It will get re-joined by the python-statsd... | Send data to statsd. Fire and forget. Cross fingers and it'll arrive. | [
"Send",
"data",
"to",
"statsd",
".",
"Fire",
"and",
"forget",
".",
"Cross",
"fingers",
"and",
"it",
"ll",
"arrive",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/stats_d.py#L106-L145 | train |
python-diamond/Diamond | src/diamond/handler/stats_d.py | StatsdHandler._connect | def _connect(self):
"""
Connect to the statsd server
"""
if not statsd:
return
if hasattr(statsd, 'StatsClient'):
self.connection = statsd.StatsClient(
host=self.host,
port=self.port
).pipeline()
else:
... | python | def _connect(self):
"""
Connect to the statsd server
"""
if not statsd:
return
if hasattr(statsd, 'StatsClient'):
self.connection = statsd.StatsClient(
host=self.host,
port=self.port
).pipeline()
else:
... | [
"def",
"_connect",
"(",
"self",
")",
":",
"if",
"not",
"statsd",
":",
"return",
"if",
"hasattr",
"(",
"statsd",
",",
"'StatsClient'",
")",
":",
"self",
".",
"connection",
"=",
"statsd",
".",
"StatsClient",
"(",
"host",
"=",
"self",
".",
"host",
",",
... | Connect to the statsd server | [
"Connect",
"to",
"the",
"statsd",
"server"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/stats_d.py#L151-L169 | train |
python-diamond/Diamond | src/diamond/handler/signalfx.py | SignalfxHandler._match_metric | def _match_metric(self, metric):
"""
matches the metric path, if the metrics are empty, it shorts to True
"""
if len(self._compiled_filters) == 0:
return True
for (collector, filter_regex) in self._compiled_filters:
if collector != metric.getCollectorPath(... | python | def _match_metric(self, metric):
"""
matches the metric path, if the metrics are empty, it shorts to True
"""
if len(self._compiled_filters) == 0:
return True
for (collector, filter_regex) in self._compiled_filters:
if collector != metric.getCollectorPath(... | [
"def",
"_match_metric",
"(",
"self",
",",
"metric",
")",
":",
"if",
"len",
"(",
"self",
".",
"_compiled_filters",
")",
"==",
"0",
":",
"return",
"True",
"for",
"(",
"collector",
",",
"filter_regex",
")",
"in",
"self",
".",
"_compiled_filters",
":",
"if",... | matches the metric path, if the metrics are empty, it shorts to True | [
"matches",
"the",
"metric",
"path",
"if",
"the",
"metrics",
"are",
"empty",
"it",
"shorts",
"to",
"True"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/signalfx.py#L55-L66 | train |
python-diamond/Diamond | src/diamond/handler/signalfx.py | SignalfxHandler.process | def process(self, metric):
"""
Queue a metric. Flushing queue if batch size reached
"""
if self._match_metric(metric):
self.metrics.append(metric)
if self.should_flush():
self._send() | python | def process(self, metric):
"""
Queue a metric. Flushing queue if batch size reached
"""
if self._match_metric(metric):
self.metrics.append(metric)
if self.should_flush():
self._send() | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"if",
"self",
".",
"_match_metric",
"(",
"metric",
")",
":",
"self",
".",
"metrics",
".",
"append",
"(",
"metric",
")",
"if",
"self",
".",
"should_flush",
"(",
")",
":",
"self",
".",
"_send",
... | Queue a metric. Flushing queue if batch size reached | [
"Queue",
"a",
"metric",
".",
"Flushing",
"queue",
"if",
"batch",
"size",
"reached"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/signalfx.py#L103-L110 | train |
python-diamond/Diamond | src/diamond/handler/signalfx.py | SignalfxHandler.into_signalfx_point | def into_signalfx_point(self, metric):
"""
Convert diamond metric into something signalfx can understand
"""
dims = {
"collector": metric.getCollectorPath(),
"prefix": metric.getPathPrefix(),
}
if metric.host is not None and metric.host != "":
... | python | def into_signalfx_point(self, metric):
"""
Convert diamond metric into something signalfx can understand
"""
dims = {
"collector": metric.getCollectorPath(),
"prefix": metric.getPathPrefix(),
}
if metric.host is not None and metric.host != "":
... | [
"def",
"into_signalfx_point",
"(",
"self",
",",
"metric",
")",
":",
"dims",
"=",
"{",
"\"collector\"",
":",
"metric",
".",
"getCollectorPath",
"(",
")",
",",
"\"prefix\"",
":",
"metric",
".",
"getPathPrefix",
"(",
")",
",",
"}",
"if",
"metric",
".",
"hos... | Convert diamond metric into something signalfx can understand | [
"Convert",
"diamond",
"metric",
"into",
"something",
"signalfx",
"can",
"understand"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/signalfx.py#L116-L133 | train |
python-diamond/Diamond | src/diamond/gmetric.py | gmetric_write | def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME = "test"
SPOOF = 0
# Meta data about a metric
packer.pack_int(128)
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer... | python | def gmetric_write(NAME, VAL, TYPE, UNITS, SLOPE, TMAX, DMAX, GROUP):
"""
Arguments are in all upper-case to match XML
"""
packer = Packer()
HOSTNAME = "test"
SPOOF = 0
# Meta data about a metric
packer.pack_int(128)
packer.pack_string(HOSTNAME)
packer.pack_string(NAME)
packer... | [
"def",
"gmetric_write",
"(",
"NAME",
",",
"VAL",
",",
"TYPE",
",",
"UNITS",
",",
"SLOPE",
",",
"TMAX",
",",
"DMAX",
",",
"GROUP",
")",
":",
"packer",
"=",
"Packer",
"(",
")",
"HOSTNAME",
"=",
"\"test\"",
"SPOOF",
"=",
"0",
"# Meta data about a metric",
... | Arguments are in all upper-case to match XML | [
"Arguments",
"are",
"in",
"all",
"upper",
"-",
"case",
"to",
"match",
"XML"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/gmetric.py#L103-L138 | train |
python-diamond/Diamond | src/collectors/disktemp/disktemp.py | DiskTemperatureCollector.collect | def collect(self):
"""
Collect and publish disk temperatures
"""
instances = {}
# Support disks such as /dev/(sd.*)
for device in os.listdir('/dev/'):
instances.update(self.match_device(device, '/dev/'))
# Support disk by id such as /dev/disk/by-id/w... | python | def collect(self):
"""
Collect and publish disk temperatures
"""
instances = {}
# Support disks such as /dev/(sd.*)
for device in os.listdir('/dev/'):
instances.update(self.match_device(device, '/dev/'))
# Support disk by id such as /dev/disk/by-id/w... | [
"def",
"collect",
"(",
"self",
")",
":",
"instances",
"=",
"{",
"}",
"# Support disks such as /dev/(sd.*)",
"for",
"device",
"in",
"os",
".",
"listdir",
"(",
"'/dev/'",
")",
":",
"instances",
".",
"update",
"(",
"self",
".",
"match_device",
"(",
"device",
... | Collect and publish disk temperatures | [
"Collect",
"and",
"publish",
"disk",
"temperatures"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/disktemp/disktemp.py#L76-L100 | train |
python-diamond/Diamond | src/collectors/elasticsearch/elasticsearch.py | ElasticSearchCollector._get | def _get(self, scheme, host, port, path, assert_key=None):
"""
Execute a ES API call. Convert response into JSON and
optionally assert its structure.
"""
url = '%s://%s:%i/%s' % (scheme, host, port, path)
try:
request = urllib2.Request(url)
if self... | python | def _get(self, scheme, host, port, path, assert_key=None):
"""
Execute a ES API call. Convert response into JSON and
optionally assert its structure.
"""
url = '%s://%s:%i/%s' % (scheme, host, port, path)
try:
request = urllib2.Request(url)
if self... | [
"def",
"_get",
"(",
"self",
",",
"scheme",
",",
"host",
",",
"port",
",",
"path",
",",
"assert_key",
"=",
"None",
")",
":",
"url",
"=",
"'%s://%s:%i/%s'",
"%",
"(",
"scheme",
",",
"host",
",",
"port",
",",
"path",
")",
"try",
":",
"request",
"=",
... | Execute a ES API call. Convert response into JSON and
optionally assert its structure. | [
"Execute",
"a",
"ES",
"API",
"call",
".",
"Convert",
"response",
"into",
"JSON",
"and",
"optionally",
"assert",
"its",
"structure",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/elasticsearch/elasticsearch.py#L107-L135 | train |
python-diamond/Diamond | src/collectors/elasticsearch/elasticsearch.py | ElasticSearchCollector._set_or_sum_metric | def _set_or_sum_metric(self, metrics, metric_path, value):
"""If we already have a datapoint for this metric, lets add
the value. This is used when the logstash mode is enabled."""
if metric_path in metrics:
metrics[metric_path] += value
else:
metrics[metric_path]... | python | def _set_or_sum_metric(self, metrics, metric_path, value):
"""If we already have a datapoint for this metric, lets add
the value. This is used when the logstash mode is enabled."""
if metric_path in metrics:
metrics[metric_path] += value
else:
metrics[metric_path]... | [
"def",
"_set_or_sum_metric",
"(",
"self",
",",
"metrics",
",",
"metric_path",
",",
"value",
")",
":",
"if",
"metric_path",
"in",
"metrics",
":",
"metrics",
"[",
"metric_path",
"]",
"+=",
"value",
"else",
":",
"metrics",
"[",
"metric_path",
"]",
"=",
"value... | If we already have a datapoint for this metric, lets add
the value. This is used when the logstash mode is enabled. | [
"If",
"we",
"already",
"have",
"a",
"datapoint",
"for",
"this",
"metric",
"lets",
"add",
"the",
"value",
".",
"This",
"is",
"used",
"when",
"the",
"logstash",
"mode",
"is",
"enabled",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/elasticsearch/elasticsearch.py#L183-L189 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector._client | def _client(self, host, port, unix_socket, auth):
"""Return a redis client for the configuration.
:param str host: redis host
:param int port: redis port
:rtype: redis.Redis
"""
db = int(self.config['db'])
timeout = int(self.config['timeout'])
try:
cli = redis.Redis... | python | def _client(self, host, port, unix_socket, auth):
"""Return a redis client for the configuration.
:param str host: redis host
:param int port: redis port
:rtype: redis.Redis
"""
db = int(self.config['db'])
timeout = int(self.config['timeout'])
try:
cli = redis.Redis... | [
"def",
"_client",
"(",
"self",
",",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
")",
":",
"db",
"=",
"int",
"(",
"self",
".",
"config",
"[",
"'db'",
"]",
")",
"timeout",
"=",
"int",
"(",
"self",
".",
"config",
"[",
"'timeout'",
"]",
")"... | Return a redis client for the configuration.
:param str host: redis host
:param int port: redis port
:rtype: redis.Redis | [
"Return",
"a",
"redis",
"client",
"for",
"the",
"configuration",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L209-L227 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector._precision | def _precision(self, value):
"""Return the precision of the number
:param str value: The value to find the precision of
:rtype: int
"""
value = str(value)
decimal = value.rfind('.')
if decimal == -1:
return 0
return len(value) - decimal - 1 | python | def _precision(self, value):
"""Return the precision of the number
:param str value: The value to find the precision of
:rtype: int
"""
value = str(value)
decimal = value.rfind('.')
if decimal == -1:
return 0
return len(value) - decimal - 1 | [
"def",
"_precision",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"str",
"(",
"value",
")",
"decimal",
"=",
"value",
".",
"rfind",
"(",
"'.'",
")",
"if",
"decimal",
"==",
"-",
"1",
":",
"return",
"0",
"return",
"len",
"(",
"value",
")",
"-"... | Return the precision of the number
:param str value: The value to find the precision of
:rtype: int | [
"Return",
"the",
"precision",
"of",
"the",
"number"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L229-L240 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector._get_info | def _get_info(self, host, port, unix_socket, auth):
"""Return info dict from specified Redis instance
:param str host: redis host
:param int port: redis port
:rtype: dict
"""
client = self._client(host, port, unix_socket, auth)
if client is None:
return None
info ... | python | def _get_info(self, host, port, unix_socket, auth):
"""Return info dict from specified Redis instance
:param str host: redis host
:param int port: redis port
:rtype: dict
"""
client = self._client(host, port, unix_socket, auth)
if client is None:
return None
info ... | [
"def",
"_get_info",
"(",
"self",
",",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
")",
":",
"client",
"=",
"self",
".",
"_client",
"(",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
")",
"if",
"client",
"is",
"None",
":",
"return",
... | Return info dict from specified Redis instance
:param str host: redis host
:param int port: redis port
:rtype: dict | [
"Return",
"info",
"dict",
"from",
"specified",
"Redis",
"instance"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L252-L267 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector._get_config | def _get_config(self, host, port, unix_socket, auth, config_key):
"""Return config string from specified Redis instance and config key
:param str host: redis host
:param int port: redis port
:param str host: redis config_key
:rtype: str
"""
client = self._client(host, port, unix_socket, auth)... | python | def _get_config(self, host, port, unix_socket, auth, config_key):
"""Return config string from specified Redis instance and config key
:param str host: redis host
:param int port: redis port
:param str host: redis config_key
:rtype: str
"""
client = self._client(host, port, unix_socket, auth)... | [
"def",
"_get_config",
"(",
"self",
",",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
",",
"config_key",
")",
":",
"client",
"=",
"self",
".",
"_client",
"(",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
")",
"if",
"client",
"is",
"N... | Return config string from specified Redis instance and config key
:param str host: redis host
:param int port: redis port
:param str host: redis config_key
:rtype: str | [
"Return",
"config",
"string",
"from",
"specified",
"Redis",
"instance",
"and",
"config",
"key"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L269-L285 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector.collect_instance | def collect_instance(self, nick, host, port, unix_socket, auth):
"""Collect metrics from a single Redis instance
:param str nick: nickname of redis instance
:param str host: redis host
:param int port: redis port
:param str unix_socket: unix socket, if applicable
:param str auth: authentication password
... | python | def collect_instance(self, nick, host, port, unix_socket, auth):
"""Collect metrics from a single Redis instance
:param str nick: nickname of redis instance
:param str host: redis host
:param int port: redis port
:param str unix_socket: unix socket, if applicable
:param str auth: authentication password
... | [
"def",
"collect_instance",
"(",
"self",
",",
"nick",
",",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",
")",
":",
"# Connect to redis and get the info",
"info",
"=",
"self",
".",
"_get_info",
"(",
"host",
",",
"port",
",",
"unix_socket",
",",
"auth",... | Collect metrics from a single Redis instance
:param str nick: nickname of redis instance
:param str host: redis host
:param int port: redis port
:param str unix_socket: unix socket, if applicable
:param str auth: authentication password | [
"Collect",
"metrics",
"from",
"a",
"single",
"Redis",
"instance"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L287-L363 | train |
python-diamond/Diamond | src/collectors/redisstat/redisstat.py | RedisCollector.collect | def collect(self):
"""Collect the stats from the redis instance and publish them.
"""
if redis is None:
self.log.error('Unable to import module redis')
return {}
for nick in self.instances.keys():
(host, port, unix_socket, auth) = self.instances[nick... | python | def collect(self):
"""Collect the stats from the redis instance and publish them.
"""
if redis is None:
self.log.error('Unable to import module redis')
return {}
for nick in self.instances.keys():
(host, port, unix_socket, auth) = self.instances[nick... | [
"def",
"collect",
"(",
"self",
")",
":",
"if",
"redis",
"is",
"None",
":",
"self",
".",
"log",
".",
"error",
"(",
"'Unable to import module redis'",
")",
"return",
"{",
"}",
"for",
"nick",
"in",
"self",
".",
"instances",
".",
"keys",
"(",
")",
":",
"... | Collect the stats from the redis instance and publish them. | [
"Collect",
"the",
"stats",
"from",
"the",
"redis",
"instance",
"and",
"publish",
"them",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/redisstat/redisstat.py#L365-L375 | train |
python-diamond/Diamond | src/collectors/xfs/xfs.py | XFSCollector.get_default_config | def get_default_config(self):
"""
Returns the xfs collector settings
"""
config = super(XFSCollector, self).get_default_config()
config.update({
'path': 'xfs'
})
return config | python | def get_default_config(self):
"""
Returns the xfs collector settings
"""
config = super(XFSCollector, self).get_default_config()
config.update({
'path': 'xfs'
})
return config | [
"def",
"get_default_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"XFSCollector",
",",
"self",
")",
".",
"get_default_config",
"(",
")",
"config",
".",
"update",
"(",
"{",
"'path'",
":",
"'xfs'",
"}",
")",
"return",
"config"
] | Returns the xfs collector settings | [
"Returns",
"the",
"xfs",
"collector",
"settings"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/xfs/xfs.py#L25-L33 | train |
python-diamond/Diamond | src/diamond/handler/cloudwatch.py | cloudwatchHandler._bind | def _bind(self):
"""
Create CloudWatch Connection
"""
self.log.debug(
"CloudWatch: Attempting to connect to CloudWatch at Region: %s",
self.region)
try:
self.connection = boto.ec2.cloudwatch.connect_to_region(
self.region)
... | python | def _bind(self):
"""
Create CloudWatch Connection
"""
self.log.debug(
"CloudWatch: Attempting to connect to CloudWatch at Region: %s",
self.region)
try:
self.connection = boto.ec2.cloudwatch.connect_to_region(
self.region)
... | [
"def",
"_bind",
"(",
"self",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"CloudWatch: Attempting to connect to CloudWatch at Region: %s\"",
",",
"self",
".",
"region",
")",
"try",
":",
"self",
".",
"connection",
"=",
"boto",
".",
"ec2",
".",
"cloudwatch... | Create CloudWatch Connection | [
"Create",
"CloudWatch",
"Connection"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/cloudwatch.py#L163-L178 | train |
python-diamond/Diamond | src/diamond/handler/cloudwatch.py | cloudwatchHandler.process | def process(self, metric):
"""
Process a metric and send it to CloudWatch
"""
if not boto:
return
collector = str(metric.getCollectorPath())
metricname = str(metric.getMetricPath())
# Send the data as ......
for rule in self.rules:
... | python | def process(self, metric):
"""
Process a metric and send it to CloudWatch
"""
if not boto:
return
collector = str(metric.getCollectorPath())
metricname = str(metric.getMetricPath())
# Send the data as ......
for rule in self.rules:
... | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"if",
"not",
"boto",
":",
"return",
"collector",
"=",
"str",
"(",
"metric",
".",
"getCollectorPath",
"(",
")",
")",
"metricname",
"=",
"str",
"(",
"metric",
".",
"getMetricPath",
"(",
")",
")",
... | Process a metric and send it to CloudWatch | [
"Process",
"a",
"metric",
"and",
"send",
"it",
"to",
"CloudWatch"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/cloudwatch.py#L189-L224 | train |
python-diamond/Diamond | src/diamond/handler/cloudwatch.py | cloudwatchHandler.send_metrics_to_cloudwatch | def send_metrics_to_cloudwatch(self, rule, metric, dimensions):
"""
Send metrics to CloudWatch for the given dimensions
"""
timestamp = datetime.datetime.utcfromtimestamp(metric.timestamp)
self.log.debug(
"CloudWatch: Attempting to publish metric: %s to %s "
... | python | def send_metrics_to_cloudwatch(self, rule, metric, dimensions):
"""
Send metrics to CloudWatch for the given dimensions
"""
timestamp = datetime.datetime.utcfromtimestamp(metric.timestamp)
self.log.debug(
"CloudWatch: Attempting to publish metric: %s to %s "
... | [
"def",
"send_metrics_to_cloudwatch",
"(",
"self",
",",
"rule",
",",
"metric",
",",
"dimensions",
")",
":",
"timestamp",
"=",
"datetime",
".",
"datetime",
".",
"utcfromtimestamp",
"(",
"metric",
".",
"timestamp",
")",
"self",
".",
"log",
".",
"debug",
"(",
... | Send metrics to CloudWatch for the given dimensions | [
"Send",
"metrics",
"to",
"CloudWatch",
"for",
"the",
"given",
"dimensions"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/cloudwatch.py#L226-L265 | train |
python-diamond/Diamond | src/collectors/mongodb/mongodb.py | MongoDBCollector._publish_replset | def _publish_replset(self, data, base_prefix):
""" Given a response to replSetGetStatus, publishes all numeric values
of the instance, aggregate stats of healthy nodes vs total nodes,
and the observed statuses of all nodes in the replica set.
"""
prefix = base_prefix + ['... | python | def _publish_replset(self, data, base_prefix):
""" Given a response to replSetGetStatus, publishes all numeric values
of the instance, aggregate stats of healthy nodes vs total nodes,
and the observed statuses of all nodes in the replica set.
"""
prefix = base_prefix + ['... | [
"def",
"_publish_replset",
"(",
"self",
",",
"data",
",",
"base_prefix",
")",
":",
"prefix",
"=",
"base_prefix",
"+",
"[",
"'replset'",
"]",
"self",
".",
"_publish_dict_with_prefix",
"(",
"data",
",",
"prefix",
")",
"total_nodes",
"=",
"len",
"(",
"data",
... | Given a response to replSetGetStatus, publishes all numeric values
of the instance, aggregate stats of healthy nodes vs total nodes,
and the observed statuses of all nodes in the replica set. | [
"Given",
"a",
"response",
"to",
"replSetGetStatus",
"publishes",
"all",
"numeric",
"values",
"of",
"the",
"instance",
"aggregate",
"stats",
"of",
"healthy",
"nodes",
"vs",
"total",
"nodes",
"and",
"the",
"observed",
"statuses",
"of",
"all",
"nodes",
"in",
"the... | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mongodb/mongodb.py#L230-L248 | train |
python-diamond/Diamond | src/diamond/handler/influxdbHandler.py | InfluxdbHandler._send | def _send(self):
"""
Send data to Influxdb. Data that can not be sent will be kept in queued.
"""
# Check to see if we have a valid socket. If not, try to connect.
try:
if self.influx is None:
self.log.debug("InfluxdbHandler: Socket is not connected. "... | python | def _send(self):
"""
Send data to Influxdb. Data that can not be sent will be kept in queued.
"""
# Check to see if we have a valid socket. If not, try to connect.
try:
if self.influx is None:
self.log.debug("InfluxdbHandler: Socket is not connected. "... | [
"def",
"_send",
"(",
"self",
")",
":",
"# Check to see if we have a valid socket. If not, try to connect.",
"try",
":",
"if",
"self",
".",
"influx",
"is",
"None",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"InfluxdbHandler: Socket is not connected. \"",
"\"Reconnecti... | Send data to Influxdb. Data that can not be sent will be kept in queued. | [
"Send",
"data",
"to",
"Influxdb",
".",
"Data",
"that",
"can",
"not",
"be",
"sent",
"will",
"be",
"kept",
"in",
"queued",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/influxdbHandler.py#L156-L194 | train |
python-diamond/Diamond | src/diamond/handler/influxdbHandler.py | InfluxdbHandler._connect | def _connect(self):
"""
Connect to the influxdb server
"""
try:
# Open Connection
self.influx = InfluxDBClient(self.hostname, self.port,
self.username, self.password,
self.database,... | python | def _connect(self):
"""
Connect to the influxdb server
"""
try:
# Open Connection
self.influx = InfluxDBClient(self.hostname, self.port,
self.username, self.password,
self.database,... | [
"def",
"_connect",
"(",
"self",
")",
":",
"try",
":",
"# Open Connection",
"self",
".",
"influx",
"=",
"InfluxDBClient",
"(",
"self",
".",
"hostname",
",",
"self",
".",
"port",
",",
"self",
".",
"username",
",",
"self",
".",
"password",
",",
"self",
".... | Connect to the influxdb server | [
"Connect",
"to",
"the",
"influxdb",
"server"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/influxdbHandler.py#L196-L217 | train |
python-diamond/Diamond | src/diamond/handler/rabbitmq_pubsub.py | rmqHandler.get_config | def get_config(self):
""" Get and set config options from config file """
if 'rmq_port' in self.config:
self.rmq_port = int(self.config['rmq_port'])
if 'rmq_user' in self.config:
self.rmq_user = self.config['rmq_user']
if 'rmq_password' in self.config:
... | python | def get_config(self):
""" Get and set config options from config file """
if 'rmq_port' in self.config:
self.rmq_port = int(self.config['rmq_port'])
if 'rmq_user' in self.config:
self.rmq_user = self.config['rmq_user']
if 'rmq_password' in self.config:
... | [
"def",
"get_config",
"(",
"self",
")",
":",
"if",
"'rmq_port'",
"in",
"self",
".",
"config",
":",
"self",
".",
"rmq_port",
"=",
"int",
"(",
"self",
".",
"config",
"[",
"'rmq_port'",
"]",
")",
"if",
"'rmq_user'",
"in",
"self",
".",
"config",
":",
"sel... | Get and set config options from config file | [
"Get",
"and",
"set",
"config",
"options",
"from",
"config",
"file"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/rabbitmq_pubsub.py#L63-L85 | train |
python-diamond/Diamond | src/diamond/handler/rabbitmq_pubsub.py | rmqHandler._unbind | def _unbind(self, rmq_server=None):
""" Close AMQP connection and unset channel """
try:
self.connections[rmq_server].close()
except AttributeError:
pass
self.connections[rmq_server] = None
self.channels[rmq_server] = None | python | def _unbind(self, rmq_server=None):
""" Close AMQP connection and unset channel """
try:
self.connections[rmq_server].close()
except AttributeError:
pass
self.connections[rmq_server] = None
self.channels[rmq_server] = None | [
"def",
"_unbind",
"(",
"self",
",",
"rmq_server",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"connections",
"[",
"rmq_server",
"]",
".",
"close",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"self",
".",
"connections",
"[",
"rmq_server",
"]",
... | Close AMQP connection and unset channel | [
"Close",
"AMQP",
"connection",
"and",
"unset",
"channel"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/rabbitmq_pubsub.py#L172-L180 | train |
python-diamond/Diamond | src/diamond/handler/rabbitmq_pubsub.py | rmqHandler.process | def process(self, metric):
"""
Process a metric and send it to RMQ pub socket
"""
for rmq_server in self.connections.keys():
try:
if ((self.connections[rmq_server] is None or
self.connections[rmq_server].is_open is False)):
... | python | def process(self, metric):
"""
Process a metric and send it to RMQ pub socket
"""
for rmq_server in self.connections.keys():
try:
if ((self.connections[rmq_server] is None or
self.connections[rmq_server].is_open is False)):
... | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"for",
"rmq_server",
"in",
"self",
".",
"connections",
".",
"keys",
"(",
")",
":",
"try",
":",
"if",
"(",
"(",
"self",
".",
"connections",
"[",
"rmq_server",
"]",
"is",
"None",
"or",
"self",
"... | Process a metric and send it to RMQ pub socket | [
"Process",
"a",
"metric",
"and",
"send",
"it",
"to",
"RMQ",
"pub",
"socket"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/rabbitmq_pubsub.py#L190-L209 | train |
python-diamond/Diamond | src/collectors/netstat/netstat.py | NetstatCollector._load | def _load():
""" Read the table of tcp connections & remove header """
with open(NetstatCollector.PROC_TCP, 'r') as f:
content = f.readlines()
content.pop(0)
return content | python | def _load():
""" Read the table of tcp connections & remove header """
with open(NetstatCollector.PROC_TCP, 'r') as f:
content = f.readlines()
content.pop(0)
return content | [
"def",
"_load",
"(",
")",
":",
"with",
"open",
"(",
"NetstatCollector",
".",
"PROC_TCP",
",",
"'r'",
")",
"as",
"f",
":",
"content",
"=",
"f",
".",
"readlines",
"(",
")",
"content",
".",
"pop",
"(",
"0",
")",
"return",
"content"
] | Read the table of tcp connections & remove header | [
"Read",
"the",
"table",
"of",
"tcp",
"connections",
"&",
"remove",
"header"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/netstat/netstat.py#L62-L67 | train |
python-diamond/Diamond | src/collectors/memory_lxc/memory_lxc.py | MemoryLxcCollector.get_default_config_help | def get_default_config_help(self):
"""
Return help text for collector configuration.
"""
config_help = super(MemoryLxcCollector, self).get_default_config_help()
config_help.update({
"sys_path": "Defaults to '/sys/fs/cgroup/lxc'",
})
return config_help | python | def get_default_config_help(self):
"""
Return help text for collector configuration.
"""
config_help = super(MemoryLxcCollector, self).get_default_config_help()
config_help.update({
"sys_path": "Defaults to '/sys/fs/cgroup/lxc'",
})
return config_help | [
"def",
"get_default_config_help",
"(",
"self",
")",
":",
"config_help",
"=",
"super",
"(",
"MemoryLxcCollector",
",",
"self",
")",
".",
"get_default_config_help",
"(",
")",
"config_help",
".",
"update",
"(",
"{",
"\"sys_path\"",
":",
"\"Defaults to '/sys/fs/cgroup/l... | Return help text for collector configuration. | [
"Return",
"help",
"text",
"for",
"collector",
"configuration",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memory_lxc/memory_lxc.py#L18-L26 | train |
python-diamond/Diamond | src/collectors/memory_lxc/memory_lxc.py | MemoryLxcCollector.get_default_config | def get_default_config(self):
"""
Returns default settings for collector.
"""
config = super(MemoryLxcCollector, self).get_default_config()
config.update({
"path": "lxc",
"sys_path": "/sys/fs/cgroup/lxc",
})
return config | python | def get_default_config(self):
"""
Returns default settings for collector.
"""
config = super(MemoryLxcCollector, self).get_default_config()
config.update({
"path": "lxc",
"sys_path": "/sys/fs/cgroup/lxc",
})
return config | [
"def",
"get_default_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"MemoryLxcCollector",
",",
"self",
")",
".",
"get_default_config",
"(",
")",
"config",
".",
"update",
"(",
"{",
"\"path\"",
":",
"\"lxc\"",
",",
"\"sys_path\"",
":",
"\"/sys/fs/... | Returns default settings for collector. | [
"Returns",
"default",
"settings",
"for",
"collector",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memory_lxc/memory_lxc.py#L28-L37 | train |
python-diamond/Diamond | src/collectors/memory_lxc/memory_lxc.py | MemoryLxcCollector.collect | def collect(self):
"""
Collect memory stats of LXCs.
"""
lxc_metrics = ["memory.usage_in_bytes", "memory.limit_in_bytes"]
if os.path.isdir(self.config["sys_path"]) is False:
self.log.debug("sys_path '%s' isn't directory.",
self.config["sys_p... | python | def collect(self):
"""
Collect memory stats of LXCs.
"""
lxc_metrics = ["memory.usage_in_bytes", "memory.limit_in_bytes"]
if os.path.isdir(self.config["sys_path"]) is False:
self.log.debug("sys_path '%s' isn't directory.",
self.config["sys_p... | [
"def",
"collect",
"(",
"self",
")",
":",
"lxc_metrics",
"=",
"[",
"\"memory.usage_in_bytes\"",
",",
"\"memory.limit_in_bytes\"",
"]",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"self",
".",
"config",
"[",
"\"sys_path\"",
"]",
")",
"is",
"False",
":",
"sel... | Collect memory stats of LXCs. | [
"Collect",
"memory",
"stats",
"of",
"LXCs",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memory_lxc/memory_lxc.py#L39-L74 | train |
python-diamond/Diamond | src/collectors/memory_lxc/memory_lxc.py | MemoryLxcCollector._read_file | def _read_file(self, filename):
"""
Read contents of given file.
"""
try:
with open(filename, "r") as fhandle:
stats = float(fhandle.readline().rstrip("\n"))
except Exception:
stats = None
return stats | python | def _read_file(self, filename):
"""
Read contents of given file.
"""
try:
with open(filename, "r") as fhandle:
stats = float(fhandle.readline().rstrip("\n"))
except Exception:
stats = None
return stats | [
"def",
"_read_file",
"(",
"self",
",",
"filename",
")",
":",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"\"r\"",
")",
"as",
"fhandle",
":",
"stats",
"=",
"float",
"(",
"fhandle",
".",
"readline",
"(",
")",
".",
"rstrip",
"(",
"\"\\n\"",
")",
... | Read contents of given file. | [
"Read",
"contents",
"of",
"given",
"file",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memory_lxc/memory_lxc.py#L76-L86 | train |
python-diamond/Diamond | src/diamond/util.py | load_modules_from_path | def load_modules_from_path(path):
"""
Import all modules from the given directory
"""
# Check and fix the path
if path[-1:] != '/':
path += '/'
# Get a list of files in the directory, if the directory exists
if not os.path.exists(path):
raise OSError("Directory does not exis... | python | def load_modules_from_path(path):
"""
Import all modules from the given directory
"""
# Check and fix the path
if path[-1:] != '/':
path += '/'
# Get a list of files in the directory, if the directory exists
if not os.path.exists(path):
raise OSError("Directory does not exis... | [
"def",
"load_modules_from_path",
"(",
"path",
")",
":",
"# Check and fix the path",
"if",
"path",
"[",
"-",
"1",
":",
"]",
"!=",
"'/'",
":",
"path",
"+=",
"'/'",
"# Get a list of files in the directory, if the directory exists",
"if",
"not",
"os",
".",
"path",
"."... | Import all modules from the given directory | [
"Import",
"all",
"modules",
"from",
"the",
"given",
"directory"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/util.py#L16-L36 | train |
python-diamond/Diamond | src/diamond/handler/logentries_diamond.py | LogentriesDiamondHandler.process | def process(self, metric):
"""
Process metric by sending it to datadog api
"""
self.queue.append(metric)
if len(self.queue) >= self.queue_size:
logging.debug("Queue is full, sending logs to Logentries")
self._send() | python | def process(self, metric):
"""
Process metric by sending it to datadog api
"""
self.queue.append(metric)
if len(self.queue) >= self.queue_size:
logging.debug("Queue is full, sending logs to Logentries")
self._send() | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"self",
".",
"queue",
".",
"append",
"(",
"metric",
")",
"if",
"len",
"(",
"self",
".",
"queue",
")",
">=",
"self",
".",
"queue_size",
":",
"logging",
".",
"debug",
"(",
"\"Queue is full, sending ... | Process metric by sending it to datadog api | [
"Process",
"metric",
"by",
"sending",
"it",
"to",
"datadog",
"api"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/logentries_diamond.py#L60-L68 | train |
python-diamond/Diamond | src/diamond/handler/logentries_diamond.py | LogentriesDiamondHandler._send | def _send(self):
"""
Convert message to a json object and send to Lognetries
"""
while len(self.queue) > 0:
metric = self.queue.popleft()
topic, value, timestamp = str(metric).split()
msg = json.dumps({"event": {topic: value}})
req = urllib... | python | def _send(self):
"""
Convert message to a json object and send to Lognetries
"""
while len(self.queue) > 0:
metric = self.queue.popleft()
topic, value, timestamp = str(metric).split()
msg = json.dumps({"event": {topic: value}})
req = urllib... | [
"def",
"_send",
"(",
"self",
")",
":",
"while",
"len",
"(",
"self",
".",
"queue",
")",
">",
"0",
":",
"metric",
"=",
"self",
".",
"queue",
".",
"popleft",
"(",
")",
"topic",
",",
"value",
",",
"timestamp",
"=",
"str",
"(",
"metric",
")",
".",
"... | Convert message to a json object and send to Lognetries | [
"Convert",
"message",
"to",
"a",
"json",
"object",
"and",
"send",
"to",
"Lognetries"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/logentries_diamond.py#L70-L83 | train |
python-diamond/Diamond | src/collectors/smart/smart.py | SmartCollector.collect | def collect(self):
"""
Collect and publish S.M.A.R.T. attributes
"""
devices = re.compile(self.config['devices'])
for device in os.listdir('/dev'):
if devices.match(device):
command = [self.config['bin'], "-A", os.path.join('/dev',
... | python | def collect(self):
"""
Collect and publish S.M.A.R.T. attributes
"""
devices = re.compile(self.config['devices'])
for device in os.listdir('/dev'):
if devices.match(device):
command = [self.config['bin'], "-A", os.path.join('/dev',
... | [
"def",
"collect",
"(",
"self",
")",
":",
"devices",
"=",
"re",
".",
"compile",
"(",
"self",
".",
"config",
"[",
"'devices'",
"]",
")",
"for",
"device",
"in",
"os",
".",
"listdir",
"(",
"'/dev'",
")",
":",
"if",
"devices",
".",
"match",
"(",
"device... | Collect and publish S.M.A.R.T. attributes | [
"Collect",
"and",
"publish",
"S",
".",
"M",
".",
"A",
".",
"R",
".",
"T",
".",
"attributes"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/smart/smart.py#L45-L99 | train |
python-diamond/Diamond | src/collectors/smart/smart.py | SmartCollector.find_attr_start_line | def find_attr_start_line(self, lines, min_line=4, max_line=9):
"""
Return line number of the first real attribute and value.
The first line is 0. If the 'ATTRIBUTE_NAME' header is not
found, return the index after max_line.
"""
for idx, line in enumerate(lines[min_line:m... | python | def find_attr_start_line(self, lines, min_line=4, max_line=9):
"""
Return line number of the first real attribute and value.
The first line is 0. If the 'ATTRIBUTE_NAME' header is not
found, return the index after max_line.
"""
for idx, line in enumerate(lines[min_line:m... | [
"def",
"find_attr_start_line",
"(",
"self",
",",
"lines",
",",
"min_line",
"=",
"4",
",",
"max_line",
"=",
"9",
")",
":",
"for",
"idx",
",",
"line",
"in",
"enumerate",
"(",
"lines",
"[",
"min_line",
":",
"max_line",
"]",
")",
":",
"col",
"=",
"line",... | Return line number of the first real attribute and value.
The first line is 0. If the 'ATTRIBUTE_NAME' header is not
found, return the index after max_line. | [
"Return",
"line",
"number",
"of",
"the",
"first",
"real",
"attribute",
"and",
"value",
".",
"The",
"first",
"line",
"is",
"0",
".",
"If",
"the",
"ATTRIBUTE_NAME",
"header",
"is",
"not",
"found",
"return",
"the",
"index",
"after",
"max_line",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/smart/smart.py#L101-L116 | train |
python-diamond/Diamond | src/collectors/diskspace/diskspace.py | DiskSpaceCollector.get_disk_labels | def get_disk_labels(self):
"""
Creates a mapping of device nodes to filesystem labels
"""
path = '/dev/disk/by-label/'
labels = {}
if not os.path.isdir(path):
return labels
for label in os.listdir(path):
label = label.replace('\\x2f', '/')... | python | def get_disk_labels(self):
"""
Creates a mapping of device nodes to filesystem labels
"""
path = '/dev/disk/by-label/'
labels = {}
if not os.path.isdir(path):
return labels
for label in os.listdir(path):
label = label.replace('\\x2f', '/')... | [
"def",
"get_disk_labels",
"(",
"self",
")",
":",
"path",
"=",
"'/dev/disk/by-label/'",
"labels",
"=",
"{",
"}",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
":",
"return",
"labels",
"for",
"label",
"in",
"os",
".",
"listdir",
"(",
... | Creates a mapping of device nodes to filesystem labels | [
"Creates",
"a",
"mapping",
"of",
"device",
"nodes",
"to",
"filesystem",
"labels"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/diskspace/diskspace.py#L96-L110 | train |
python-diamond/Diamond | src/collectors/diskspace/diskspace.py | DiskSpaceCollector.get_file_systems | def get_file_systems(self):
"""
Creates a map of mounted filesystems on the machine.
iostat(1): Each sector has size of 512 bytes.
Returns:
st_dev -> FileSystem(device, mount_point)
"""
result = {}
if os.access('/proc/mounts', os.R_OK):
fil... | python | def get_file_systems(self):
"""
Creates a map of mounted filesystems on the machine.
iostat(1): Each sector has size of 512 bytes.
Returns:
st_dev -> FileSystem(device, mount_point)
"""
result = {}
if os.access('/proc/mounts', os.R_OK):
fil... | [
"def",
"get_file_systems",
"(",
"self",
")",
":",
"result",
"=",
"{",
"}",
"if",
"os",
".",
"access",
"(",
"'/proc/mounts'",
",",
"os",
".",
"R_OK",
")",
":",
"file",
"=",
"open",
"(",
"'/proc/mounts'",
")",
"for",
"line",
"in",
"file",
":",
"try",
... | Creates a map of mounted filesystems on the machine.
iostat(1): Each sector has size of 512 bytes.
Returns:
st_dev -> FileSystem(device, mount_point) | [
"Creates",
"a",
"map",
"of",
"mounted",
"filesystems",
"on",
"the",
"machine",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/diskspace/diskspace.py#L112-L181 | train |
python-diamond/Diamond | src/diamond/handler/libratohandler.py | LibratoHandler.process | def process(self, metric):
"""
Process a metric by sending it to Librato
"""
path = metric.getCollectorPath()
path += '.'
path += metric.getMetricPath()
if self.config['apply_metric_prefix']:
path = metric.getPathPrefix() + '.' + path
if self.... | python | def process(self, metric):
"""
Process a metric by sending it to Librato
"""
path = metric.getCollectorPath()
path += '.'
path += metric.getMetricPath()
if self.config['apply_metric_prefix']:
path = metric.getPathPrefix() + '.' + path
if self.... | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"path",
"=",
"metric",
".",
"getCollectorPath",
"(",
")",
"path",
"+=",
"'.'",
"path",
"+=",
"metric",
".",
"getMetricPath",
"(",
")",
"if",
"self",
".",
"config",
"[",
"'apply_metric_prefix'",
"]",... | Process a metric by sending it to Librato | [
"Process",
"a",
"metric",
"by",
"sending",
"it",
"to",
"Librato"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/libratohandler.py#L98-L127 | train |
python-diamond/Diamond | src/diamond/handler/libratohandler.py | LibratoHandler._send | def _send(self):
"""
Send data to Librato.
"""
self.queue.submit()
self.queue_max_timestamp = int(time.time() + self.queue_max_interval)
self.current_n_measurements = 0 | python | def _send(self):
"""
Send data to Librato.
"""
self.queue.submit()
self.queue_max_timestamp = int(time.time() + self.queue_max_interval)
self.current_n_measurements = 0 | [
"def",
"_send",
"(",
"self",
")",
":",
"self",
".",
"queue",
".",
"submit",
"(",
")",
"self",
".",
"queue_max_timestamp",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
"+",
"self",
".",
"queue_max_interval",
")",
"self",
".",
"current_n_measurements",
... | Send data to Librato. | [
"Send",
"data",
"to",
"Librato",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/libratohandler.py#L133-L139 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.collect | def collect(self):
"""
Collect and publish metrics
"""
stats = self.parse_stats_file(self.config["status_path"])
if len(stats) == 0:
return {}
elif "info" not in stats.keys():
return {}
elif "programstatus" not in stats.keys():
... | python | def collect(self):
"""
Collect and publish metrics
"""
stats = self.parse_stats_file(self.config["status_path"])
if len(stats) == 0:
return {}
elif "info" not in stats.keys():
return {}
elif "programstatus" not in stats.keys():
... | [
"def",
"collect",
"(",
"self",
")",
":",
"stats",
"=",
"self",
".",
"parse_stats_file",
"(",
"self",
".",
"config",
"[",
"\"status_path\"",
"]",
")",
"if",
"len",
"(",
"stats",
")",
"==",
"0",
":",
"return",
"{",
"}",
"elif",
"\"info\"",
"not",
"in",... | Collect and publish metrics | [
"Collect",
"and",
"publish",
"metrics"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L19-L44 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.get_default_config | def get_default_config(self):
"""
Returns default settings for collector
"""
config = super(IcingaStatsCollector, self).get_default_config()
config.update({
"path": "icinga_stats",
"status_path": "/var/lib/icinga/status.dat",
})
return conf... | python | def get_default_config(self):
"""
Returns default settings for collector
"""
config = super(IcingaStatsCollector, self).get_default_config()
config.update({
"path": "icinga_stats",
"status_path": "/var/lib/icinga/status.dat",
})
return conf... | [
"def",
"get_default_config",
"(",
"self",
")",
":",
"config",
"=",
"super",
"(",
"IcingaStatsCollector",
",",
"self",
")",
".",
"get_default_config",
"(",
")",
"config",
".",
"update",
"(",
"{",
"\"path\"",
":",
"\"icinga_stats\"",
",",
"\"status_path\"",
":",... | Returns default settings for collector | [
"Returns",
"default",
"settings",
"for",
"collector"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L57-L66 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.get_icinga_stats | def get_icinga_stats(self, app_stats):
""" Extract metrics from 'programstatus' """
stats = {}
stats = dict(stats.items() + self._get_active_stats(app_stats).items())
stats = dict(stats.items() + self._get_cached_stats(app_stats).items())
stats = dict(
stats.items() +... | python | def get_icinga_stats(self, app_stats):
""" Extract metrics from 'programstatus' """
stats = {}
stats = dict(stats.items() + self._get_active_stats(app_stats).items())
stats = dict(stats.items() + self._get_cached_stats(app_stats).items())
stats = dict(
stats.items() +... | [
"def",
"get_icinga_stats",
"(",
"self",
",",
"app_stats",
")",
":",
"stats",
"=",
"{",
"}",
"stats",
"=",
"dict",
"(",
"stats",
".",
"items",
"(",
")",
"+",
"self",
".",
"_get_active_stats",
"(",
"app_stats",
")",
".",
"items",
"(",
")",
")",
"stats"... | Extract metrics from 'programstatus' | [
"Extract",
"metrics",
"from",
"programstatus"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L68-L78 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.parse_stats_file | def parse_stats_file(self, file_name):
""" Read and parse given file_name, return config as a dictionary """
stats = {}
try:
with open(file_name, "r") as fhandle:
fbuffer = []
save_buffer = False
for line in fhandle:
... | python | def parse_stats_file(self, file_name):
""" Read and parse given file_name, return config as a dictionary """
stats = {}
try:
with open(file_name, "r") as fhandle:
fbuffer = []
save_buffer = False
for line in fhandle:
... | [
"def",
"parse_stats_file",
"(",
"self",
",",
"file_name",
")",
":",
"stats",
"=",
"{",
"}",
"try",
":",
"with",
"open",
"(",
"file_name",
",",
"\"r\"",
")",
"as",
"fhandle",
":",
"fbuffer",
"=",
"[",
"]",
"save_buffer",
"=",
"False",
"for",
"line",
"... | Read and parse given file_name, return config as a dictionary | [
"Read",
"and",
"parse",
"given",
"file_name",
"return",
"config",
"as",
"a",
"dictionary"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L80-L121 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.get_host_stats | def get_host_stats(self, hosts):
""" Get statistics for Hosts, resp. Host entities """
stats = {
"hosts.total": 0,
"hosts.ok": 0,
"hosts.down": 0,
"hosts.unreachable": 0,
"hosts.flapping": 0,
"hosts.in_downtime": 0,
"hos... | python | def get_host_stats(self, hosts):
""" Get statistics for Hosts, resp. Host entities """
stats = {
"hosts.total": 0,
"hosts.ok": 0,
"hosts.down": 0,
"hosts.unreachable": 0,
"hosts.flapping": 0,
"hosts.in_downtime": 0,
"hos... | [
"def",
"get_host_stats",
"(",
"self",
",",
"hosts",
")",
":",
"stats",
"=",
"{",
"\"hosts.total\"",
":",
"0",
",",
"\"hosts.ok\"",
":",
"0",
",",
"\"hosts.down\"",
":",
"0",
",",
"\"hosts.unreachable\"",
":",
"0",
",",
"\"hosts.flapping\"",
":",
"0",
",",
... | Get statistics for Hosts, resp. Host entities | [
"Get",
"statistics",
"for",
"Hosts",
"resp",
".",
"Host",
"entities"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L123-L153 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector.get_svc_stats | def get_svc_stats(self, svcs):
""" Get statistics for Services, resp. Service entities """
stats = {
"services.total": 0,
"services.ok": 0,
"services.warning": 0,
"services.critical": 0,
"services.unknown": 0,
"services.flapping": 0... | python | def get_svc_stats(self, svcs):
""" Get statistics for Services, resp. Service entities """
stats = {
"services.total": 0,
"services.ok": 0,
"services.warning": 0,
"services.critical": 0,
"services.unknown": 0,
"services.flapping": 0... | [
"def",
"get_svc_stats",
"(",
"self",
",",
"svcs",
")",
":",
"stats",
"=",
"{",
"\"services.total\"",
":",
"0",
",",
"\"services.ok\"",
":",
"0",
",",
"\"services.warning\"",
":",
"0",
",",
"\"services.critical\"",
":",
"0",
",",
"\"services.unknown\"",
":",
... | Get statistics for Services, resp. Service entities | [
"Get",
"statistics",
"for",
"Services",
"resp",
".",
"Service",
"entities"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L155-L187 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector._convert_tripplet | def _convert_tripplet(self, tripplet):
""" Turn '10,178,528' into tuple of integers """
splitted = tripplet.split(",")
if len(splitted) != 3:
self.log.debug("Got %i chunks, expected 3.", len(splitted))
return (0, 0, 0)
try:
x01 = int(splitted[0])
... | python | def _convert_tripplet(self, tripplet):
""" Turn '10,178,528' into tuple of integers """
splitted = tripplet.split(",")
if len(splitted) != 3:
self.log.debug("Got %i chunks, expected 3.", len(splitted))
return (0, 0, 0)
try:
x01 = int(splitted[0])
... | [
"def",
"_convert_tripplet",
"(",
"self",
",",
"tripplet",
")",
":",
"splitted",
"=",
"tripplet",
".",
"split",
"(",
"\",\"",
")",
"if",
"len",
"(",
"splitted",
")",
"!=",
"3",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Got %i chunks, expected 3.\"",
... | Turn '10,178,528' into tuple of integers | [
"Turn",
"10",
"178",
"528",
"into",
"tuple",
"of",
"integers"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L189-L206 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector._get_uptime | def _get_uptime(self, app_stats):
""" Return Icinga's uptime """
if "program_start" not in app_stats.keys():
return 0
if not app_stats["program_start"].isdigit():
return 0
uptime = int(time.time()) - int(app_stats["program_start"])
if uptime < 0:
... | python | def _get_uptime(self, app_stats):
""" Return Icinga's uptime """
if "program_start" not in app_stats.keys():
return 0
if not app_stats["program_start"].isdigit():
return 0
uptime = int(time.time()) - int(app_stats["program_start"])
if uptime < 0:
... | [
"def",
"_get_uptime",
"(",
"self",
",",
"app_stats",
")",
":",
"if",
"\"program_start\"",
"not",
"in",
"app_stats",
".",
"keys",
"(",
")",
":",
"return",
"0",
"if",
"not",
"app_stats",
"[",
"\"program_start\"",
"]",
".",
"isdigit",
"(",
")",
":",
"return... | Return Icinga's uptime | [
"Return",
"Icinga",
"s",
"uptime"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L323-L335 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector._parse_config_buffer | def _parse_config_buffer(self, fbuffer):
""" Parse buffered chunk of config into dict """
if len(fbuffer) < 1 or not fbuffer[0].endswith("{"):
# Invalid input
return {}
entity = {}
entity_type = fbuffer.pop(0)
entity_type = entity_type.rstrip("{")
... | python | def _parse_config_buffer(self, fbuffer):
""" Parse buffered chunk of config into dict """
if len(fbuffer) < 1 or not fbuffer[0].endswith("{"):
# Invalid input
return {}
entity = {}
entity_type = fbuffer.pop(0)
entity_type = entity_type.rstrip("{")
... | [
"def",
"_parse_config_buffer",
"(",
"self",
",",
"fbuffer",
")",
":",
"if",
"len",
"(",
"fbuffer",
")",
"<",
"1",
"or",
"not",
"fbuffer",
"[",
"0",
"]",
".",
"endswith",
"(",
"\"{\"",
")",
":",
"# Invalid input",
"return",
"{",
"}",
"entity",
"=",
"{... | Parse buffered chunk of config into dict | [
"Parse",
"buffered",
"chunk",
"of",
"config",
"into",
"dict"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L337-L357 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector._sanitize_entity | def _sanitize_entity(self, entity):
"""
Make given entity 'sane' for further use.
"""
aliases = {
"current_state": "state",
"is_flapping": "flapping",
"scheduled_downtime_depth": "in_downtime",
"has_been_checked": "checked",
"sh... | python | def _sanitize_entity(self, entity):
"""
Make given entity 'sane' for further use.
"""
aliases = {
"current_state": "state",
"is_flapping": "flapping",
"scheduled_downtime_depth": "in_downtime",
"has_been_checked": "checked",
"sh... | [
"def",
"_sanitize_entity",
"(",
"self",
",",
"entity",
")",
":",
"aliases",
"=",
"{",
"\"current_state\"",
":",
"\"state\"",
",",
"\"is_flapping\"",
":",
"\"flapping\"",
",",
"\"scheduled_downtime_depth\"",
":",
"\"in_downtime\"",
",",
"\"has_been_checked\"",
":",
"... | Make given entity 'sane' for further use. | [
"Make",
"given",
"entity",
"sane",
"for",
"further",
"use",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L359-L395 | train |
python-diamond/Diamond | src/collectors/icinga_stats/icinga_stats.py | IcingaStatsCollector._trim | def _trim(self, somestr):
""" Trim left-right given string """
tmp = RE_LSPACES.sub("", somestr)
tmp = RE_TSPACES.sub("", tmp)
return str(tmp) | python | def _trim(self, somestr):
""" Trim left-right given string """
tmp = RE_LSPACES.sub("", somestr)
tmp = RE_TSPACES.sub("", tmp)
return str(tmp) | [
"def",
"_trim",
"(",
"self",
",",
"somestr",
")",
":",
"tmp",
"=",
"RE_LSPACES",
".",
"sub",
"(",
"\"\"",
",",
"somestr",
")",
"tmp",
"=",
"RE_TSPACES",
".",
"sub",
"(",
"\"\"",
",",
"tmp",
")",
"return",
"str",
"(",
"tmp",
")"
] | Trim left-right given string | [
"Trim",
"left",
"-",
"right",
"given",
"string"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/icinga_stats/icinga_stats.py#L441-L445 | train |
python-diamond/Diamond | src/collectors/jolokia/jolokia.py | JolokiaCollector._list_request | def _list_request(self):
"""Returns a dictionary with JMX domain names as keys"""
try:
# https://jolokia.org/reference/html/protocol.html
#
# A maxDepth of 1 restricts the return value to a map with the JMX
# domains as keys. The values of the maps don't h... | python | def _list_request(self):
"""Returns a dictionary with JMX domain names as keys"""
try:
# https://jolokia.org/reference/html/protocol.html
#
# A maxDepth of 1 restricts the return value to a map with the JMX
# domains as keys. The values of the maps don't h... | [
"def",
"_list_request",
"(",
"self",
")",
":",
"try",
":",
"# https://jolokia.org/reference/html/protocol.html",
"#",
"# A maxDepth of 1 restricts the return value to a map with the JMX",
"# domains as keys. The values of the maps don't have any meaning",
"# and are dummy values.",
"#",
... | Returns a dictionary with JMX domain names as keys | [
"Returns",
"a",
"dictionary",
"with",
"JMX",
"domain",
"names",
"as",
"keys"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/jolokia/jolokia.py#L213-L238 | train |
python-diamond/Diamond | src/collectors/cephstats/cephstats.py | CephStatsCollector._get_stats | def _get_stats(self):
"""
Get ceph stats
"""
try:
output = subprocess.check_output(['ceph', '-s'])
except subprocess.CalledProcessError as err:
self.log.info(
'Could not get stats: %s' % err)
self.log.exception('Could not get st... | python | def _get_stats(self):
"""
Get ceph stats
"""
try:
output = subprocess.check_output(['ceph', '-s'])
except subprocess.CalledProcessError as err:
self.log.info(
'Could not get stats: %s' % err)
self.log.exception('Could not get st... | [
"def",
"_get_stats",
"(",
"self",
")",
":",
"try",
":",
"output",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"'ceph'",
",",
"'-s'",
"]",
")",
"except",
"subprocess",
".",
"CalledProcessError",
"as",
"err",
":",
"self",
".",
"log",
".",
"info",
"... | Get ceph stats | [
"Get",
"ceph",
"stats"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/cephstats/cephstats.py#L65-L76 | train |
python-diamond/Diamond | src/collectors/filestat/filestat.py | FilestatCollector.process_lsof | def process_lsof(self, users, types):
"""
Get the list of users and file types to collect for and collect the
data from lsof
"""
d = {}
for u in users:
d[u] = {}
tmp = os.popen("lsof -wbu %s | awk '{ print $5 }'" % (
u)).read().spli... | python | def process_lsof(self, users, types):
"""
Get the list of users and file types to collect for and collect the
data from lsof
"""
d = {}
for u in users:
d[u] = {}
tmp = os.popen("lsof -wbu %s | awk '{ print $5 }'" % (
u)).read().spli... | [
"def",
"process_lsof",
"(",
"self",
",",
"users",
",",
"types",
")",
":",
"d",
"=",
"{",
"}",
"for",
"u",
"in",
"users",
":",
"d",
"[",
"u",
"]",
"=",
"{",
"}",
"tmp",
"=",
"os",
".",
"popen",
"(",
"\"lsof -wbu %s | awk '{ print $5 }'\"",
"%",
"(",... | Get the list of users and file types to collect for and collect the
data from lsof | [
"Get",
"the",
"list",
"of",
"users",
"and",
"file",
"types",
"to",
"collect",
"for",
"and",
"collect",
"the",
"data",
"from",
"lsof"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/filestat/filestat.py#L231-L243 | train |
python-diamond/Diamond | src/collectors/nfacct/nfacct.py | NetfilterAccountingCollector.collect | def collect(self):
"""
Collect and publish netfilter counters
"""
cmd = [self.config['bin'], "list"]
if str_to_bool(self.config['reset']):
cmd.append("reset")
if str_to_bool(self.config['use_sudo']):
cmd.insert(0, self.config['sudo_cmd'])
... | python | def collect(self):
"""
Collect and publish netfilter counters
"""
cmd = [self.config['bin'], "list"]
if str_to_bool(self.config['reset']):
cmd.append("reset")
if str_to_bool(self.config['use_sudo']):
cmd.insert(0, self.config['sudo_cmd'])
... | [
"def",
"collect",
"(",
"self",
")",
":",
"cmd",
"=",
"[",
"self",
".",
"config",
"[",
"'bin'",
"]",
",",
"\"list\"",
"]",
"if",
"str_to_bool",
"(",
"self",
".",
"config",
"[",
"'reset'",
"]",
")",
":",
"cmd",
".",
"append",
"(",
"\"reset\"",
")",
... | Collect and publish netfilter counters | [
"Collect",
"and",
"publish",
"netfilter",
"counters"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/nfacct/nfacct.py#L47-L75 | train |
python-diamond/Diamond | src/collectors/openvpn/openvpn.py | OpenVPNCollector.parse_url | def parse_url(self, uri):
"""
Convert urlparse from a python 2.4 layout to a python 2.7 layout
"""
parsed = urlparse.urlparse(uri)
if 'scheme' not in parsed:
class Object(object):
pass
newparsed = Object()
newparsed.scheme = par... | python | def parse_url(self, uri):
"""
Convert urlparse from a python 2.4 layout to a python 2.7 layout
"""
parsed = urlparse.urlparse(uri)
if 'scheme' not in parsed:
class Object(object):
pass
newparsed = Object()
newparsed.scheme = par... | [
"def",
"parse_url",
"(",
"self",
",",
"uri",
")",
":",
"parsed",
"=",
"urlparse",
".",
"urlparse",
"(",
"uri",
")",
"if",
"'scheme'",
"not",
"in",
"parsed",
":",
"class",
"Object",
"(",
"object",
")",
":",
"pass",
"newparsed",
"=",
"Object",
"(",
")"... | Convert urlparse from a python 2.4 layout to a python 2.7 layout | [
"Convert",
"urlparse",
"from",
"a",
"python",
"2",
".",
"4",
"layout",
"to",
"a",
"python",
"2",
".",
"7",
"layout"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/openvpn/openvpn.py#L66-L86 | train |
python-diamond/Diamond | src/collectors/jcollectd/jcollectd.py | sanitize_word | def sanitize_word(s):
"""Remove non-alphanumerical characters from metric word.
And trim excessive underscores.
"""
s = re.sub('[^\w-]+', '_', s)
s = re.sub('__+', '_', s)
return s.strip('_') | python | def sanitize_word(s):
"""Remove non-alphanumerical characters from metric word.
And trim excessive underscores.
"""
s = re.sub('[^\w-]+', '_', s)
s = re.sub('__+', '_', s)
return s.strip('_') | [
"def",
"sanitize_word",
"(",
"s",
")",
":",
"s",
"=",
"re",
".",
"sub",
"(",
"'[^\\w-]+'",
",",
"'_'",
",",
"s",
")",
"s",
"=",
"re",
".",
"sub",
"(",
"'__+'",
",",
"'_'",
",",
"s",
")",
"return",
"s",
".",
"strip",
"(",
"'_'",
")"
] | Remove non-alphanumerical characters from metric word.
And trim excessive underscores. | [
"Remove",
"non",
"-",
"alphanumerical",
"characters",
"from",
"metric",
"word",
".",
"And",
"trim",
"excessive",
"underscores",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/jcollectd/jcollectd.py#L197-L203 | train |
python-diamond/Diamond | src/collectors/mesos/mesos.py | MesosCollector._add_cpu_usage | def _add_cpu_usage(self, cur_read):
"""Compute cpu usage based on cpu time spent compared to elapsed time
"""
for executor_id, cur_data in cur_read.items():
if executor_id in self.executors_prev_read:
prev_data = self.executors_prev_read[executor_id]
... | python | def _add_cpu_usage(self, cur_read):
"""Compute cpu usage based on cpu time spent compared to elapsed time
"""
for executor_id, cur_data in cur_read.items():
if executor_id in self.executors_prev_read:
prev_data = self.executors_prev_read[executor_id]
... | [
"def",
"_add_cpu_usage",
"(",
"self",
",",
"cur_read",
")",
":",
"for",
"executor_id",
",",
"cur_data",
"in",
"cur_read",
".",
"items",
"(",
")",
":",
"if",
"executor_id",
"in",
"self",
".",
"executors_prev_read",
":",
"prev_data",
"=",
"self",
".",
"execu... | Compute cpu usage based on cpu time spent compared to elapsed time | [
"Compute",
"cpu",
"usage",
"based",
"on",
"cpu",
"time",
"spent",
"compared",
"to",
"elapsed",
"time"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mesos/mesos.py#L101-L119 | train |
python-diamond/Diamond | src/collectors/mesos/mesos.py | MesosCollector._add_cpu_percent | def _add_cpu_percent(self, cur_read):
"""Compute cpu percent basing on the provided utilisation
"""
for executor_id, cur_data in cur_read.items():
stats = cur_data['statistics']
cpus_limit = stats.get('cpus_limit')
cpus_utilisation = stats.get('cpus_utilisatio... | python | def _add_cpu_percent(self, cur_read):
"""Compute cpu percent basing on the provided utilisation
"""
for executor_id, cur_data in cur_read.items():
stats = cur_data['statistics']
cpus_limit = stats.get('cpus_limit')
cpus_utilisation = stats.get('cpus_utilisatio... | [
"def",
"_add_cpu_percent",
"(",
"self",
",",
"cur_read",
")",
":",
"for",
"executor_id",
",",
"cur_data",
"in",
"cur_read",
".",
"items",
"(",
")",
":",
"stats",
"=",
"cur_data",
"[",
"'statistics'",
"]",
"cpus_limit",
"=",
"stats",
".",
"get",
"(",
"'cp... | Compute cpu percent basing on the provided utilisation | [
"Compute",
"cpu",
"percent",
"basing",
"on",
"the",
"provided",
"utilisation"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mesos/mesos.py#L121-L129 | train |
python-diamond/Diamond | src/collectors/mesos/mesos.py | MesosCollector._add_mem_percent | def _add_mem_percent(self, cur_read):
"""Compute memory percent utilisation based on the
mem_rss_bytes and mem_limit_bytes
"""
for executor_id, cur_data in cur_read.items():
stats = cur_data['statistics']
mem_rss_bytes = stats.get('mem_rss_bytes')
mem_... | python | def _add_mem_percent(self, cur_read):
"""Compute memory percent utilisation based on the
mem_rss_bytes and mem_limit_bytes
"""
for executor_id, cur_data in cur_read.items():
stats = cur_data['statistics']
mem_rss_bytes = stats.get('mem_rss_bytes')
mem_... | [
"def",
"_add_mem_percent",
"(",
"self",
",",
"cur_read",
")",
":",
"for",
"executor_id",
",",
"cur_data",
"in",
"cur_read",
".",
"items",
"(",
")",
":",
"stats",
"=",
"cur_data",
"[",
"'statistics'",
"]",
"mem_rss_bytes",
"=",
"stats",
".",
"get",
"(",
"... | Compute memory percent utilisation based on the
mem_rss_bytes and mem_limit_bytes | [
"Compute",
"memory",
"percent",
"utilisation",
"based",
"on",
"the",
"mem_rss_bytes",
"and",
"mem_limit_bytes"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mesos/mesos.py#L131-L140 | train |
python-diamond/Diamond | src/collectors/mesos/mesos.py | MesosCollector._group_and_publish_tasks_statistics | def _group_and_publish_tasks_statistics(self, result):
"""This function group statistics of same tasks by adding them.
It also add 'instances_count' statistic to get information about
how many instances is running on the server
Args:
result: result of mesos query. List of di... | python | def _group_and_publish_tasks_statistics(self, result):
"""This function group statistics of same tasks by adding them.
It also add 'instances_count' statistic to get information about
how many instances is running on the server
Args:
result: result of mesos query. List of di... | [
"def",
"_group_and_publish_tasks_statistics",
"(",
"self",
",",
"result",
")",
":",
"for",
"i",
"in",
"result",
":",
"executor_id",
"=",
"i",
"[",
"'executor_id'",
"]",
"i",
"[",
"'executor_id'",
"]",
"=",
"executor_id",
"[",
":",
"executor_id",
".",
"rfind"... | This function group statistics of same tasks by adding them.
It also add 'instances_count' statistic to get information about
how many instances is running on the server
Args:
result: result of mesos query. List of dictionaries with
'executor_id', 'framework_id' as a str... | [
"This",
"function",
"group",
"statistics",
"of",
"same",
"tasks",
"by",
"adding",
"them",
".",
"It",
"also",
"add",
"instances_count",
"statistic",
"to",
"get",
"information",
"about",
"how",
"many",
"instances",
"is",
"running",
"on",
"the",
"server"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mesos/mesos.py#L142-L169 | train |
python-diamond/Diamond | src/collectors/mesos/mesos.py | MesosCollector._get | def _get(self, path):
"""
Execute a Mesos API call.
"""
url = self._get_url(path)
try:
response = urllib2.urlopen(url)
except Exception as err:
self.log.error("%s: %s", url, err)
return False
try:
doc = json.load(re... | python | def _get(self, path):
"""
Execute a Mesos API call.
"""
url = self._get_url(path)
try:
response = urllib2.urlopen(url)
except Exception as err:
self.log.error("%s: %s", url, err)
return False
try:
doc = json.load(re... | [
"def",
"_get",
"(",
"self",
",",
"path",
")",
":",
"url",
"=",
"self",
".",
"_get_url",
"(",
"path",
")",
"try",
":",
"response",
"=",
"urllib2",
".",
"urlopen",
"(",
"url",
")",
"except",
"Exception",
"as",
"err",
":",
"self",
".",
"log",
".",
"... | Execute a Mesos API call. | [
"Execute",
"a",
"Mesos",
"API",
"call",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/mesos/mesos.py#L194-L212 | train |
python-diamond/Diamond | src/collectors/postgres/postgres.py | PostgresqlCollector.get_default_config_help | def get_default_config_help(self):
"""
Return help text for collector
"""
config_help = super(PostgresqlCollector,
self).get_default_config_help()
config_help.update({
'host': 'Hostname',
'dbname': 'DB to connect to in order to ... | python | def get_default_config_help(self):
"""
Return help text for collector
"""
config_help = super(PostgresqlCollector,
self).get_default_config_help()
config_help.update({
'host': 'Hostname',
'dbname': 'DB to connect to in order to ... | [
"def",
"get_default_config_help",
"(",
"self",
")",
":",
"config_help",
"=",
"super",
"(",
"PostgresqlCollector",
",",
"self",
")",
".",
"get_default_config_help",
"(",
")",
"config_help",
".",
"update",
"(",
"{",
"'host'",
":",
"'Hostname'",
",",
"'dbname'",
... | Return help text for collector | [
"Return",
"help",
"text",
"for",
"collector"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/postgres/postgres.py#L27-L50 | train |
python-diamond/Diamond | src/collectors/postgres/postgres.py | PostgresqlCollector.collect | def collect(self):
"""
Do pre-flight checks, get list of db names, collect metrics, publish
"""
if psycopg2 is None:
self.log.error('Unable to import module psycopg2')
return {}
# Get list of databases
dbs = self._get_db_names()
if len(dbs... | python | def collect(self):
"""
Do pre-flight checks, get list of db names, collect metrics, publish
"""
if psycopg2 is None:
self.log.error('Unable to import module psycopg2')
return {}
# Get list of databases
dbs = self._get_db_names()
if len(dbs... | [
"def",
"collect",
"(",
"self",
")",
":",
"if",
"psycopg2",
"is",
"None",
":",
"self",
".",
"log",
".",
"error",
"(",
"'Unable to import module psycopg2'",
")",
"return",
"{",
"}",
"# Get list of databases",
"dbs",
"=",
"self",
".",
"_get_db_names",
"(",
")",... | Do pre-flight checks, get list of db names, collect metrics, publish | [
"Do",
"pre",
"-",
"flight",
"checks",
"get",
"list",
"of",
"db",
"names",
"collect",
"metrics",
"publish"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/postgres/postgres.py#L74-L126 | train |
python-diamond/Diamond | src/collectors/postgres/postgres.py | PostgresqlCollector._get_db_names | def _get_db_names(self):
"""
Try to get a list of db names
"""
query = """
SELECT datname FROM pg_database
WHERE datallowconn AND NOT datistemplate
AND NOT datname='postgres' AND NOT datname='rdsadmin' ORDER BY 1
"""
conn = self._connec... | python | def _get_db_names(self):
"""
Try to get a list of db names
"""
query = """
SELECT datname FROM pg_database
WHERE datallowconn AND NOT datistemplate
AND NOT datname='postgres' AND NOT datname='rdsadmin' ORDER BY 1
"""
conn = self._connec... | [
"def",
"_get_db_names",
"(",
"self",
")",
":",
"query",
"=",
"\"\"\"\n SELECT datname FROM pg_database\n WHERE datallowconn AND NOT datistemplate\n AND NOT datname='postgres' AND NOT datname='rdsadmin' ORDER BY 1\n \"\"\"",
"conn",
"=",
"self",
".",
... | Try to get a list of db names | [
"Try",
"to",
"get",
"a",
"list",
"of",
"db",
"names"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/postgres/postgres.py#L128-L148 | train |
python-diamond/Diamond | src/collectors/postgres/postgres.py | PostgresqlCollector._connect | def _connect(self, database=None):
"""
Connect to given database
"""
conn_args = {
'host': self.config['host'],
'user': self.config['user'],
'password': self.config['password'],
'port': self.config['port'],
'sslmode': self.confi... | python | def _connect(self, database=None):
"""
Connect to given database
"""
conn_args = {
'host': self.config['host'],
'user': self.config['user'],
'password': self.config['password'],
'port': self.config['port'],
'sslmode': self.confi... | [
"def",
"_connect",
"(",
"self",
",",
"database",
"=",
"None",
")",
":",
"conn_args",
"=",
"{",
"'host'",
":",
"self",
".",
"config",
"[",
"'host'",
"]",
",",
"'user'",
":",
"self",
".",
"config",
"[",
"'user'",
"]",
",",
"'password'",
":",
"self",
... | Connect to given database | [
"Connect",
"to",
"given",
"database"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/postgres/postgres.py#L150-L179 | train |
python-diamond/Diamond | src/collectors/iodrivesnmp/iodrivesnmp.py | IODriveSNMPCollector.get_string_index_oid | def get_string_index_oid(self, s):
"""Turns a string into an oid format is length of name followed by
name chars in ascii"""
return (len(self.get_bytes(s)), ) + self.get_bytes(s) | python | def get_string_index_oid(self, s):
"""Turns a string into an oid format is length of name followed by
name chars in ascii"""
return (len(self.get_bytes(s)), ) + self.get_bytes(s) | [
"def",
"get_string_index_oid",
"(",
"self",
",",
"s",
")",
":",
"return",
"(",
"len",
"(",
"self",
".",
"get_bytes",
"(",
"s",
")",
")",
",",
")",
"+",
"self",
".",
"get_bytes",
"(",
"s",
")"
] | Turns a string into an oid format is length of name followed by
name chars in ascii | [
"Turns",
"a",
"string",
"into",
"an",
"oid",
"format",
"is",
"length",
"of",
"name",
"followed",
"by",
"name",
"chars",
"in",
"ascii"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/iodrivesnmp/iodrivesnmp.py#L89-L92 | train |
python-diamond/Diamond | src/collectors/iodrivesnmp/iodrivesnmp.py | IODriveSNMPCollector.collect_snmp | def collect_snmp(self, device, host, port, community):
"""
Collect Fusion IO Drive SNMP stats from device
host and device are from the conf file. In the future device should be
changed to be what IODRive device it being checked.
i.e. fioa, fiob.
"""
# Set timesta... | python | def collect_snmp(self, device, host, port, community):
"""
Collect Fusion IO Drive SNMP stats from device
host and device are from the conf file. In the future device should be
changed to be what IODRive device it being checked.
i.e. fioa, fiob.
"""
# Set timesta... | [
"def",
"collect_snmp",
"(",
"self",
",",
"device",
",",
"host",
",",
"port",
",",
"community",
")",
":",
"# Set timestamp",
"timestamp",
"=",
"time",
".",
"time",
"(",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"IODRIVE_STATS",
".",
"items",
"(",
... | Collect Fusion IO Drive SNMP stats from device
host and device are from the conf file. In the future device should be
changed to be what IODRive device it being checked.
i.e. fioa, fiob. | [
"Collect",
"Fusion",
"IO",
"Drive",
"SNMP",
"stats",
"from",
"device",
"host",
"and",
"device",
"are",
"from",
"the",
"conf",
"file",
".",
"In",
"the",
"future",
"device",
"should",
"be",
"changed",
"to",
"be",
"what",
"IODRive",
"device",
"it",
"being",
... | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/iodrivesnmp/iodrivesnmp.py#L98-L135 | train |
python-diamond/Diamond | src/diamond/handler/graphite.py | GraphiteHandler._send_data | def _send_data(self, data):
"""
Try to send all data in buffer.
"""
try:
self.socket.sendall(data)
self._reset_errors()
except:
self._close()
self._throttle_error("GraphiteHandler: Socket error, "
"t... | python | def _send_data(self, data):
"""
Try to send all data in buffer.
"""
try:
self.socket.sendall(data)
self._reset_errors()
except:
self._close()
self._throttle_error("GraphiteHandler: Socket error, "
"t... | [
"def",
"_send_data",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"self",
".",
"socket",
".",
"sendall",
"(",
"data",
")",
"self",
".",
"_reset_errors",
"(",
")",
"except",
":",
"self",
".",
"_close",
"(",
")",
"self",
".",
"_throttle_error",
"(",... | Try to send all data in buffer. | [
"Try",
"to",
"send",
"all",
"data",
"in",
"buffer",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/graphite.py#L126-L142 | train |
python-diamond/Diamond | src/diamond/handler/graphite.py | GraphiteHandler._send | def _send(self):
"""
Send data to graphite. Data that can not be sent will be queued.
"""
# Check to see if we have a valid socket. If not, try to connect.
try:
try:
if self.socket is None:
self.log.debug("GraphiteHandler: Socket is... | python | def _send(self):
"""
Send data to graphite. Data that can not be sent will be queued.
"""
# Check to see if we have a valid socket. If not, try to connect.
try:
try:
if self.socket is None:
self.log.debug("GraphiteHandler: Socket is... | [
"def",
"_send",
"(",
"self",
")",
":",
"# Check to see if we have a valid socket. If not, try to connect.",
"try",
":",
"try",
":",
"if",
"self",
".",
"socket",
"is",
"None",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"GraphiteHandler: Socket is not connected. \"",... | Send data to graphite. Data that can not be sent will be queued. | [
"Send",
"data",
"to",
"graphite",
".",
"Data",
"that",
"can",
"not",
"be",
"sent",
"will",
"be",
"queued",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/graphite.py#L151-L183 | train |
python-diamond/Diamond | src/diamond/handler/graphite.py | GraphiteHandler._connect | def _connect(self):
"""
Connect to the graphite server
"""
if (self.proto == 'udp'):
stream = socket.SOCK_DGRAM
else:
stream = socket.SOCK_STREAM
if (self.proto[-1] == '4'):
family = socket.AF_INET
connection_struct = (self... | python | def _connect(self):
"""
Connect to the graphite server
"""
if (self.proto == 'udp'):
stream = socket.SOCK_DGRAM
else:
stream = socket.SOCK_STREAM
if (self.proto[-1] == '4'):
family = socket.AF_INET
connection_struct = (self... | [
"def",
"_connect",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"proto",
"==",
"'udp'",
")",
":",
"stream",
"=",
"socket",
".",
"SOCK_DGRAM",
"else",
":",
"stream",
"=",
"socket",
".",
"SOCK_STREAM",
"if",
"(",
"self",
".",
"proto",
"[",
"-",
"1"... | Connect to the graphite server | [
"Connect",
"to",
"the",
"graphite",
"server"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/graphite.py#L185-L251 | train |
python-diamond/Diamond | src/diamond/handler/null.py | NullHandler.process | def process(self, metric):
"""
Process a metric by doing nothing
"""
self.log.debug("Metric: %s", str(metric).rstrip().replace(' ', '\t')) | python | def process(self, metric):
"""
Process a metric by doing nothing
"""
self.log.debug("Metric: %s", str(metric).rstrip().replace(' ', '\t')) | [
"def",
"process",
"(",
"self",
",",
"metric",
")",
":",
"self",
".",
"log",
".",
"debug",
"(",
"\"Metric: %s\"",
",",
"str",
"(",
"metric",
")",
".",
"rstrip",
"(",
")",
".",
"replace",
"(",
"' '",
",",
"'\\t'",
")",
")"
] | Process a metric by doing nothing | [
"Process",
"a",
"metric",
"by",
"doing",
"nothing"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/null.py#L15-L19 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.load_config | def load_config(self, configfile=None, override_config=None):
"""
Process a configfile, or reload if previously given one.
"""
self.config = configobj.ConfigObj()
# Load in the collector's defaults
if self.get_default_config() is not None:
self.config.merge(s... | python | def load_config(self, configfile=None, override_config=None):
"""
Process a configfile, or reload if previously given one.
"""
self.config = configobj.ConfigObj()
# Load in the collector's defaults
if self.get_default_config() is not None:
self.config.merge(s... | [
"def",
"load_config",
"(",
"self",
",",
"configfile",
"=",
"None",
",",
"override_config",
"=",
"None",
")",
":",
"self",
".",
"config",
"=",
"configobj",
".",
"ConfigObj",
"(",
")",
"# Load in the collector's defaults",
"if",
"self",
".",
"get_default_config",
... | Process a configfile, or reload if previously given one. | [
"Process",
"a",
"configfile",
"or",
"reload",
"if",
"previously",
"given",
"one",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L181-L212 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.process_config | def process_config(self):
"""
Intended to put any code that should be run after any config reload
event
"""
if 'byte_unit' in self.config:
if isinstance(self.config['byte_unit'], basestring):
self.config['byte_unit'] = self.config['byte_unit'].split()
... | python | def process_config(self):
"""
Intended to put any code that should be run after any config reload
event
"""
if 'byte_unit' in self.config:
if isinstance(self.config['byte_unit'], basestring):
self.config['byte_unit'] = self.config['byte_unit'].split()
... | [
"def",
"process_config",
"(",
"self",
")",
":",
"if",
"'byte_unit'",
"in",
"self",
".",
"config",
":",
"if",
"isinstance",
"(",
"self",
".",
"config",
"[",
"'byte_unit'",
"]",
",",
"basestring",
")",
":",
"self",
".",
"config",
"[",
"'byte_unit'",
"]",
... | Intended to put any code that should be run after any config reload
event | [
"Intended",
"to",
"put",
"any",
"code",
"that",
"should",
"be",
"run",
"after",
"any",
"config",
"reload",
"event"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L214-L242 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.get_metric_path | def get_metric_path(self, name, instance=None):
"""
Get metric path.
Instance indicates that this is a metric for a
virtual machine and should have a different
root prefix.
"""
if 'path' in self.config:
path = self.config['path']
else:
... | python | def get_metric_path(self, name, instance=None):
"""
Get metric path.
Instance indicates that this is a metric for a
virtual machine and should have a different
root prefix.
"""
if 'path' in self.config:
path = self.config['path']
else:
... | [
"def",
"get_metric_path",
"(",
"self",
",",
"name",
",",
"instance",
"=",
"None",
")",
":",
"if",
"'path'",
"in",
"self",
".",
"config",
":",
"path",
"=",
"self",
".",
"config",
"[",
"'path'",
"]",
"else",
":",
"path",
"=",
"self",
".",
"__class__",
... | Get metric path.
Instance indicates that this is a metric for a
virtual machine and should have a different
root prefix. | [
"Get",
"metric",
"path",
".",
"Instance",
"indicates",
"that",
"this",
"is",
"a",
"metric",
"for",
"a",
"virtual",
"machine",
"and",
"should",
"have",
"a",
"different",
"root",
"prefix",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L310-L362 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.publish | def publish(self, name, value, raw_value=None, precision=0,
metric_type='GAUGE', instance=None):
"""
Publish a metric with the given name
"""
# Check whitelist/blacklist
if self.config['metrics_whitelist']:
if not self.config['metrics_whitelist'].match... | python | def publish(self, name, value, raw_value=None, precision=0,
metric_type='GAUGE', instance=None):
"""
Publish a metric with the given name
"""
# Check whitelist/blacklist
if self.config['metrics_whitelist']:
if not self.config['metrics_whitelist'].match... | [
"def",
"publish",
"(",
"self",
",",
"name",
",",
"value",
",",
"raw_value",
"=",
"None",
",",
"precision",
"=",
"0",
",",
"metric_type",
"=",
"'GAUGE'",
",",
"instance",
"=",
"None",
")",
":",
"# Check whitelist/blacklist",
"if",
"self",
".",
"config",
"... | Publish a metric with the given name | [
"Publish",
"a",
"metric",
"with",
"the",
"given",
"name"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L373-L404 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.derivative | def derivative(self, name, new, max_value=0,
time_delta=True, interval=None,
allow_negative=False, instance=None):
"""
Calculate the derivative of the metric.
"""
# Format Metric Path
path = self.get_metric_path(name, instance=instance)
... | python | def derivative(self, name, new, max_value=0,
time_delta=True, interval=None,
allow_negative=False, instance=None):
"""
Calculate the derivative of the metric.
"""
# Format Metric Path
path = self.get_metric_path(name, instance=instance)
... | [
"def",
"derivative",
"(",
"self",
",",
"name",
",",
"new",
",",
"max_value",
"=",
"0",
",",
"time_delta",
"=",
"True",
",",
"interval",
"=",
"None",
",",
"allow_negative",
"=",
"False",
",",
"instance",
"=",
"None",
")",
":",
"# Format Metric Path",
"pat... | Calculate the derivative of the metric. | [
"Calculate",
"the",
"derivative",
"of",
"the",
"metric",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L430-L467 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector._run | def _run(self):
"""
Run the collector unless it's already running
"""
try:
start_time = time.time()
# Collect Data
self.collect()
end_time = time.time()
collector_time = int((end_time - start_time) * 1000)
self.lo... | python | def _run(self):
"""
Run the collector unless it's already running
"""
try:
start_time = time.time()
# Collect Data
self.collect()
end_time = time.time()
collector_time = int((end_time - start_time) * 1000)
self.lo... | [
"def",
"_run",
"(",
"self",
")",
":",
"try",
":",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"# Collect Data",
"self",
".",
"collect",
"(",
")",
"end_time",
"=",
"time",
".",
"time",
"(",
")",
"collector_time",
"=",
"int",
"(",
"(",
"end_time"... | Run the collector unless it's already running | [
"Run",
"the",
"collector",
"unless",
"it",
"s",
"already",
"running"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L469-L493 | train |
python-diamond/Diamond | src/diamond/collector.py | Collector.find_binary | def find_binary(self, binary):
"""
Scan and return the first path to a binary that we can find
"""
if os.path.exists(binary):
return binary
# Extract out the filename if we were given a full path
binary_name = os.path.basename(binary)
# Gather $PATH
... | python | def find_binary(self, binary):
"""
Scan and return the first path to a binary that we can find
"""
if os.path.exists(binary):
return binary
# Extract out the filename if we were given a full path
binary_name = os.path.basename(binary)
# Gather $PATH
... | [
"def",
"find_binary",
"(",
"self",
",",
"binary",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"binary",
")",
":",
"return",
"binary",
"# Extract out the filename if we were given a full path",
"binary_name",
"=",
"os",
".",
"path",
".",
"basename",
... | Scan and return the first path to a binary that we can find | [
"Scan",
"and",
"return",
"the",
"first",
"path",
"to",
"a",
"binary",
"that",
"we",
"can",
"find"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/collector.py#L495-L528 | train |
python-diamond/Diamond | src/collectors/memcached_slab/memcached_slab.py | parse_slab_stats | def parse_slab_stats(slab_stats):
"""Convert output from memcached's `stats slabs` into a Python dict.
Newlines are returned by memcached along with carriage returns
(i.e. '\r\n').
>>> parse_slab_stats(
"STAT 1:chunk_size 96\r\nSTAT 1:chunks_per_page 10922\r\nSTAT "
"active_sla... | python | def parse_slab_stats(slab_stats):
"""Convert output from memcached's `stats slabs` into a Python dict.
Newlines are returned by memcached along with carriage returns
(i.e. '\r\n').
>>> parse_slab_stats(
"STAT 1:chunk_size 96\r\nSTAT 1:chunks_per_page 10922\r\nSTAT "
"active_sla... | [
"def",
"parse_slab_stats",
"(",
"slab_stats",
")",
":",
"stats_dict",
"=",
"{",
"'slabs'",
":",
"defaultdict",
"(",
"lambda",
":",
"{",
"}",
")",
"}",
"for",
"line",
"in",
"slab_stats",
".",
"splitlines",
"(",
")",
":",
"if",
"line",
"==",
"'END'",
":"... | Convert output from memcached's `stats slabs` into a Python dict.
Newlines are returned by memcached along with carriage returns
(i.e. '\r\n').
>>> parse_slab_stats(
"STAT 1:chunk_size 96\r\nSTAT 1:chunks_per_page 10922\r\nSTAT "
"active_slabs 1\r\nSTAT total_malloced 1048512\r\nEN... | [
"Convert",
"output",
"from",
"memcached",
"s",
"stats",
"slabs",
"into",
"a",
"Python",
"dict",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memcached_slab/memcached_slab.py#L19-L56 | train |
python-diamond/Diamond | src/collectors/memcached_slab/memcached_slab.py | dict_to_paths | def dict_to_paths(dict_):
"""Convert a dict to metric paths.
>>> dict_to_paths({'foo': {'bar': 1}, 'baz': 2})
{
'foo.bar': 1,
'baz': 2,
}
"""
metrics = {}
for k, v in dict_.iteritems():
if isinstance(v, dict):
submetrics = dict_to_paths(v)
for... | python | def dict_to_paths(dict_):
"""Convert a dict to metric paths.
>>> dict_to_paths({'foo': {'bar': 1}, 'baz': 2})
{
'foo.bar': 1,
'baz': 2,
}
"""
metrics = {}
for k, v in dict_.iteritems():
if isinstance(v, dict):
submetrics = dict_to_paths(v)
for... | [
"def",
"dict_to_paths",
"(",
"dict_",
")",
":",
"metrics",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"dict_",
".",
"iteritems",
"(",
")",
":",
"if",
"isinstance",
"(",
"v",
",",
"dict",
")",
":",
"submetrics",
"=",
"dict_to_paths",
"(",
"v",
")",
... | Convert a dict to metric paths.
>>> dict_to_paths({'foo': {'bar': 1}, 'baz': 2})
{
'foo.bar': 1,
'baz': 2,
} | [
"Convert",
"a",
"dict",
"to",
"metric",
"paths",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memcached_slab/memcached_slab.py#L59-L76 | train |
python-diamond/Diamond | src/collectors/memcached_slab/memcached_slab.py | MemcachedSlabCollector.get_slab_stats | def get_slab_stats(self):
"""Retrieve slab stats from memcached."""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.host, self.port))
s.send("stats slabs\n")
try:
data = ""
while True:
data += s.recv(4096)
... | python | def get_slab_stats(self):
"""Retrieve slab stats from memcached."""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.host, self.port))
s.send("stats slabs\n")
try:
data = ""
while True:
data += s.recv(4096)
... | [
"def",
"get_slab_stats",
"(",
"self",
")",
":",
"s",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")",
"s",
".",
"connect",
"(",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
")",
")",
"s",
... | Retrieve slab stats from memcached. | [
"Retrieve",
"slab",
"stats",
"from",
"memcached",
"."
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/memcached_slab/memcached_slab.py#L99-L112 | train |
python-diamond/Diamond | src/collectors/netapp/netapp_inode.py | netapp_inodeCol.push | def push(self, metric_name=None, metric_value=None, volume=None):
""" Ship that shit off to graphite broski
"""
graphite_path = self.path_prefix
graphite_path += '.' + self.device + '.' + 'volume'
graphite_path += '.' + volume + '.' + metric_name
metric = Metric(graphit... | python | def push(self, metric_name=None, metric_value=None, volume=None):
""" Ship that shit off to graphite broski
"""
graphite_path = self.path_prefix
graphite_path += '.' + self.device + '.' + 'volume'
graphite_path += '.' + volume + '.' + metric_name
metric = Metric(graphit... | [
"def",
"push",
"(",
"self",
",",
"metric_name",
"=",
"None",
",",
"metric_value",
"=",
"None",
",",
"volume",
"=",
"None",
")",
":",
"graphite_path",
"=",
"self",
".",
"path_prefix",
"graphite_path",
"+=",
"'.'",
"+",
"self",
".",
"device",
"+",
"'.'",
... | Ship that shit off to graphite broski | [
"Ship",
"that",
"shit",
"off",
"to",
"graphite",
"broski"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/netapp/netapp_inode.py#L61-L72 | train |
python-diamond/Diamond | src/collectors/netapp/netapp_inode.py | netapp_inodeCol.get_netapp_data | def get_netapp_data(self):
""" Retrieve netapp volume information
returns ElementTree of netapp volume information
"""
netapp_data = self.server.invoke('volume-list-info')
if netapp_data.results_status() == 'failed':
self.log.error(
'While usin... | python | def get_netapp_data(self):
""" Retrieve netapp volume information
returns ElementTree of netapp volume information
"""
netapp_data = self.server.invoke('volume-list-info')
if netapp_data.results_status() == 'failed':
self.log.error(
'While usin... | [
"def",
"get_netapp_data",
"(",
"self",
")",
":",
"netapp_data",
"=",
"self",
".",
"server",
".",
"invoke",
"(",
"'volume-list-info'",
")",
"if",
"netapp_data",
".",
"results_status",
"(",
")",
"==",
"'failed'",
":",
"self",
".",
"log",
".",
"error",
"(",
... | Retrieve netapp volume information
returns ElementTree of netapp volume information | [
"Retrieve",
"netapp",
"volume",
"information"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/collectors/netapp/netapp_inode.py#L74-L91 | train |
python-diamond/Diamond | src/diamond/handler/sentry.py | BaseResult.verbose_message | def verbose_message(self):
"""return more complete message"""
if self.threshold is None:
return 'No threshold'
return '%.1f is %s than %.1f' % (self.value,
self.adjective,
self.threshold) | python | def verbose_message(self):
"""return more complete message"""
if self.threshold is None:
return 'No threshold'
return '%.1f is %s than %.1f' % (self.value,
self.adjective,
self.threshold) | [
"def",
"verbose_message",
"(",
"self",
")",
":",
"if",
"self",
".",
"threshold",
"is",
"None",
":",
"return",
"'No threshold'",
"return",
"'%.1f is %s than %.1f'",
"%",
"(",
"self",
".",
"value",
",",
"self",
".",
"adjective",
",",
"self",
".",
"threshold",
... | return more complete message | [
"return",
"more",
"complete",
"message"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/sentry.py#L77-L83 | train |
python-diamond/Diamond | src/diamond/handler/sentry.py | Rule.process | def process(self, metric, handler):
"""
process a single diamond metric
@type metric: diamond.metric.Metric
@param metric: metric to process
@type handler: diamond.handler.sentry.SentryHandler
@param handler: configured Sentry graphite handler
@rtype None
... | python | def process(self, metric, handler):
"""
process a single diamond metric
@type metric: diamond.metric.Metric
@param metric: metric to process
@type handler: diamond.handler.sentry.SentryHandler
@param handler: configured Sentry graphite handler
@rtype None
... | [
"def",
"process",
"(",
"self",
",",
"metric",
",",
"handler",
")",
":",
"match",
"=",
"self",
".",
"regexp",
".",
"match",
"(",
"metric",
".",
"path",
")",
"if",
"match",
":",
"minimum",
"=",
"Minimum",
"(",
"metric",
".",
"value",
",",
"self",
"."... | process a single diamond metric
@type metric: diamond.metric.Metric
@param metric: metric to process
@type handler: diamond.handler.sentry.SentryHandler
@param handler: configured Sentry graphite handler
@rtype None | [
"process",
"a",
"single",
"diamond",
"metric"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/sentry.py#L179-L220 | train |
python-diamond/Diamond | src/diamond/handler/sentry.py | SentryHandler.compile_rules | def compile_rules(self):
"""
Compile alert rules
@rtype list of Rules
"""
output = []
# validate configuration, skip invalid section
for key_name, section in self.config.items():
rule = self.compile_section(section)
if rule is not None:
... | python | def compile_rules(self):
"""
Compile alert rules
@rtype list of Rules
"""
output = []
# validate configuration, skip invalid section
for key_name, section in self.config.items():
rule = self.compile_section(section)
if rule is not None:
... | [
"def",
"compile_rules",
"(",
"self",
")",
":",
"output",
"=",
"[",
"]",
"# validate configuration, skip invalid section",
"for",
"key_name",
",",
"section",
"in",
"self",
".",
"config",
".",
"items",
"(",
")",
":",
"rule",
"=",
"self",
".",
"compile_section",
... | Compile alert rules
@rtype list of Rules | [
"Compile",
"alert",
"rules"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/sentry.py#L277-L288 | train |
python-diamond/Diamond | src/diamond/handler/sentry.py | SentryHandler.compile_section | def compile_section(self, section):
"""
Validate if a section is a valid rule
@type section: configobj.Section
@param section: section to validate
@rtype Rule or None
@return None if invalid
"""
if section.__class__ != Section:
# not a section,... | python | def compile_section(self, section):
"""
Validate if a section is a valid rule
@type section: configobj.Section
@param section: section to validate
@rtype Rule or None
@return None if invalid
"""
if section.__class__ != Section:
# not a section,... | [
"def",
"compile_section",
"(",
"self",
",",
"section",
")",
":",
"if",
"section",
".",
"__class__",
"!=",
"Section",
":",
"# not a section, just skip",
"return",
"# name and path are mandatory",
"keys",
"=",
"section",
".",
"keys",
"(",
")",
"for",
"key",
"in",
... | Validate if a section is a valid rule
@type section: configobj.Section
@param section: section to validate
@rtype Rule or None
@return None if invalid | [
"Validate",
"if",
"a",
"section",
"is",
"a",
"valid",
"rule"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/sentry.py#L290-L337 | train |
python-diamond/Diamond | src/diamond/handler/sentry.py | SentryHandler.configure_sentry_errors | def configure_sentry_errors(self):
"""
Configure sentry.errors to use the same loggers as the root handler
@rtype: None
"""
sentry_errors_logger = logging.getLogger('sentry.errors')
root_logger = logging.getLogger()
for handler in root_logger.handlers:
... | python | def configure_sentry_errors(self):
"""
Configure sentry.errors to use the same loggers as the root handler
@rtype: None
"""
sentry_errors_logger = logging.getLogger('sentry.errors')
root_logger = logging.getLogger()
for handler in root_logger.handlers:
... | [
"def",
"configure_sentry_errors",
"(",
"self",
")",
":",
"sentry_errors_logger",
"=",
"logging",
".",
"getLogger",
"(",
"'sentry.errors'",
")",
"root_logger",
"=",
"logging",
".",
"getLogger",
"(",
")",
"for",
"handler",
"in",
"root_logger",
".",
"handlers",
":"... | Configure sentry.errors to use the same loggers as the root handler
@rtype: None | [
"Configure",
"sentry",
".",
"errors",
"to",
"use",
"the",
"same",
"loggers",
"as",
"the",
"root",
"handler"
] | 0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47 | https://github.com/python-diamond/Diamond/blob/0f3eb04327d6d3ed5e53a9967d6c9d2c09714a47/src/diamond/handler/sentry.py#L339-L347 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.