ok
Mini Shell
import agent_util
try:
# Python 2.x
import httplib
except:
import http.client as httplib
class CouchPlugin(agent_util.Plugin):
textkey = 'couch'
label = 'CouchDB'
description = 'Monitoring agent for CouchDB'
@classmethod
def get_metadata(self, config):
status = agent_util.SUPPORTED
msg = None
response = None
self.base_url = "/_stats"
if not config:
self.log.info("The [couch] config block is not found in the config file")
return {}
if "host" not in config or "port" not in config:
msg = "The host and port settings were not found in the [couch] block of the agent config file."
self.log.info(msg)
status = agent_util.MISCONFIGURED
if "base_url" in config:
self.base_url = config["base_url"]
if status == agent_util.SUPPORTED:
try:
couch_client = httplib.HTTPConnection(config['host'], config['port'])
couch_client.request('GET', '/')
response = couch_client.getresponse()
except Exception:
import sys
_, exception, _ = sys.exc_info()
status = agent_util.MISCONFIGURED
msg = "Unable to connect to CouchDB server to request metrics"
self.log.info('%s' % exception)
if response and response.status != 200:
status = agent_util.MISCONFIGURED
mgs = 'CouchDB Stats not found at %s:%s' % (config['host'], config['port'])
self.log.info(msg)
return {
'couchdb.database_writes': {
'label': 'Number of times a database was changed',
'options': None,
'status': status,
'error_message': msg,
'unit': 'times',
},
'couchdb.database_reads': {
'label': 'Number of times a document was read from a database',
'options': None,
'status': status,
'error_message': msg,
'unit': 'times',
},
'couchdb.open_databases': {
'label': 'Number of open databases',
'options': None,
'status': status,
'error_message': msg,
'unit': 'databases',
},
'couchdb.open_os_files': {
'label': 'Number of file descriptors CouchDB has open',
'options': None,
'status': status,
'error_message': msg,
'unit': 'files',
},
'couchdb.request_time': {
'label': 'Length of a request inside CouchDB without MochiWeb',
'options': None,
'status': status,
'error_message': msg,
'unit': 'ms',
},
'httpd.bulk_requests': {
'label': 'Number of bulk requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd.requests': {
'label': 'Number of HTTP requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd.temporary_view_reads': {
'label': 'Number of temporary view reads',
'options': None,
'status': status,
'error_message': msg,
'unit': 'reads',
},
'httpd.view_reads': {
'label': 'Number of view reads',
'options': None,
'status': status,
'error_message': msg,
'unit': 'reads',
},
'httpd_request_methods.COPY': {
'label': 'Number of HTTP COPY requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.DELETE': {
'label': 'Number of HTTP DELETE requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.GET': {
'label': 'Number of HTTP GET requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.HEAD': {
'label': 'Number of HTTP HEAD requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.MOVE': {
'label': 'Number of HTTP MOVE requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.POST': {
'label': 'Number of HTTP POST requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_request_methods.PUT': {
'label': 'Number of HTTP PUT requests',
'options': None,
'status': status,
'error_message': msg,
'unit': 'requests',
},
'httpd_status_codes.200': {
'label': 'Number of HTTP 200 OK responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.201': {
'label': 'Number of HTTP 201 Created responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.202': {
'label': 'Number of HTTP 202 Accepted responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.301': {
'label': 'Number of HTTP 301 Moved Permanently responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.304': {
'label': 'Number of HTTP 304 Not Modified responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.400': {
'label': 'Number of HTTP 400 Bad Request responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.401': {
'label': 'Number of HTTP 401 Unauthorized responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.403': {
'label': 'Number of HTTP 403 Forbidden responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.404': {
'label': 'Number of HTTP 404 Not Found responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.405': {
'label': 'Number of HTTP 405 Method Not Allowed responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.409': {
'label': 'Number of HTTP 409 Conflict responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.412': {
'label': 'Number of HTTP 412 Precondition Failed responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
'httpd_status_codes.500': {
'label': 'Number of HTTP 500 Internal Server Error responses',
'options': None,
'status': status,
'error_message': msg,
'unit': 'responses',
},
}
def check(self, textkey, data, config):
stat_area, stat_name = textkey.split('.')
url = '/'.join([self.base_url, stat_area, stat_name]) + '?range=60'
try:
couch_client = httplib.HTTPConnection(config["host"], config["port"])
couch_client.request('GET', url)
except Exception:
return None
response = couch_client.getresponse()
stat = agent_util.json_loads(response.read())
return stat[stat_area][stat_name]['current']
Zerion Mini Shell 1.0