def getLogPaths(readerConfig): """ Get paths """ logger.info('getLogPaths') connDbBase = db.connectDbOnlyRead(readerConfig.dbBasePath) cursor = connDbBase.cursor() cursor.execute(""" SELECT id, node1_id, node2_id FROM lmp_logPathsT """) rows = cursor.fetchall() #agrega una columna con el key+el id # rows2 = list(map(lambda row: row + ( (readerKey+'_'+str(row[0])), (readerKey+'_'+str(row[1])), (readerKey+'_'+str(row[2])) ), rows)) #elimina la primeras 2 columnas # rows3 = list(map(lambda row: row[3:], rows2)) data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'logPaths': rows } connDbBase.close() return data
def getLogEventsWithRemoteCall(readerConfig, start, end): """ Get event count """ logger.info('getLogEventsWithRemoteCall: ' + str(start) + " - " + str(end)) connDbEvents = db.connectDbOnlyRead(readerConfig.dbEventsPath) cursor = connDbEvents.cursor() cursor.execute( """ SELECT exectime, logNode_id, remoteCallKey, userKey FROM lmp_logEventsT WHERE remoteCallKey IS NOT NULL AND path_id IS NOT NULL AND exectime BETWEEN ? AND ? """, (start, end)) rows = cursor.fetchall() data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'logRecords': rows } cursor.close() connDbEvents.close() return data
def getMonitorTomcatMeasures(monitorConfig, start, end): """ Get paths """ logger.info('getMonitorTomcatMeasures: ' + str(start) + " - " + str(end)) connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() measures = [] while start < end: endLoop = start + datetime.timedelta(minutes=lmutil.PERIOD) cursor.execute( """ SELECT MAX(memused), MAX(threads), MAX(threadsBusy), MAX(workers), COUNT(fail) FROM lmp_monitor_tomcat_dataT WHERE exectime BETWEEN ? AND ? """, (start, endLoop)) measure = cursor.fetchone() if measure[0]: measures.append((str(start), ) + measure) start = endLoop connDbMonitor.close() return measures
def getMonitorHostMeasures(monitorConfig, start, end): """ Get paths """ logger.info('getMonitorHostMeasures: ' + str(start) + " - " + str(end)) connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() measures = [] while start < end: endLoop = start + datetime.timedelta(minutes=lmutil.PERIOD) cursor.execute( """ SELECT MAX(cpu), max(cpu_user), MAX(cpu_sys), MIN(cpu_idle), MAX(mem), MAX(swap), MAX(diskusage), MAX(pids), MAX(cnxs), MAX(users), MAX(disk_io_rate_w), MAX(disk_io_rate_r), MAX(net_io_rate_r), MAX(net_io_rate_s), MAX(openfiles), max(openfiles_rate), SUM(net_err_rate_in), SUM(net_err_rate_out), SUM(net_drop_rate_in), SUM(net_drop_rate_out) FROM lmp_monitor_host_dataT WHERE exectime BETWEEN ? AND ? """, (start, endLoop)) measure = cursor.fetchone() if measure[0]: measures.append((str(start), ) + measure) start = endLoop connDbMonitor.close() return measures
def getLogNodesByCategory(readerConfig, category): """ Get logNodes """ logger.info('getLogNodesByCategory:' + str(category)) connDbBase = db.connectDbOnlyRead(readerConfig.dbBasePath) cursor = connDbBase.cursor() cursor.execute( """ SELECT id, key, component, className, method, lineNumber, logLevel, text, category FROM lmp_logNodesT WHERE category = ? """, (category.value, )) rows = cursor.fetchall() #agrega una columna con el key+el id # rows2 = list(map(lambda row: row + ( (readerKey+'_'+str(row[0])), ), rows)) #elimina la primera columna # rows3 = list(map(lambda row: row[1:], rows2)) data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'logNodes': rows } connDbBase.close() return data
def getLogNodesByCategoryTrace(readerConfig): """ Get logNodes """ logger.info('getLogNodesByCategory') connDbBase = db.connectDbOnlyRead(readerConfig.dbBasePath) cursor = connDbBase.cursor() cat1 = cat.LogEventCategories.TRACE_MAIN_NODE cursor.execute( """ SELECT id, replace( key, '>>', '' ) as key, component, className, method, lineNumber, logLevel, replace( text, '>>', '' ) as text, category FROM lmp_logNodesT WHERE category = ? """, (cat1.value, )) rows = cursor.fetchall() data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'logItems': rows } connDbBase.close() return data
def getMonitorPostgresColnames(monitorConfig): """ Get paths """ logger.info('getMonitorPostgresColnames: ') connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() cursor.execute(""" SELECT MAX(conns), MAX(locks), COUNT(fail) FROM lmp_monitor_postgres_dataT LIMIT 1 """) colnames = formatColnames(list(map(lambda x: x[0], cursor.description)), 1) connDbMonitor.close() return colnames
def getMonitorTomcatColnames(monitorConfig): """ Get paths """ logger.info('getMonitorTomcatColnames:') connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() cursor.execute(""" SELECT MAX(memused), MAX(threads), MAX(threadsBusy), MAX(workers), COUNT(fail) FROM lmp_monitor_tomcat_dataT LIMIT 1 """) colnames = formatColnames(list(map(lambda x: x[0], cursor.description)), 1) connDbMonitor.close() return colnames
def getMonitorMicroserviceColnames(monitorConfig): """ Get paths """ logger.info('getMonitorMicroserviceColnames:') connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() cursor.execute(""" SELECT MAX(memused), MAX(heapused), MAX(nonheapused), MAX(threads), MAX(classes), MAX(sessions), MAX(dsconn), COUNT(fail) FROM lmp_monitor_microservice_dataT LIMIT 1 """) colnames = formatColnames(list(map(lambda x: x[0], cursor.description)), 1) connDbMonitor.close() return colnames
def getMonitorHostColnames(monitorConfig): """ Get paths """ logger.info('getMonitorHostColnames:') connDbMonitor = db.connectDbOnlyRead(monitorConfig.dbMonitorPath) cursor = connDbMonitor.cursor() cursor.execute(""" SELECT MAX(cpu), max(cpu_user), MAX(cpu_sys), MIN(cpu_idle), MAX(mem), MAX(swap), MAX(diskusage), MAX(pids), MAX(cnxs), MAX(users), MAX(disk_io_rate_w), MAX(disk_io_rate_r), MAX(net_io_rate_r), MAX(net_io_rate_s), MAX(openfiles), max(openfiles_rate), SUM(net_err_rate_in), SUM(net_err_rate_out), SUM(net_drop_rate_in), SUM(net_drop_rate_out) FROM lmp_monitor_host_dataT LIMIT 1 """) colnames = formatColnames(list(map(lambda x: x[0], cursor.description)), 1) connDbMonitor.close() return colnames
def getJsonLogMetrics(readerConfig, start, end): """ Get event count """ logger.info('getJsonLogMetrics: ' + str(start) + " - " + str(end)) connDbData = db.connectDbOnlyRead(readerConfig.dbDataPath) cursor = connDbData.cursor() cursor.execute("SELECT * from lmp_logmetricsT WHERE date BETWEEN ? AND ?", (start, end)) metrics = cursor.fetchall() connDbData.close() data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'datatype': lmkey.DATATYPE_LOG_METRICS, 'metrics': metrics } return data
def getJsonPathMeasures(readerConfig, start, end): """ Get paths measurements """ logger.info('getJsonPathMeasures: ' + str(start) + " - " + str(end)) connDbData = db.connectDbOnlyRead(readerConfig.dbDataPath) cursor = connDbData.cursor() cursor.execute( "SELECT * from lmp_paths_measuresT WHERE date BETWEEN ? AND ?", (start, end)) measures = cursor.fetchall() connDbData.close() data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'pathMeasures': measures } return data
def getJsonLogColnames(readerConfig): """ Get event count """ logger.info('getJsonLogColnames: ') connDbData = db.connectDbOnlyRead(readerConfig.dbDataPath) cursor = connDbData.cursor() cursor.execute("SELECT * from lmp_logmetricsT LIMIT 1") colnames = formatColnames(list(map(lambda x: x[0], cursor.description)), 0) colnames = colnames[2:] # drop colums 1 y 2: id and date connDbData.close() data = { 'readerKey': readerConfig.key, 'component': readerConfig.component, 'host': readerConfig.hostname, 'datatype': lmkey.DATATYPE_LOG_METRICS, 'colnames': colnames } return data