Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support collect Hadoop that turning on https #459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collectors/0/hadoop_datanode.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HadoopDataNode(HadoopHttp):
"""

def __init__(self):
super(HadoopDataNode, self).__init__('hadoop', 'datanode', 'localhost', 50075)
super(HadoopDataNode, self).__init__('hadoop', 'datanode', 'localhost', 50075, https_port=50475)

def emit(self):
current_time = int(time.time())
Expand Down
2 changes: 1 addition & 1 deletion collectors/0/hadoop_namenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HadoopNameNode(HadoopHttp):
"""

def __init__(self):
super(HadoopNameNode, self).__init__('hadoop', 'namenode', 'localhost', 50070)
super(HadoopNameNode, self).__init__('hadoop', 'namenode', 'localhost', 50070, https_port=50470)

def emit(self):
current_time = int(time.time())
Expand Down
23 changes: 20 additions & 3 deletions collectors/lib/hadoop_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# of the GNU Lesser General Public License along with this program. If not,
# see <http://www.gnu.org/licenses/>.

import ssl
import sys

try:
Expand All @@ -26,10 +27,10 @@

try:
# noinspection PyCompatibility
from http.client import HTTPConnection
from http.client import HTTPConnection, HTTPSConnection
except ImportError:
# noinspection PyUnresolvedReferences,PyCompatibility
from httplib import HTTPConnection
from httplib import HTTPConnection, HTTPSConnection


EXCLUDED_KEYS = (
Expand All @@ -52,21 +53,37 @@ def recurse(key,value):
yield (key,value)

class HadoopHttp(object):
def __init__(self, service, daemon, host, port, uri="/jmx"):
def __init__(self, service, daemon, host, port, https_port=None, uri="/jmx"):
self.service = service
self.daemon = daemon
self.port = port
self.https_port = https_port
self.host = host
self.uri = uri
self.server = HTTPConnection(self.host, self.port)
self.server.auto_open = True
if self.https_port:
self.https_server = HTTPSConnection(
self.host,
self.https_port,
context=ssl._create_unverified_context(),
timeout=10)
self.https_server.auto_open = True

def request(self):
try:
self.server.request('GET', self.uri)
resp = self.server.getresponse().read()
except:
resp = '{}'
if self.https_port:
try:
self.https_server.request('GET', self.uri)
resp = self.https_server.getresponse().read()
except:
resp = '{}'
finally:
self.https_server.close()
finally:
self.server.close()
return json.loads(resp)
Expand Down