Skip to content

Commit

Permalink
Merged some Lint Errors into master (#414)
Browse files Browse the repository at this point in the history
* Fixed 3.x lint items

* formatted hadoop collectors
  • Loading branch information
johann8384 authored Dec 5, 2018
1 parent 40c3dda commit 5037dfb
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 251 deletions.
88 changes: 44 additions & 44 deletions collectors/0/hadoop_yarn_node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,72 @@
import os
import sys
import time

try:
import json
import json
except ImportError:
json = None
json = None
import argparse

SRCDIR = os.path.join(os.path.dirname(__file__))
LIBDIR = os.path.join(SRCDIR, '..', 'lib')
sys.path.append(LIBDIR)
# pylint: disable=wrong-import-position
from collectors.lib import utils
from collectors.lib.hadoop_http import HadoopHttp


REPLACEMENTS = {
}


class HadoopYarnNodeManager(HadoopHttp):
"""
Class that will retrieve metrics from an Apache Hadoop Yarn Node Manager JMX API
"""
Class that will retrieve metrics from an Apache Hadoop Yarn Node Manager JMX API
Tested on Apache Hadoop 2.7
"""
Tested on Apache Hadoop 2.7
"""

def __init__(self, host='localhost', port=8042):
super(HadoopYarnNodeManager, self).__init__('hadoop',
'yarn.node_manager',
host,
port)
def __init__(self, host='localhost', port=8042):
super(HadoopYarnNodeManager, self).__init__('hadoop',
'yarn.node_manager',
host,
port)

def emit(self):
current_time = int(time.time())
metrics = self.poll()
for context, metric_name, value in metrics:
for key, value in REPLACEMENTS.iteritems():
if any(_.startswith(key) for _ in context):
context = value
self.emit_metric(context, current_time, metric_name, value)
def emit(self):
current_time = int(time.time())
metrics = self.poll()
for context, metric_name, value in metrics:
for key, value in REPLACEMENTS.items():
if any(_.startswith(key) for _ in context):
context = value
self.emit_metric(context, current_time, metric_name, value)


# args are useful for testing but no given by TCollector so will inherit defaults normally
def main(args):
""" Calls HadoopYarnNodeManager at interval secs
and emits metrics to stdout for TCollector """
if json is None:
utils.err("This collector requires the `json' Python module.")
return 13 # Ask tcollector not to respawn us
utils.drop_privileges()
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', default='localhost',
help='Host to connect to (default: localhost)')
parser.add_argument('-P', '--port', default=8042, type=int,
help='Port to connect to (default: 8042)')
parser.add_argument('-i', '--interval', default=90, type=int,
help='Interval at which to emit metrics')
args = parser.parse_args(args[1:])
host = args.host
port = args.port
interval = args.interval
yarn_service = HadoopYarnNodeManager(host=host, port=port)
while True:
yarn_service.emit()
time.sleep(interval)
return 0
""" Calls HadoopYarnNodeManager at interval secs
and emits metrics to stdout for TCollector """
if json is None:
utils.err("This collector requires the `json' Python module.")
return 13 # Ask tcollector not to respawn us
utils.drop_privileges()
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', default='localhost',
help='Host to connect to (default: localhost)')
parser.add_argument('-P', '--port', default=8042, type=int,
help='Port to connect to (default: 8042)')
parser.add_argument('-i', '--interval', default=90, type=int,
help='Interval at which to emit metrics')
args = parser.parse_args(args[1:])
host = args.host
port = args.port
interval = args.interval
yarn_service = HadoopYarnNodeManager(host=host, port=port)
while True:
yarn_service.emit()
time.sleep(interval)
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv))

sys.exit(main(sys.argv))
88 changes: 44 additions & 44 deletions collectors/0/hadoop_yarn_resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,72 +21,72 @@
import os
import sys
import time

try:
import json
import json
except ImportError:
json = None
json = None
import argparse

SRCDIR = os.path.join(os.path.dirname(__file__))
LIBDIR = os.path.join(SRCDIR, '..', 'lib')
sys.path.append(LIBDIR)
# pylint: disable=wrong-import-position
from collectors.lib import utils
from collectors.lib.hadoop_http import HadoopHttp


REPLACEMENTS = {
}


class HadoopYarnResourceManager(HadoopHttp):
"""
Class that will retrieve metrics from an Apache Hadoop Yarn Resource Manager JMX API
"""
Class that will retrieve metrics from an Apache Hadoop Yarn Resource Manager JMX API
Tested on Apache Hadoop 2.7
"""
Tested on Apache Hadoop 2.7
"""

def __init__(self, host='localhost', port=8088):
super(HadoopYarnResourceManager, self).__init__('hadoop',
'yarn.resource_manager',
host,
port)
def __init__(self, host='localhost', port=8088):
super(HadoopYarnResourceManager, self).__init__('hadoop',
'yarn.resource_manager',
host,
port)

def emit(self):
current_time = int(time.time())
metrics = self.poll()
for context, metric_name, value in metrics:
for key, value in REPLACEMENTS.iteritems():
if any(_.startswith(key) for _ in context):
context = value
self.emit_metric(context, current_time, metric_name, value)
def emit(self):
current_time = int(time.time())
metrics = self.poll()
for context, metric_name, value in metrics:
for key, value in REPLACEMENTS.items():
if any(_.startswith(key) for _ in context):
context = value
self.emit_metric(context, current_time, metric_name, value)


# args are useful for testing but no given by TCollector so will inherit defaults normally
def main(args):
""" Calls HadoopYarnResourceManager at interval secs
and emits metrics to stdout for TCollector """
if json is None:
utils.err("This collector requires the `json' Python module.")
return 13 # Ask tcollector not to respawn us
utils.drop_privileges()
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', default='localhost',
help='Host to connect to (default: localhost)')
parser.add_argument('-P', '--port', default=8088, type=int,
help='Port to connect to (default: 8088)')
parser.add_argument('-i', '--interval', default=90, type=int,
help='Interval at which to emit metrics')
args = parser.parse_args(args[1:])
host = args.host
port = args.port
interval = args.interval
yarn_service = HadoopYarnResourceManager(host=host, port=port)
while True:
yarn_service.emit()
time.sleep(interval)
return 0
""" Calls HadoopYarnResourceManager at interval secs
and emits metrics to stdout for TCollector """
if json is None:
utils.err("This collector requires the `json' Python module.")
return 13 # Ask tcollector not to respawn us
utils.drop_privileges()
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', default='localhost',
help='Host to connect to (default: localhost)')
parser.add_argument('-P', '--port', default=8088, type=int,
help='Port to connect to (default: 8088)')
parser.add_argument('-i', '--interval', default=90, type=int,
help='Interval at which to emit metrics')
args = parser.parse_args(args[1:])
host = args.host
port = args.port
interval = args.interval
yarn_service = HadoopYarnResourceManager(host=host, port=port)
while True:
yarn_service.emit()
time.sleep(interval)
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv))

sys.exit(main(sys.argv))
Loading

0 comments on commit 5037dfb

Please sign in to comment.