Merge "Remove url from http_status metric value_meta"
This commit is contained in:
commit
499c63bca7
|
@ -1,5 +1,5 @@
|
|||
#!/bin/env python
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
|
||||
"""Monitoring Agent plugin for HTTP/API checks.
|
||||
|
||||
"""
|
||||
|
@ -26,7 +26,7 @@ class HTTPCheck(services_checks.ServicesCheck):
|
|||
self._response_not_ready = set()
|
||||
self._general_exception = set()
|
||||
self._invalid_token = set()
|
||||
self._warning_msg = set()
|
||||
self._warn_msg = set()
|
||||
|
||||
super(HTTPCheck, self).__init__(name, init_config, agent_config,
|
||||
instances)
|
||||
|
@ -86,10 +86,10 @@ class HTTPCheck(services_checks.ServicesCheck):
|
|||
headers["X-Auth-Token"] = token
|
||||
headers["Content-type"] = "application/json"
|
||||
else:
|
||||
warning_string = """Unable to get token. Keystone API
|
||||
server may be down. Skipping check for {0}""".format(addr)
|
||||
self.log.warning(warning_string)
|
||||
return False, warning_string
|
||||
error_msg = "Unable to get token. Keystone API server may be down."
|
||||
warn_string = '{0} Skipping check for {1}'.format(error_msg, addr)
|
||||
self.log.warning(warn_string)
|
||||
return False, error_msg
|
||||
try:
|
||||
self.log.debug("Connecting to %s" % addr)
|
||||
if disable_ssl_validation:
|
||||
|
@ -101,30 +101,32 @@ class HTTPCheck(services_checks.ServicesCheck):
|
|||
|
||||
except (socket.timeout, HttpLib2Error, socket.error) as e:
|
||||
length = int((time.time() - start) * 1000)
|
||||
warn_string = '{0} is DOWN, error: {1}. Connection failed' \
|
||||
'after {2} ms'.format(addr, repr(e), length)
|
||||
error_msg = 'error: {0}. Connection failed after {1} ' \
|
||||
'ms'.format(repr(e), length)
|
||||
if addr not in self._socket_errors:
|
||||
self._socket_errors.add(addr)
|
||||
warn_string = '{0} is DOWN, {1}'.format(addr, error_msg)
|
||||
self.log.warn(warn_string)
|
||||
return False, warn_string
|
||||
return False, error_msg
|
||||
|
||||
except httplib.ResponseNotReady as e:
|
||||
length = int((time.time() - start) * 1000)
|
||||
warn_string = '{0} is DOWN, error: {1}. Network is not ' \
|
||||
'routable after {2} ms'.format(addr, repr(e),
|
||||
length)
|
||||
error_msg = 'error: {0}. Network is not routable after {1} ' \
|
||||
'ms'.format(repr(e), length)
|
||||
if addr not in self._response_not_ready:
|
||||
self._response_not_ready.add(addr)
|
||||
warn_string = '{0} is DOWN, {1}'.format(addr, error_msg)
|
||||
self.log.warn(warn_string)
|
||||
return False, warn_string
|
||||
return False, error_msg
|
||||
|
||||
except Exception as e:
|
||||
length = int((time.time() - start) * 1000)
|
||||
error_string = '{0} is DOWN, error: {1}. Connection failed after {2} ms'.format(addr, repr(e), length)
|
||||
error_msg = 'error: {0}. Connection failed after {1} ms'.format(repr(e), length)
|
||||
if addr not in self._general_exception:
|
||||
self._general_exception.add(addr)
|
||||
error_string = '{0} is DOWN, {1}'.format(addr, error_msg)
|
||||
self.log.error(error_string)
|
||||
return False, error_string
|
||||
return False, error_msg
|
||||
|
||||
if response_time:
|
||||
# Stop the timer as early as possible
|
||||
|
@ -134,11 +136,12 @@ class HTTPCheck(services_checks.ServicesCheck):
|
|||
if int(resp.status) >= 400:
|
||||
if use_keystone and int(resp.status) == 401:
|
||||
if retry:
|
||||
error_string = '{0} is DOWN, unable to get a valid token to connect with'.format(addr)
|
||||
error_msg = 'unable to get a valid token to connect with'
|
||||
if addr not in self._invalid_token:
|
||||
self._invalid_token.add(addr)
|
||||
error_string = '{0} is DOWN, {1}'.format(addr, error_msg)
|
||||
self.log.error(error_string)
|
||||
return False, error_string
|
||||
return False, error_msg
|
||||
else:
|
||||
# Get a new token and retry
|
||||
self.log.info("Token expired, getting new token and retrying...")
|
||||
|
@ -146,18 +149,18 @@ class HTTPCheck(services_checks.ServicesCheck):
|
|||
ksclient.refresh_token()
|
||||
continue
|
||||
else:
|
||||
warn_string = '{0} is DOWN, error code: {1}'.\
|
||||
format(addr, str(resp.status))
|
||||
if addr not in self._warning_msg:
|
||||
self._warning_msg.add(addr)
|
||||
warn_msg = 'error code: {0}'.format(str(resp.status))
|
||||
if addr not in self._warn_msg:
|
||||
self._warn_msg.add(addr)
|
||||
warn_string = '{0} is DOWN, {1}'.format(addr, warn_msg)
|
||||
self.log.warn(warn_string)
|
||||
return False, warn_string
|
||||
return False, warn_msg
|
||||
|
||||
self._socket_errors.discard(addr)
|
||||
self._invalid_token.discard(addr)
|
||||
self._response_not_ready.discard(addr)
|
||||
self._general_exception.discard(addr)
|
||||
self._warning_msg.discard(addr)
|
||||
self._warn_msg.discard(addr)
|
||||
|
||||
done = True
|
||||
return True, content
|
||||
|
|
Loading…
Reference in New Issue