Package io.prometheus.client.hibernate
Class HibernateStatisticsCollector
java.lang.Object
io.prometheus.client.Collector
io.prometheus.client.hibernate.HibernateStatisticsCollector
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceprivate static interfaceprivate static interfaceNested classes/interfaces inherited from class io.prometheus.client.Collector
Collector.Describable, Collector.MetricFamilySamples, Collector.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFields inherited from class io.prometheus.client.Collector
MILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty collector.HibernateStatisticsCollector(org.hibernate.SessionFactory sessionFactory, String name) Creates a new collector for the given session factory. -
Method Summary
Modifier and TypeMethodDescriptionRegisters a Hibernate SessionFactory with this collector.private voidaddMetricsForQuery(HibernateStatisticsCollector.PerQuerySamples samples, HibernateStatisticsCollector.ValueProviderPerQuery provider) collect()Return all metrics of this Collector.private CounterMetricFamilycreateCounter(String metric, String help, HibernateStatisticsCollector.ValueProvider provider) private CounterMetricFamilycreateCounterForQuery(String metric, String help, HibernateStatisticsCollector.ValueProviderPerQuery provider) private GaugeMetricFamilycreateGaugeForQuery(String metric, String help, HibernateStatisticsCollector.ValueProviderPerQuery provider) Enables collection of per-query metrics.private List<Collector.MetricFamilySamples>private List<Collector.MetricFamilySamples>private List<Collector.MetricFamilySamples>private List<Collector.MetricFamilySamples>private List<Collector.MetricFamilySamples>private List<Collector.MetricFamilySamples><T extends Collector>
Tregister(CollectorRegistry registry) Register the Collector with the given registry.private doubletoSeconds(long milliseconds) Methods inherited from class io.prometheus.client.Collector
checkMetricLabelName, checkMetricName, collect, doubleToGoString, register, sanitizeMetricName
-
Field Details
-
LABEL_NAMES
-
LABEL_NAMES_PER_QUERY
-
sessionFactories
-
perQueryMetricsEnabled
private boolean perQueryMetricsEnabled
-
-
Constructor Details
-
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
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 Details
-
add
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
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
Description copied from class:CollectorReturn all metrics of this Collector. -
register
Description copied from class:CollectorRegister the Collector with the given registry. -
getSessionMetrics
-
getConnectionMetrics
-
getCacheMetrics
-
getEntityMetrics
-
getQueryExecutionMetrics
-
getPerQueryMetrics
-
createCounter
private CounterMetricFamily createCounter(String metric, String help, HibernateStatisticsCollector.ValueProvider provider) -
createCounterForQuery
private CounterMetricFamily createCounterForQuery(String metric, String help, HibernateStatisticsCollector.ValueProviderPerQuery provider) -
createGaugeForQuery
private GaugeMetricFamily createGaugeForQuery(String metric, String help, HibernateStatisticsCollector.ValueProviderPerQuery provider) -
addMetricsForQuery
private void addMetricsForQuery(HibernateStatisticsCollector.PerQuerySamples samples, HibernateStatisticsCollector.ValueProviderPerQuery provider) -
toSeconds
private double toSeconds(long milliseconds)
-