From ab6c126af0988e786ae986bd3692850ab47f07b8 Mon Sep 17 00:00:00 2001 From: Bikram Debnath <76914472+debnathbikram@users.noreply.github.com> Date: Tue, 14 May 2024 13:36:08 +0530 Subject: [PATCH] InformixDB: Onstat support for couple of item and Minor refactoring (#31) * InformixDB: Onstat support for couple of item and Minor refactoring * InformixDB: Minor refactoring --- rdb/config/config-informix.yaml | 12 ++-- rdb/scripts/informix/active_session_count.sh | 13 ++++ rdb/scripts/informix/session_count.sh | 2 +- rdb/scripts/informix/task_wait_count.sh | 13 ++++ .../com/instana/dc/rdb/impl/Constants.java | 3 + .../dc/rdb/impl/informix/InformixDc.java | 64 ++++++++++--------- .../dc/rdb/impl/informix/InformixUtil.java | 48 +++++++------- .../collection/strategy/MetricsCollector.java | 8 ++- 8 files changed, 104 insertions(+), 59 deletions(-) create mode 100644 rdb/scripts/informix/active_session_count.sh create mode 100644 rdb/scripts/informix/task_wait_count.sh diff --git a/rdb/config/config-informix.yaml b/rdb/config/config-informix.yaml index ea202f0..2255fbb 100644 --- a/rdb/config/config-informix.yaml +++ b/rdb/config/config-informix.yaml @@ -16,13 +16,15 @@ instances: #Data collector properties: #Either use `poll.interval` or `custom.poll.interval` poll.interval: 30 + #All three category value is Mandatory if leveraging Custom Poll Rate custom.poll.interval: - high: 10 #polling_value_in_sec - medium: 120 #polling_value_in_sec - low: 300 #polling_value_in_sec + high: 300 #polling_value_in_sec + medium: 45 #polling_value_in_sec + low: 20 #polling_value_in_sec callback.interval: 20 otel.backend.url: http://127.0.0.1:4317 + #Custom Input custom.input: - db.names: 'testDb1, testDb2, testDb3' # Provide the DB Names in Comma separated way - + #Time Frame for which you want to get the expensive query. Default value 900 Sec + db.sql.elapsed.timeframe: 900 # Values should be in Seconds \ No newline at end of file diff --git a/rdb/scripts/informix/active_session_count.sh b/rdb/scripts/informix/active_session_count.sh new file mode 100644 index 0000000..6327aa8 --- /dev/null +++ b/rdb/scripts/informix/active_session_count.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# (c) Copyright IBM Corp. 2024 +# (c) Copyright Instana Inc. + +result=$(cd $1 && + export INFORMIXDIR=$2 && + export ONCONFIG=$3 && + export INFO RMIXSERVER=$4 && + export PATH=$INFORMIXDIR/bin:$PATH && + export INFORMIXSQLHOSTS=$INFORMIXDIR/etc/$5 && + ./onstat -g ses active | awk 'BEGIN {RS=""; FS="\n"} NR==2 {linecount = NF -2; if (linecount>0) print linecount; else print 0}') + +echo $result \ No newline at end of file diff --git a/rdb/scripts/informix/session_count.sh b/rdb/scripts/informix/session_count.sh index 6cb148d..ee196e8 100644 --- a/rdb/scripts/informix/session_count.sh +++ b/rdb/scripts/informix/session_count.sh @@ -8,6 +8,6 @@ result=$(cd $1 && export INFO RMIXSERVER=$4 && export PATH=$INFORMIXDIR/bin:$PATH && export INFORMIXSQLHOSTS=$INFORMIXDIR/etc/$5 && - ./onstat -g ses | tail -n +7 | head -n -1 | wc -l) + ./onstat -g ses | awk 'BEGIN {RS=""; FS="\n"} NR==2 {linecount = NF -2; if (linecount>0) print linecount; else print 0}') echo $result diff --git a/rdb/scripts/informix/task_wait_count.sh b/rdb/scripts/informix/task_wait_count.sh new file mode 100644 index 0000000..ba64003 --- /dev/null +++ b/rdb/scripts/informix/task_wait_count.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# (c) Copyright IBM Corp. 2024 +# (c) Copyright Instana Inc. + +result=$(cd $1 && + export INFORMIXDIR=$2 && + export ONCONFIG=$3 && + export INFO RMIXSERVER=$4 && + export PATH=$INFORMIXDIR/bin:$PATH && + export INFORMIXSQLHOSTS=$INFORMIXDIR/etc/$5 && + ./onstat -g wai | awk 'BEGIN {RS=""; FS="\n"} NR==2 {linecount = NF -2; if (linecount>0) print linecount; else print 0}') + +echo $result \ No newline at end of file diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/Constants.java b/rdb/src/main/java/com/instana/dc/rdb/impl/Constants.java index adbd25e..0e0e01c 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/Constants.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/Constants.java @@ -20,6 +20,9 @@ public class Constants { public static final String MEMORY_UTILIZATION_SCRIPT = "memory_utilization.sh"; public static final String DISK_READ_SCRIPT = "disk_read.sh"; public static final String DISK_WRITE_SCRIPT = "disk_write.sh"; + public static final String TASK_WAIT_COUNT_SCRIPT = "task_wait_count.sh"; + public static final String TOTAL_SESSION_COUNT_SCRIPT = "session_count.sh"; + public static final String ACTIVE_SESSION_COUNT_SCRIPT = "active_session_count.sh"; private Constants() { //Private constructor diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java index b289ab0..d671ce4 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java @@ -18,6 +18,7 @@ import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.Executors; @@ -27,34 +28,37 @@ import java.util.logging.Logger; import static com.instana.dc.rdb.DbDcUtil.*; +import static com.instana.dc.rdb.impl.Constants.ACTIVE_SESSION_COUNT_SCRIPT; +import static com.instana.dc.rdb.impl.Constants.DISK_READ_SCRIPT; +import static com.instana.dc.rdb.impl.Constants.DISK_WRITE_SCRIPT; import static com.instana.dc.rdb.impl.Constants.IO_READ_COUNT_SCRIPT; import static com.instana.dc.rdb.impl.Constants.IO_WRITE_COUNT_SCRIPT; import static com.instana.dc.rdb.impl.Constants.MEMORY_UTILIZATION_SCRIPT; import static com.instana.dc.rdb.impl.Constants.SQL_COUNT_SCRIPT; +import static com.instana.dc.rdb.impl.Constants.TASK_WAIT_COUNT_SCRIPT; +import static com.instana.dc.rdb.impl.Constants.TOTAL_SESSION_COUNT_SCRIPT; import static com.instana.dc.rdb.impl.Constants.TRANSACTION_COUNT_SCRIPT; -import static com.instana.dc.rdb.impl.Constants.DISK_READ_SCRIPT; -import static com.instana.dc.rdb.impl.Constants.DISK_WRITE_SCRIPT; import static com.instana.dc.rdb.impl.informix.InformixUtil.DB_HOST_AND_VERSION_SQL; public class InformixDc extends AbstractDbDc { private static final Logger LOGGER = Logger.getLogger(InformixDc.class.getName()); - public static final String SESSION_COUNT_SCRIPT = "session_count.sh"; + private static final int DEFAULT_ELAPSED_TIME = 900; private String tableSpaceSizeQuery; private String tableSpaceUsedQuery; private String tableSpaceUtilizationQuery; private String tableSpaceMaxQuery; + private String sqlElapsedTimeQuery; private boolean customPollRateEnabled = true; private ScheduledExecutorService executorService; private final BasicDataSource dataSource; - private final OnstatCommandExecutor onstatCommandExecutor; private final MetricsCollector metricCollector; public InformixDc(Map properties, String dbSystem, String dbDriver) throws SQLException { super(properties, dbSystem, dbDriver); parseCustomAttributes(properties); - onstatCommandExecutor = new OnstatCommandExecutor(getDbPath(), getServerName()); + OnstatCommandExecutor onstatCommandExecutor = new OnstatCommandExecutor(getDbPath(), getServerName()); setDbPassword(InformixUtil.decodePassword(getDbPassword())); setDbConnUrl(); @@ -69,15 +73,15 @@ public InformixDc(Map properties, String dbSystem, String dbDriv } private BasicDataSource getDataSource() { - final BasicDataSource dataSource; - dataSource = new BasicDataSource(); - dataSource.setDriverClassName(getDbDriver()); - dataSource.setUsername(getDbUserName()); - dataSource.setPassword(getDbPassword()); - dataSource.setUrl(getDbConnUrl()); - dataSource.setInitialSize(3); - dataSource.setMaxIdle(1); - return dataSource; + final BasicDataSource basicDataSource; + basicDataSource = new BasicDataSource(); + basicDataSource.setDriverClassName(getDbDriver()); + basicDataSource.setUsername(getDbUserName()); + basicDataSource.setPassword(getDbPassword()); + basicDataSource.setUrl(getDbConnUrl()); + basicDataSource.setInitialSize(3); + basicDataSource.setMaxIdle(1); + return basicDataSource; } /** @@ -94,12 +98,11 @@ private void registerMetricsMetadata() { MetricsDataConfigRegister.subscribeMetricDataConfig(DB_TABLESPACE_MAX_NAME, new MetricDataConfig(tableSpaceMaxQuery, MetricCollectionMode.SQL, List.class, DB_TABLESPACE_MAX_KEY)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_SQL_ELAPSED_TIME_NAME, - new MetricDataConfig(InformixUtil.SQL_ELAPSED_TIME_SQL, MetricCollectionMode.SQL, List.class, DB_SQL_ELAPSED_TIME_KEY, SemanticAttributes.SQL_TEXT.getKey())); + new MetricDataConfig(sqlElapsedTimeQuery, MetricCollectionMode.SQL, List.class, DB_SQL_ELAPSED_TIME_KEY, SemanticAttributes.SQL_TEXT.getKey())); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_INSTANCE_COUNT_NAME, new MetricDataConfig(InformixUtil.INSTANCE_COUNT_SQL, MetricCollectionMode.SQL, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_INSTANCE_ACTIVE_COUNT_NAME, new MetricDataConfig(InformixUtil.INSTANCE_ACTIVE_COUNT_SQL, MetricCollectionMode.SQL, Number.class)); - MetricsDataConfigRegister.subscribeMetricDataConfig(DB_DATABASE_LOG_ENABLED_NAME, new MetricDataConfig(InformixUtil.DB_DATABASE_LOG_ENABLED_SQL, MetricCollectionMode.SQL, List.class, DB_DATABASE_LOG_ENABLED_KEY)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_DATABASE_BUFF_LOG_ENABLED_NAME, @@ -121,9 +124,9 @@ private void registerMetricsMetadata() { MetricsDataConfigRegister.subscribeMetricDataConfig(DB_TRANSACTION_RATE_NAME, new MetricDataConfig(DB_TRANSACTION_RATE_NAME, TRANSACTION_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_SESSION_COUNT_NAME, - new MetricDataConfig(DB_SESSION_COUNT_NAME, SESSION_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); + new MetricDataConfig(DB_SESSION_COUNT_NAME, TOTAL_SESSION_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_SESSION_ACTIVE_COUNT_NAME, - new MetricDataConfig(DB_SESSION_ACTIVE_COUNT_NAME, SESSION_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); + new MetricDataConfig(DB_SESSION_ACTIVE_COUNT_NAME, ACTIVE_SESSION_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_IO_READ_RATE_NAME, new MetricDataConfig(DB_IO_READ_RATE_NAME, IO_READ_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_IO_WRITE_RATE_NAME, @@ -134,7 +137,8 @@ private void registerMetricsMetadata() { new MetricDataConfig(DB_DISK_READ_COUNT_NAME, DISK_READ_SCRIPT, MetricCollectionMode.CMD, Number.class)); MetricsDataConfigRegister.subscribeMetricDataConfig(DB_DISK_WRITE_COUNT_NAME, new MetricDataConfig(DB_DISK_WRITE_COUNT_NAME, DISK_WRITE_SCRIPT, MetricCollectionMode.CMD, Number.class)); - + MetricsDataConfigRegister.subscribeMetricDataConfig(DB_TASK_WAIT_COUNT_NAME, + new MetricDataConfig(DB_TASK_WAIT_COUNT_NAME, TASK_WAIT_COUNT_SCRIPT, MetricCollectionMode.CMD, Number.class)); } /** @@ -142,6 +146,7 @@ private void registerMetricsMetadata() { * * @param properties : user inputs */ + @SuppressWarnings("unchecked") private void parseCustomPollRate(Map properties) { Map customInput = (Map) properties.get("custom.poll.interval"); if (null == customInput || customInput.isEmpty()) { @@ -190,17 +195,16 @@ private void scheduleCustomPollRate(int pollInterval, IntervalType intervalType) * * @param properties : Config data */ + @SuppressWarnings("unchecked") private void parseCustomAttributes(Map properties) { - Map customInput = (Map) properties.get("custom.input"); - String[] dbNames = ((String) customInput.get("db.names")).split(","); - StringBuilder sb = new StringBuilder(Constants.SINGLE_QUOTES + dbNames[0] + Constants.SINGLE_QUOTES); - for (int i = 1; i < dbNames.length; i++) { - sb.append(Constants.COMMA).append(Constants.SINGLE_QUOTES).append(dbNames[i].trim()).append(Constants.SINGLE_QUOTES); - } - tableSpaceSizeQuery = String.format(InformixUtil.TABLESPACE_SIZE_SQL, sb); - tableSpaceUsedQuery = String.format(InformixUtil.TABLESPACE_USED_SQL, sb); - tableSpaceUtilizationQuery = String.format(InformixUtil.TABLESPACE_UTILIZATION_SQL, sb); - tableSpaceMaxQuery = String.format(InformixUtil.TABLESPACE_MAX_SQL, sb); + Map customInput = (Map) properties.getOrDefault("custom.input", Collections.emptyMap()); + long elapsedTimeFrame = Long.parseLong((customInput.getOrDefault("db.sql.elapsed.timeframe", DEFAULT_ELAPSED_TIME)).toString()); + StringBuilder databaseName = new StringBuilder(Constants.SINGLE_QUOTES + getDbName() + Constants.SINGLE_QUOTES); + tableSpaceSizeQuery = String.format(InformixUtil.TABLESPACE_SIZE_SQL, databaseName); + tableSpaceUsedQuery = String.format(InformixUtil.TABLESPACE_USED_SQL, databaseName); + tableSpaceUtilizationQuery = String.format(InformixUtil.TABLESPACE_UTILIZATION_SQL, databaseName); + tableSpaceMaxQuery = String.format(InformixUtil.TABLESPACE_MAX_SQL, databaseName); + sqlElapsedTimeQuery = String.format(InformixUtil.SQL_ELAPSED_TIME_SQL, elapsedTimeFrame, databaseName); } private void setDbConnUrl() { @@ -248,6 +252,7 @@ private void getallMetrics() { shortPollingInterval(); } + @SuppressWarnings("unchecked") private void mediumPollingInterval() { getRawMetric(DB_SQL_COUNT_NAME).setValue((Number) metricCollector.collectMetrics(DB_SQL_COUNT_NAME)); getRawMetric(DB_SQL_RATE_NAME).setValue((Number) metricCollector.collectMetrics(DB_SQL_RATE_NAME)); @@ -271,6 +276,7 @@ private void shortPollingInterval() { getRawMetric(DB_DISK_READ_COUNT_NAME).setValue((Number) metricCollector.collectMetrics(DB_DISK_READ_COUNT_NAME)); } + @SuppressWarnings("unchecked") private void longPollingInterval() { getRawMetric(DB_TABLESPACE_SIZE_NAME).setValue((List) metricCollector.collectMetrics(DB_TABLESPACE_SIZE_NAME)); getRawMetric(DB_TABLESPACE_USED_NAME).setValue((List) metricCollector.collectMetrics(DB_TABLESPACE_USED_NAME)); diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixUtil.java b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixUtil.java index b44185a..0cf11a8 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixUtil.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixUtil.java @@ -12,38 +12,42 @@ private InformixUtil() { //Private Constructor } - public static final String DB_HOST_AND_VERSION_SQL = "SELECT FIRST 1 DBINFO('version','full') as Version, DBINFO('dbhostname') as HostName FROM systables;"; - public static final String AVAILABLE_DATA_BASES = "select name, owner, partnum from sysdatabases"; - + public static final String DB_HOST_AND_VERSION_SQL = "SELECT FIRST 1 DBINFO('VERSION','FULL') AS VERSION, DBINFO('DBHOSTNAME') AS HOSTNAME FROM SYSTABLES;"; + public static final String AVAILABLE_DATA_BASES = "SELECT NAME, OWNER, PARTNUM FROM SYSDATABASES;"; //Instance & Active Instance information (KPI) - public static final String INSTANCE_COUNT_SQL = "SELECT count(distinct DBSERVERNAME) as SERVER FROM systables;"; - public static final String INSTANCE_ACTIVE_COUNT_SQL = "select count(distinct name) as ACTIVE_SERVER from syscluster where server_status = 'Active';"; + public static final String INSTANCE_COUNT_SQL = "SELECT COUNT(DISTINCT DBSERVERNAME) AS SERVER FROM SYSTABLES;"; + public static final String INSTANCE_ACTIVE_COUNT_SQL = "SELECT COUNT(DISTINCT NAME) AS ACTIVE_SERVER FROM SYSCLUSTER WHERE SERVER_STATUS = 'Active';"; //Session & Active Session information (KPI) - public static final String ACTIVE_SESSION = "select count(1) from syssessions;"; - public static final String SESSION_COUNT_SQL = "select count(1) from syssessions;"; + public static final String ACTIVE_SESSION = "SELECT COUNT(1) FROM SYSSESSIONS;"; + public static final String SESSION_COUNT_SQL = "SELECT COUNT(1) FROM SYSSESSIONS;"; //I/O Read & Write information (KPI) : As number of Reads/Writes PER CHUNK hence doing the sum - public static final String IO_READ_COUNT_SQL = "SELECT SUM(syschunks.pagesize * syschkio.pagesread) FROM SYSCHKIO INNER JOIN syschunks ON syschunks.chknum=syschkio.chunknum;"; - public static final String IO_WRITE_COUNT_SQL = "SELECT SUM(syschunks.pagesize * syschkio.pageswritten) FROM SYSCHKIO INNER JOIN syschunks ON syschunks.chknum=syschkio.chunknum;"; + public static final String IO_READ_COUNT_SQL = "SELECT SUM(SYSCHUNKS.PAGESIZE * SYSCHKIO.PAGESREAD) FROM SYSCHKIO INNER JOIN SYSCHUNKS ON SYSCHUNKS.CHKNUM=SYSCHKIO.CHUNKNUM;"; + public static final String IO_WRITE_COUNT_SQL = "SELECT SUM(SYSCHUNKS.PAGESIZE * SYSCHKIO.PAGESWRITTEN) FROM SYSCHKIO INNER JOIN SYSCHUNKS ON SYSCHUNKS.CHKNUM=SYSCHKIO.CHUNKNUM;"; - public static final String MEMORY_UTILIZATION_SQL = "SELECT (sum(seg_blkused) * 100) / (sum(seg_blkused) + sum(seg_blkfree)) FROM SYSSEGLST;"; + public static final String MEMORY_UTILIZATION_SQL = "SELECT (SUM(SEG_BLKUSED) * 100) / (SUM(SEG_BLKUSED) + SUM(SEG_BLKFREE)) FROM SYSSEGLST;"; - public static final String SQL_COUNT_SQL = "SELECT count(1) from syssqltrace where (dbinfo('utc_current') - sql_finishtime)<24*60*60;"; - public static final String TRANSACTION_COUNT_SQL = "select count(1) from systrans;"; - public static final String SQL_ELAPSED_TIME_SQL = "SELECT sql_runtime*1000 as ELAPSED_TIME_MILLIS, sql_id as sql_id, sql_statement as sql_text FROM sysmaster:syssqltrace where sql_statement not like '%syssqltrace%' ORDER BY sql_runtime desc limit 20;"; + public static final String SQL_COUNT_SQL = "SELECT COUNT(1) FROM SYSSQLTRACE WHERE (DBINFO('UTC_CURRENT') - SQL_FINISHTIME)<24*60*60;"; + public static final String TRANSACTION_COUNT_SQL = "SELECT COUNT(1) FROM SYSTRANS;"; + public static final String SQL_ELAPSED_TIME_SQL = "SELECT SQL_RUNTIME * 1000 AS ELAPSED_TIME_MILLIS, SQL_ID AS SQL_ID, SQL_STATEMENT AS SQL_TEXT FROM INFORMIX.SYSSQLTRACE WHERE SQL_FINISHTIME >= (DBINFO('UTC_CURRENT') - %s) AND SQL_DATABASE = %s ORDER BY ELAPSED_TIME_MILLIS DESC LIMIT 20;"; //Table Space Queries - public static final String TABLESPACE_SIZE_SQL = "SELECT(pt.nptotal * pt.pagesize) * 1024 AS total_kb,tabname FROM sysmaster:sysptnhdr pt INNER JOIN sysmaster:systabnames tn ON tn.partnum = pt.partnum where (tn.dbsname in ( %s )) order by tabname desc Limit 40;"; - public static final String TABLESPACE_USED_SQL = "SELECT(pt.npused * pt.pagesize) * 1024 AS used_kb,tabname FROM sysmaster:sysptnhdr pt INNER JOIN sysmaster:systabnames tn ON tn.partnum = pt.partnum where (tn.dbsname in (%s)) order by tabname desc Limit 40;"; - public static final String TABLESPACE_UTILIZATION_SQL = "select case WHEN (pt.nptotal > 0) THEN ((pt.npused) /pt.nptotal) * 100 ELSE 0 END AS table_utilization, tabname FROM sysmaster:sysptnhdr pt INNER JOIN sysmaster:systabnames tn ON tn.partnum = pt.partnum where (tn.dbsname in ('instana')) order by tabname desc Limit 40;"; - public static final String TABLESPACE_MAX_SQL = "SELECT(pt.nptotal * pt.pagesize) * 1024 AS total_kb, tabname FROM sysmaster:sysptnhdr pt INNER JOIN sysmaster:systabnames tn ON tn.partnum = pt.partnum where (tn.dbsname in ('instana')) order by tabname desc Limit 40;"; + public static final String TABLESPACE_SIZE_SQL = "SELECT (PT.NPTOTAL * PT.PAGESIZE) * 1024 AS TOTAL_KB,TABNAME FROM SYSMASTER:SYSPTNHDR PT INNER JOIN SYSMASTER:SYSTABNAMES TN ON TN.PARTNUM = PT.PARTNUM WHERE TN.DBSNAME = %S ORDER BY TABNAME DESC LIMIT 20;"; + public static final String TABLESPACE_USED_SQL = "SELECT (PT.NPUSED * PT.PAGESIZE) * 1024 AS USED_KB,TABNAME FROM SYSMASTER:SYSPTNHDR PT INNER JOIN SYSMASTER:SYSTABNAMES TN ON TN.PARTNUM = PT.PARTNUM WHERE TN.DBSNAME = %S ORDER BY TABNAME DESC LIMIT 20;"; + public static final String TABLESPACE_UTILIZATION_SQL = "SELECT CASE WHEN (PT.NPTOTAL > 0) THEN ((PT.NPUSED) / PT.NPTOTAL) * 100 ELSE 0 END AS TABLE_UTILIZATION, TABNAME FROM SYSMASTER:SYSPTNHDR PT INNER JOIN SYSMASTER:SYSTABNAMES TN ON TN.PARTNUM = PT.PARTNUM WHERE TN.DBSNAME = %s ORDER BY TABNAME DESC LIMIT 20;"; + public static final String TABLESPACE_MAX_SQL = "SELECT (PT.NPTOTAL * PT.PAGESIZE) * 1024 AS TOTAL_KB, TABNAME FROM SYSMASTER:SYSPTNHDR PT INNER JOIN SYSMASTER:SYSTABNAMES TN ON TN.PARTNUM = PT.PARTNUM WHERE TN.DBSNAME = %s ORDER BY TABNAME DESC LIMIT 20;"; //Database Queries - public static final String DB_DATABASE_LOG_ENABLED_SQL = "SELECT is_logging, name as database_name FROM sysdatabases"; - public static final String DB_DATABASE_BUFF_LOG_ENABLED_SQL = "SELECT is_buff_log, name as database_name FROM sysdatabases"; - public static final String DB_DATABASE_ANSI_COMPLAINT_SQL = "SELECT is_ansi, name as database_name FROM sysdatabases"; - public static final String DB_DATABASE_NLS_ENABLED_SQL = "SELECT is_nls, name as database_name FROM sysdatabases"; - public static final String DB_DATABASE_CASE_INCENSITIVE_SQL = "SELECT is_case_insens, name as database_name FROM sysdatabases"; + public static final String DB_DATABASE_LOG_ENABLED_SQL = "SELECT IS_LOGGING, NAME AS DATABASE_NAME FROM SYSDATABASES"; + public static final String DB_DATABASE_BUFF_LOG_ENABLED_SQL = "SELECT IS_BUFF_LOG, NAME AS DATABASE_NAME FROM SYSDATABASES"; + public static final String DB_DATABASE_ANSI_COMPLAINT_SQL = "SELECT IS_ANSI, NAME AS DATABASE_NAME FROM SYSDATABASES"; + public static final String DB_DATABASE_NLS_ENABLED_SQL = "SELECT IS_NLS, NAME AS DATABASE_NAME FROM SYSDATABASES"; + public static final String DB_DATABASE_CASE_INCENSITIVE_SQL = "SELECT IS_CASE_INSENS, NAME AS DATABASE_NAME FROM SYSDATABASES"; + + //Disk Read & Write + public static final String DB_DISK_WRITE_COUNT_SQL = "SELECT VALUE FROM SYSPROFILE WHERE NAME = 'dskwrites';"; + public static final String DB_DISK_READ_COUNT_SQL = "SELECT VALUE FROM SYSPROFILE WHERE NAME = 'dskreads';"; + public static String decodePassword(String encodedPwd) { return new String(Base64.getDecoder().decode(encodedPwd)); } diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/strategy/MetricsCollector.java b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/strategy/MetricsCollector.java index 974e13d..88da40e 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/strategy/MetricsCollector.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/strategy/MetricsCollector.java @@ -35,6 +35,10 @@ public MetricsCollector(BasicDataSource dataSource, OnstatCommandExecutor onstat public T collectMetrics(String metricName) { try { MetricDataConfig metricDataConfig = MetricsDataConfigRegister.getMetricDataConfig(metricName); + if (null == metricDataConfig) { + LOGGER.log(Level.INFO, "No Metrics Data for metric: {}", metricName); + return null; + } MetricCollectionMode mode = metricDataConfig.getSelectedMode(); if (mode == MetricCollectionMode.SQL) { T response = sqlExecutorStrategy.collectMetrics(metricDataConfig); @@ -46,8 +50,8 @@ public T collectMetrics(String metricName) { return response; } throw new IllegalStateException("For Metric: " + metricName + " Invalid Mode selected: " + mode); - }catch (Exception e){ - LOGGER.log(Level.SEVERE, "Failed to update metric {0} due to exception: {1}", new Object[]{metricName,e}); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "Failed to update metric {0} due to exception: {1}", new Object[]{metricName, e}); } return null; }