Package io.prometheus.client.hibernate
Class HibernateStatisticsCollector
- java.lang.Object
-
- io.prometheus.client.Collector
-
- io.prometheus.client.hibernate.HibernateStatisticsCollector
-
public class HibernateStatisticsCollector extends io.prometheus.client.Collector
Collect metrics from one or more Hibernate SessionFactory instances.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.- Author:
- Christian Kaltepoth
-
-
Constructor Summary
Constructors Constructor Description HibernateStatisticsCollector()Creates an empty collector.HibernateStatisticsCollector(org.hibernate.SessionFactory sessionFactory, String name)Creates a new collector for the given session factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HibernateStatisticsCollectoradd(org.hibernate.SessionFactory sessionFactory, String name)Registers a Hibernate SessionFactory with this collector.List<io.prometheus.client.Collector.MetricFamilySamples>collect()HibernateStatisticsCollectorenablePerQueryMetrics()Enables collection of per-query metrics.<T extends io.prometheus.client.Collector>
Tregister(io.prometheus.client.CollectorRegistry registry)
-
-
-
Constructor Detail
-
HibernateStatisticsCollector
public HibernateStatisticsCollector()
Creates an empty collector. If you use this constructor, you have to add one or more session factories to the collector by calling theadd(SessionFactory, String)method.
-
HibernateStatisticsCollector
public HibernateStatisticsCollector(org.hibernate.SessionFactory sessionFactory, String name)
Creates a new collector for the given session factory. Calling this constructor has the same effect as creating an empty collector and adding the session factory usingadd(SessionFactory, String).- Parameters:
sessionFactory- The Hibernate SessionFactory to collect metrics forname- A unique name for this SessionFactory
-
-
Method Detail
-
add
public HibernateStatisticsCollector add(org.hibernate.SessionFactory sessionFactory, String name)
Registers a Hibernate SessionFactory with this collector.- Parameters:
sessionFactory- The Hibernate SessionFactory to collect metrics forname- A unique name for this SessionFactory- Returns:
- Returns the collector
-
enablePerQueryMetrics
public HibernateStatisticsCollector enablePerQueryMetrics()
Enables collection of per-query metrics. Produces a lot of monitoring data, so use with caution.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=?).- Returns:
- Returns the collector
-
collect
public List<io.prometheus.client.Collector.MetricFamilySamples> collect()
- Specified by:
collectin classio.prometheus.client.Collector
-
register
public <T extends io.prometheus.client.Collector> T register(io.prometheus.client.CollectorRegistry registry)
- Overrides:
registerin classio.prometheus.client.Collector
-
-