Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from subprocess import Popen,PIPE
- from socket import gethostname
- USER="myuser"
- PASS="mypassword"
- DB="mydb"
- HOST="somehost"
- vsql = "/opt/vertica/bin/vsql -d %s -h %s -U %s -w %s -X -t -c " % (DB, HOST, USER, PASS)
- node = 'v_rpt_node0001'
- metrics = {
- 'active_user_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Active User Sessions',
- 'groups': 'vertica'
- },
- 'active_system_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Active System Sessions',
- 'groups': 'vertica'
- },
- 'total_user_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total User Sessions',
- 'groups': 'vertica'
- },
- 'total_system_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total System Sessions',
- 'groups': 'vertica'
- },
- 'total_active_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total Active Sessions',
- 'groups': 'vertica'
- },
- 'total_session_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total Sessions',
- 'groups': 'vertica'
- },
- 'running_query_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Running Queries',
- 'groups': 'vertica'
- },
- 'executed_query_count': {
- 'table': 'v_monitor.query_metrics',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Sessions',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Executed Queries',
- 'groups': 'vertica'
- },
- 'request_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': '',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Request Count',
- 'groups': 'vertica'
- },
- 'local_request_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Requests',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Local Request Count',
- 'groups': 'vertica'
- },
- 'request_queue_depth': {
- 'select': 'nvl(request_queue_depth, 0)',
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Requests',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Request Queue Depth',
- 'groups': 'vertica'
- },
- 'active_thread_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Threads',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Active Threads',
- 'groups': 'vertica'
- },
- 'open_file_handle_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'File Handles',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Open File Handles',
- 'groups': 'vertica'
- },
- 'memory_requested_kb': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'kb',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Memory Requested',
- 'groups': 'vertica'
- },
- 'address_space_requested_kb': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'kb',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Address Space Requested',
- 'groups': 'vertica'
- },
- 'wos_used_bytes': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'bytes',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'wos Used',
- 'groups': 'vertica'
- },
- 'wos_row_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Rows',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'wos Rows',
- 'groups': 'vertica'
- },
- 'ros_used_bytes': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'bytes',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'ros Used',
- 'groups': 'vertica'
- },
- 'ros_row_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Rows',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'row Rows',
- 'groups': 'vertica'
- },
- 'total_used_bytes': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'bytes',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total Used',
- 'groups': 'vertica'
- },
- 'total_row_count': {
- 'table': 'v_monitor.resource_usage',
- 'time_max': 60,
- 'value_type': 'uint32',
- 'units': 'Rows',
- 'slope': 'both',
- 'format': '%u',
- 'description': 'Total Rows',
- 'groups': 'vertica'
- }
- }
- class curry:
- def __init__(self, fun, *args, **kwargs):
- self.fun = fun
- self.pending = args[:]
- self.kwargs = kwargs.copy()
- def __call__(self, *args, **kwargs):
- if kwargs and self.kwargs:
- kw = self.kwargs.copy()
- kw.update(kwargs)
- else:
- kw = kwargs or self.kwargs
- return self.fun(*(self.pending + args), **kw)
- def get_metric(metric, name):
- select = metric[1].get('select', name)
- table = metric[1].get('table')
- sql = "select %s from %s where node_name = '%s'" % (select, table, node)
- sqlcmd = "%s \"%s\"" % (vsql, sql)
- res = Popen(sqlcmd, shell=True, stdout=PIPE).stdout.read()
- rows = clean_output(res)
- if rows[0][0] == '':
- return 0
- return int(rows[0][0])
- def clean_output(vsql_output):
- """
- takes output from vsql, parses it into column names and rows, returns a dict
- could use some extra checking for # rows returned, or non-standard output
- """
- lines = vsql_output.split("\n")
- #cols = []
- #for value in lines[0].split('|'):
- # cols.append(value.strip())
- rows = []
- for line in lines:
- values = []
- for value in line.split('|'):
- values.append(value.strip())
- rows.append(values)
- return rows
- def metric_init(params):
- global descriptors
- descriptors = []
- for metric in metrics.items():
- descriptor = {
- 'name': metric[0],
- 'call_back': curry(get_metric, metric),
- 'time_max': metric[1].get('time_max'),
- 'value_type': metric[1].get('value_type'),
- 'units': metric[1].get('units'),
- 'slope': metric[1].get('slope'),
- 'format': metric[1].get('format'),
- 'description': metric[1].get('description'),
- 'groups': metric[1].get('groups')
- }
- descriptors.append(descriptor)
- return descriptors
- def metric_cleanup():
- '''Clean up the metric module.'''
- pass
- if __name__ == '__main__':
- descriptors = metric_init(None)
- for d in descriptors:
- v = d['call_back'](d['name'])
- print 'value for %s is %u' % (d['name'], v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement