public class HibernateStatisticsCollector extends io.prometheus.client.Collector
Usage example for a single session factory:
new HibernateStatisticsCollector(sessionFactory, "myapp").register();Usage example for multiple session factories:
new HibernateStatisticsCollector()
.add(sessionFactory1, "myapp1")
.add(sessionFactory2, "myapp2")
.register();
If you are in a JPA environment, you can obtain the SessionFactory like this:
SessionFactory sessionFactory =
entityManagerFactory.unwrap(SessionFactory.class);
When enablePerQueryMetrics() has been called, certain metrics like execution
time are collected per query. This may create a lot of monitoring data, so it should
be used with caution.
| Constructor and Description |
|---|
HibernateStatisticsCollector()
Creates an empty collector.
|
HibernateStatisticsCollector(org.hibernate.SessionFactory sessionFactory,
String name)
Creates a new collector for the given session factory.
|
| Modifier and Type | Method and Description |
|---|---|
HibernateStatisticsCollector |
add(org.hibernate.SessionFactory sessionFactory,
String name)
Registers a Hibernate SessionFactory with this collector.
|
List<io.prometheus.client.Collector.MetricFamilySamples> |
collect() |
HibernateStatisticsCollector |
enablePerQueryMetrics()
Enables collection of per-query metrics.
|
<T extends io.prometheus.client.Collector> |
register(io.prometheus.client.CollectorRegistry registry) |
public HibernateStatisticsCollector()
add(SessionFactory, String)
method.public HibernateStatisticsCollector(org.hibernate.SessionFactory sessionFactory, String name)
add(SessionFactory, String).sessionFactory - The Hibernate SessionFactory to collect metrics forname - A unique name for this SessionFactorypublic HibernateStatisticsCollector add(org.hibernate.SessionFactory sessionFactory, String name)
sessionFactory - The Hibernate SessionFactory to collect metrics forname - A unique name for this SessionFactorypublic HibernateStatisticsCollector enablePerQueryMetrics()
Per-query metrics have a label "query" with the actual HQL query as value. The query will contain
placeholders ("?") instead of the real parameter values (example: select u from User u where id=?).
public List<io.prometheus.client.Collector.MetricFamilySamples> collect()
collect in class io.prometheus.client.Collectorpublic <T extends io.prometheus.client.Collector> T register(io.prometheus.client.CollectorRegistry registry)
register in class io.prometheus.client.CollectorCopyright © 2021. All rights reserved.