Наша установка HikariCP выглядит следующим образом:
Код: Выделить всё
private DataSource createDataSource() {
final HikariConfig config = new HikariConfig();
config.setJdbcUrl(...);
config.setUsername(...);
config.setPassword(...);
config.setSchema(...);
config.setConnectionTimeout(...);
config.setMinimumIdle(...);
config.setMaximumPoolSize(...);
config.setIdleTimeout(...);
config.setLeakDetectionThreshold(...);
config.setMaxLifetime(...);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setMetricRegistry(metricsRegistry.getRegistry());
return new HikariDataSource(config);
}
Код: Выделить всё
public class NewRelicMetricsService {
private static final Logger logger = LoggerFactory.getLogger(NewRelicMetricsService.class);
private final NewRelicReporter reporter;
@Inject
public NewRelicMetricsService(ApplicationMetricsRegistry metricRegistry) {
NewRelicReporter tmpReporter = null;
// Check if the NewRelic java agent has been loaded.
try {
Class.forName("com.newrelic.api.agent.NewRelic");
Config config = NewRelic.getAgent().getConfig();
SenderConfiguration sender = MetricBatchSender.configurationBuilder()
.apiKey(config.getValue("license_key"))
.useLicenseKey(true)
.httpPoster(new OkHttpPoster(Duration.ofSeconds(2)))
.build();
MetricBatchSender metricBatchSender = MetricBatchSender.create(sender);
// Use this to define custom attributes visible in the APM & Service.
Attributes commonAttributes = new Attributes();
tmpReporter = NewRelicReporter.build(metricRegistry.getRegistry(), metricBatchSender)
.commonAttributes(commonAttributes)
.build();
} catch (ClassNotFoundException e) {
logger.info("New Relic java agent has not been loaded. Metrics will not be showing in New Relic.");
}
this.reporter = tmpReporter;
// Start reporting.
start();
}
public void start() {
if (reporter == null) {
return;
}
reporter.start(1, TimeUnit.SECONDS);
}
public void stop() {
if (reporter == null) {
return;
}
reporter.stop();
}
}

Однако, как только вы попытаетесь отфильтровать метрики через объект - эти метрики нигде не видно. Это как если бы метрики были включены в «корневую» сущность, где вы видите «все метрики».
[img]https: //i.sstatic.net/pBMM1TEf.png[/img]
Не совсем понимаю, что здесь не так. Есть у кого-нибудь идеи?
Может быть, нам нужно добавить какие-то особые/дополнительные атрибуты?
Подробнее здесь: https://stackoverflow.com/questions/783 ... n-newrelic