From 1955560eddd684eb37b5057443bedf7b31ba53ac Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Tue, 12 Sep 2023 11:14:38 -0300 Subject: [PATCH] add TM counter --- jpos/src/main/java/org/jpos/metrics/MeterInfo.java | 5 +++-- .../org/jpos/transaction/TransactionManager.java | 14 ++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/jpos/src/main/java/org/jpos/metrics/MeterInfo.java b/jpos/src/main/java/org/jpos/metrics/MeterInfo.java index 3dfa0df27e..cbe58a085c 100644 --- a/jpos/src/main/java/org/jpos/metrics/MeterInfo.java +++ b/jpos/src/main/java/org/jpos/metrics/MeterInfo.java @@ -18,8 +18,9 @@ package org.jpos.metrics; public enum MeterInfo { - TM_ACTIVE_SESSIONS("jpos.tm.active.sessions", "approximate number of activeSessions"), - TM_OPERATION("jpos.tm", "transaction manager operation"); + TM_ACTIVE_SESSIONS("jpos.tm.active.sessions", "TransactionManager activeSessions"), + TM_OPERATION("jpos.tm.op", "TransactionManager operation"), + TM_COUNTER("jpos.tm.cnt", "TransactionManager counter"); final String id; final String description; diff --git a/jpos/src/main/java/org/jpos/transaction/TransactionManager.java b/jpos/src/main/java/org/jpos/transaction/TransactionManager.java index 53a288ce9e..9f742e7833 100644 --- a/jpos/src/main/java/org/jpos/transaction/TransactionManager.java +++ b/jpos/src/main/java/org/jpos/transaction/TransactionManager.java @@ -113,7 +113,7 @@ public class TransactionManager private static AtomicBoolean filtersAdded = new AtomicBoolean(); private Gauge activeSessionsGauge; - private Counter transactionsCounter; + private Counter transactionCounter; @Override public void initService () throws ConfigurationException { @@ -226,9 +226,13 @@ public void run () { if (context instanceof Context ctx) ctx.log ("active=%d, maxSessions=%d".formatted(getActiveSessions(), maxSessions)); int session = activeSessions.incrementAndGet(); + transactionCounter.increment(); executor.execute(() -> { - runTransaction(context, session); - activeSessions.decrementAndGet(); + try { + runTransaction(context, session); + } finally { + activeSessions.decrementAndGet(); + } }); } else { @@ -393,11 +397,13 @@ public void setConfiguration (Configuration cfg) throws ConfigurationException { metrics = new Metrics(new AtomicHistogram(cfg.getLong("metrics-highest-trackable-value", 60000), 2)); abortOnMisconfiguredGroups = cfg.getBoolean("abort-on-misconfigured-groups"); - // Configure meters try { activeSessionsGauge = MeterFactory.gauge (getServer().getMeterRegistry(), MeterInfo.TM_ACTIVE_SESSIONS, Tags.of("name", getName()), BaseUnits.THREADS, activeSessions::get ); + transactionCounter = MeterFactory.counter + (getServer().getMeterRegistry(), MeterInfo.TM_COUNTER, Tags.of("name", getName()) + ); } catch (Exception e) { throw new ConfigurationException (e); }