Reputation: 4503
I’m using p6spy-spring-boot-starter
in my Spring Boot application to analyze MySQL queries. I’ve added the following dependencies in my pom.xml:
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
In my application.properties
, I’ve included the following property because I don’t want to generate any logs; instead, I want to set up monitoring based on captured metrics.
decorator.datasource.p6spy.enable-logging=false
Additionally, I’ve created a custom JDBC event listener to capture metrics:
public class CustomJdbcEventListener extends SimpleJdbcEventListener {
private final MetricManager metricManager;
public CustomJdbcEventListener(MetricManager metricManager) {
this.metricManager = metricManager;
}
@Override
public void onAfterAnyExecute(StatementInformation statementInformation,
long timeElapsedNanos,
SQLException e) {
long timeElapsedMs = TimeUnit.NANOSECONDS.toMillis(timeElapsedNanos);
String metricName = "SQL_STATEMENT " + statementInformation.getStatementQuery();
metricManager.registerCustomMetric(metricName);
metricManager.setCustomMetricsValue(metricName, timeElapsedMs);
}
}
I’m injecting this listener using the following configuration:
@Configuration
public class CustomJdbcListenerConfiguration {
@Bean
public CustomJdbcEventListener getCustomJdbcEventListener(MetricManager metricManager) {
return new CustomJdbcEventListener(metricManager);
}
}
However, when I start the application, I get the following error:
java.lang.IllegalStateException: couldn't create PrintStream for spy.log (Permission Denied)
Despite setting decorator.datasource.p6spy.enable-logging=false
, the application seems to be trying to create a spy.log
file, which I don't want.
Any help would be greatly appreciated!
Upvotes: 0
Views: 143