Skip to content

Commit

Permalink
add TM counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Sep 12, 2023
1 parent bcba1e8 commit 1955560
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions jpos/src/main/java/org/jpos/metrics/MeterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 10 additions & 4 deletions jpos/src/main/java/org/jpos/transaction/TransactionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1955560

Please sign in to comment.