try {
jdbcConnection = getPooledConnectionProvider().getPooledConnection();
statement = jdbcConnection.createStatement();
resultSet = statement.executeQuery("SELECT pg_postmaster_start_time()");
if (resultSet.next()) {
report.addData(new MeasurementDataTrait(request, resultSet.getTimestamp(1).toString()));
}
} catch (SQLException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Can not collect metric: " + metricName + ": " + e.getLocalizedMessage());
}
} finally {
DatabasePluginUtil.safeClose(jdbcConnection, statement, resultSet);
}
} else if (metricName.endsWith("backends")) {
// number of connected backends
Connection jdbcConnection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
jdbcConnection = getPooledConnectionProvider().getPooledConnection();
statement = jdbcConnection.createStatement();
resultSet = statement.executeQuery("select count(*) from pg_stat_activity");
if (resultSet.next()) {
report.addData(new MeasurementDataNumeric(request, (double) resultSet.getLong(1)));
}
} catch (SQLException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Can not collect metricName: " + metricName + ": " + e.getLocalizedMessage());
}
} finally {
DatabasePluginUtil.safeClose(jdbcConnection, statement, resultSet);
}
}
} else if (metricName.startsWith(METRIC_RUNTIME_PREFIX)) {
runtimePropertiesRequests.put(metricName.substring(METRIC_RUNTIME_PREFIX.length()), request);
}
}
if (!runtimePropertiesRequests.isEmpty()) {
Connection jdbcConnection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
jdbcConnection = getPooledConnectionProvider().getPooledConnection();
statement = jdbcConnection.createStatement();
resultSet = statement.executeQuery("show all");
while (resultSet.next()) {
String runtimeProperty = resultSet.getString("name");
if (!runtimePropertiesRequests.containsKey(runtimeProperty)) {
continue;
}
String setting = resultSet.getString("setting");
MeasurementScheduleRequest request = runtimePropertiesRequests.get(runtimeProperty);
switch (request.getDataType()) {
case TRAIT:
report.addData(new MeasurementDataTrait(request, setting));
break;
default:
if (LOG.isDebugEnabled()) {
LOG.debug("Unsupported metric data type: " + request.getName() + ", "
+ request.getDataType());