io.thundra.swark.jdbc.spring.monitoring.DatabaseExecutionInfoProvider Maven / Gradle / Ivy
package io.thundra.swark.jdbc.spring.monitoring;
import io.thundra.swark.monitoring.ExecutionInfoProvider;
import java.util.HashMap;
import java.util.Map;
/**
* @author serkan
*/
public class DatabaseExecutionInfoProvider implements ExecutionInfoProvider {
private static final int NANOSECONDS_IN_MILLISECONDS = 1_000_000;
@Override
public String getGroupName() {
return DatabaseExecutionInfoGroup.GROUP_NAME;
}
@Override
public DatabaseExecutionInfoGroup createInfoGroup() {
return new DatabaseExecutionInfoGroup();
}
@Override
public Map toInfo(DatabaseExecutionInfoGroup databaseExecutionInfoGroup) {
Map executionInfo = new HashMap<>();
executionInfo.put("query.count",
databaseExecutionInfoGroup.queryCount.intValue());
executionInfo.put("query.duration.total",
databaseExecutionInfoGroup.queryDuration.longValue() / NANOSECONDS_IN_MILLISECONDS);
executionInfo.put("query.duration.avg",
databaseExecutionInfoGroup.queryCount.intValue() == 0
? 0
: (databaseExecutionInfoGroup.queryDuration.longValue() / NANOSECONDS_IN_MILLISECONDS) /
databaseExecutionInfoGroup.queryCount.intValue());
executionInfo.put("update.count",
databaseExecutionInfoGroup.updateCount.intValue());
executionInfo.put("update.duration.total",
databaseExecutionInfoGroup.updateDuration.longValue() / NANOSECONDS_IN_MILLISECONDS);
executionInfo.put("update.duration.avg",
databaseExecutionInfoGroup.updateCount.intValue() == 0
? 0
: (databaseExecutionInfoGroup.updateDuration.longValue() / NANOSECONDS_IN_MILLISECONDS) /
databaseExecutionInfoGroup.updateCount.intValue());
executionInfo.put("count",
databaseExecutionInfoGroup.queryCount.intValue() +
databaseExecutionInfoGroup.updateCount.intValue());
executionInfo.put("duration.total",
(
databaseExecutionInfoGroup.queryDuration.longValue() +
databaseExecutionInfoGroup.updateDuration.longValue()
) / NANOSECONDS_IN_MILLISECONDS);
executionInfo.put("duration.avg",
(
databaseExecutionInfoGroup.queryCount.intValue() +
databaseExecutionInfoGroup.updateCount.intValue()
) == 0
? 0
: (
(
databaseExecutionInfoGroup.queryDuration.longValue() +
databaseExecutionInfoGroup.updateDuration.longValue()
)
/ NANOSECONDS_IN_MILLISECONDS
) /
(
databaseExecutionInfoGroup.queryCount.intValue() +
databaseExecutionInfoGroup.updateCount.intValue()
));
executionInfo.put("error.count",
databaseExecutionInfoGroup.errorCount.intValue());
return executionInfo;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy