def get_tnx_age(self, state): """ Get max age of transactions in given state. Supported states are: 'running', 'idle_tnx', 'prepared' """ v = self._get_version() if v >= (9, 2, 0): vtag = 'post92' else: vtag = 'pre92' if state == 'prepared': q = pgq.TNX_AGE_PREPARED else: q = pgq.CHECK_INSUFF_PRIV[vtag] insuff_priv = self.dbconn.query(q) if insuff_priv: raise CheckFail( "Insufficient privileges to read queries from pg_stat_activity" ) try: q = pgq.TNX_AGE[vtag][state] except KeyError: raise CheckFail("Unknown transaction state requested") # the query always returns something becuase of COALESCE(..., 0), # even if there's no transactions in given state ret = self.dbconn.query(q)[0][0] return abs(ret)
def get_status(self, metric): """ get php-fpm status metric """ metric = metric.replace('_', ' ') page = self.get_status_page() if not page: raise CheckFail("unable to get status page") if page.has_key(metric): return page[metric] # no such metric found raise CheckFail("no such metric found")
def _get(self, metric=None, *args, **kwargs): """ get metric """ if metric == 'num': status = args[0] return self.get_status_num(status) else: CheckFail('uncknown metric %s' % metric)
def _get(self, metric, *arg): """ Return requested metric """ if metric == 'ping': url = arg[0] return self.get_ping(url) else: raise CheckFail("unknown metric: %s" % metric)
def _get(self, metric, *args): if metric == 'ping': return self.get_ping() elif metric == 'operations': m = args[0] return self.get_operations(m) elif metric == 'connections': m = args[0] return self.get_connections(m) elif metric == 'globallock': m = args[0] return self.get_globallock(m) elif metric == 'globallock_currentqueue': m = args[0] return self.get_globallock_currentqueue(m) elif metric == 'globallock_activeclients': m = args[0] return self.get_globallock_activeclients(m) elif metric == 'bgflushing': m = args[0] return self.get_bgflushing(m) elif metric == 'mem': m = args[0] return self.get_mem(m) elif metric == 'dbstats': # per-db metrics m = args[0] db = args[1] return self.get_dbstats(db, m) elif metric == 'page_faults': return self.get_page_faults() else: raise CheckFail("uncknown metric: %s" % metric)
def _get(self, metric, *args, **kwargs): if metric == 'ping': return self._get_ping() elif metric == 'status': try: return self._get_status(args[0]) except IndexError: raise CheckFail("not enough arguments - pass global status " "metric name as 2nd arg")
def _get(self, metric=None, *args, **kwargs): """ get metric """ allowed_metrics = ('accepts', 'handled', 'requests', 'connections_active', 'connections_reading', 'connections_waiting', 'connections_writing', 'ping', '2xx', '3xx', '4xx', '5xx') if metric in allowed_metrics: return self.__getattribute__('get_' + metric)() else: raise CheckFail("Requested not allowed metric")
def get_setting(self, parameter): """ Get arbitrary postgresql user configurable parameter """ q = pgq.GET_SETTING % (parameter) res = self.dbconn.query(q) if res: return res[0][0] raise CheckFail( "The requested parameter %s does not exist in pg_settings" % parameter)
def _get_status(self, metric): if not self._connect(): self.logger.error("get_status: could not connect to mysql") # pylint: disable=E0702 raise self.lasterr r = self.query('SHOW GLOBAL STATUS LIKE "%s"' % (self.escape(metric))) if r: return r[0][1] else: raise CheckFail('uncknown global status metric: %s' % (metric))
def _get(self, metric=None, *args, **kwargs): """ get some metric """ if metric == 'avg': return self.get_avg() elif metric == 'min': return self.get_min() elif metric == 'max': return self.get_max() else: raise CheckFail("Uncknown metric: %s" % (metric, ))
def _get(self, metric, *args, **kwargs): if metric == 'query': q = args[0] return self.dbconn.query(q) elif metric == 'autovac_freeze': return self.get_autovac_freeze() elif metric == 'ping': return self.get_ping() elif metric == 'tnxage': state = args[0] return self.get_tnx_age(state) elif metric == 'buffers': buf_metric = args[0] return self.get_buffers(buf_metric) elif metric == 'conn': state = args[0] return self.get_conn_nr(state) elif metric == 'dbstat': m = args[0] return self.get_dbstat(m) elif metric == 'fsm': m = args[0] return self.get_fsm(m) elif metric == 'locks': m = args[0] mm = args[1] return self.get_locks(m, mm) elif metric == 'bgwriter': bgw_metric = args[0] return self.get_bgwriter(bgw_metric) elif metric == 'settings': param = args[0] return self.get_setting(param) elif metric == 'wal': m = args[0] if m == 'num': return self.get_wal_num() else: CheckFail('uncknown wal metric: %s' % m) else: raise CheckFail('uncknown metric %s' % metric)
def _get(self, metric, *arg, **kwarg): if metric == 'ping': return self.ping elif metric == 'status': m = arg[0] return self.get_status(m) elif metric == 'error': return self.get_err_count() elif metric == 'slow': return self.get_slow_count() else: raise CheckFail("uncknown metric")
def get_prop(self, mbean_name, attribute_name): """ get custom JMX bean property """ # escape spaces in mbean_name mbean_name = mbean_name.replace(' ', '\ ') popen_cmd = "java -Djava.endorsed.dirs=/opt/ztc/lib/ -jar " + \ "/opt/ztc/lib/jmxterm-1.0-alpha-4-uber.jar -l %s -e -n " + \ "-v silent" % (self.jmx_url,) jmxterm_cmd = "get -b %s %s -s" % (mbean_name, attribute_name) self.logger.debug("Executing jmxterm command %s" % jmxterm_cmd) self.logger.debug("Jmxterm executable: %s" % popen_cmd) try: code, ret = popen(popen_cmd, self.logger, jmxterm_cmd) except IOError: self.logger.exception("Failed to run popen") raise CheckFail("jmxterm call failed") if code != 0: self.logger.error('jmxterm returned non-zero status') raise CheckFail('unable to get jmx propery %s %s' % (mbean_name, attribute_name)) return ret.strip()
def _get(self, metric=None, *args, **kwargs): """ get some metric """ allowed_metrics = ('ping', 'accesses', 'bytes', 'workers_busy', 'workers_closingconn', 'workers_dns', 'workers_finishing', 'workers_idle', 'workers_idlecleanup', 'workers_keepalive', 'workers_logging', 'workers_openslot', 'workers_reading', 'workers_starting', 'workers_writing') if metric in allowed_metrics: return self.__getattribute__('get_' + metric)() else: raise CheckFail("Requested not allowed metric")
def get_conn_nr(self, state): """ Get number of connections in given state """ v = self._get_version() if v >= (9, 2, 0): vtag = 'post92' else: vtag = 'pre92' # we don't need to be able to read queries to get total and max if state != 'total': q = pgq.CHECK_INSUFF_PRIV[vtag] insuff_priv = self.dbconn.query(q) if insuff_priv: raise CheckFail( "Insufficient privileges to read queries from pg_stat_activity" ) try: q = pgq.CONN_NUMBER[vtag][state] except KeyError: raise CheckFail("Unknown connection state requested") ret = self.dbconn.query(q)[0][0] return ret
def _get(self, metric, *args, **kwargs): #print args device = args[0] dev_type = 'auto' if len(args) > 1: dev_type = args[1] if metric == 'health': return self.get_health(device, dev_type) else: #ds = DiskStats() p = DiskStatsParser(device, self.logger) ds = p.parse() return ds.__getattribute__(metric) raise CheckFail('uncknown metric')
def get_heap(self, metric): """ get terracotta heap memory metrics """ st = ZTCStore('java.terracotta.heap', self.options) st.ttl = 60 data = st.get() if not data: # no cache, get from jmx data = self.get_prop('java.lang:type=Memory', 'HeapMemoryUsage') st.set(data) rt = self.extract_val_from_dict(data, metric) if rt is None: raise CheckFail('no such memory mertic') else: return rt
def _get(self, metric, *args, **kwargs): """ get metric - overrides _get from ZTCCheck """ if metric == 'get_prop': # get jmx property return self.get_prop(*args) elif metric == 'ds': # get datasource info ds = args[0] metric = args[1] return self.get_ds_info(ds, metric) elif metric == 'heap': # get java heap memory info return self.get_heap(args[0]) else: raise CheckFail('unsupported metric')
def _get(self, metric, *args, **kwargs): if metric == 'get_prop': # get jmx property return self.get_prop(*args) elif metric == 'heap': # get java heap memory info # supported metric under heap: commited, init, max, used return self.get_heap(args[0]) elif metric == 'codecache': # get java Code Cache memory info # supported sub-metrics: commited, max, init, used # candidate for moving to jmx class return self.get_codecache(args[0]) else: raise CheckFail('unsupported metric')
def get_codecache(self, metric): """ get java codecache memory (non-heap) metrics """ self.logger.debug('in get_codecache') st = ZTCStore('java.terracotta.codecache', self.options) st.ttl = 60 data = st.get() if not data: # no cache, get from jmx data = self.get_prop('java.lang:name=Code Cache,type=MemoryPool', 'Usage') st.set(data) rt = self.extract_val_from_dict(data, metric) if rt is None: raise CheckFail('no such memory mertic') else: return rt
def _get(self, metric, *arg, **kwarg): if metric == 'status': return self.get_status() else: raise CheckFail('uncknown metric')
def _get(self, metric=None, *args, **kwargs): if metric == 'mounted': return self.get_mounted() else: CheckFail("Uncknown metric: %s" % metric)
def _get(self, metric, *args, **kwargs): if metric == 'get_prop': # get jmx property return self.get_prop(*args) else: raise CheckFail('unsupported metric')