mirror of
https://github.com/apache/activemq.git
synced 2025-02-26 03:54:57 +00:00
AMQ-9552: Add metric lastMessageTimestamp to StatisticsBroker based on lastSampleTime of metric enqueues (if hasUpdated)
This commit is contained in:
parent
e45ee4aae5
commit
4c307dfae5
@ -160,6 +160,11 @@ public class StatisticsBroker extends BrokerFilter {
|
|||||||
tempFirstMessage.clear();
|
tempFirstMessage.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( stats.getEnqueues().hasUpdated() ) {
|
||||||
|
// NOTICE: Client-side, you may get the broker "now" Timestamp by msg.getJMSTimestamp()
|
||||||
|
// This allows for calculating inactivity.
|
||||||
|
statsMessage.setLong("lastMessageTimestamp", stats.getEnqueues().getLastSampleTime());
|
||||||
|
}
|
||||||
statsMessage.setJMSCorrelationID(messageSend.getCorrelationId());
|
statsMessage.setJMSCorrelationID(messageSend.getCorrelationId());
|
||||||
sendStats(producerExchange.getConnectionContext(), statsMessage, replyTo);
|
sendStats(producerExchange.getConnectionContext(), statsMessage, replyTo);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ public class StatisticImpl implements Statistic, Resettable {
|
|||||||
private String description;
|
private String description;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long lastSampleTime;
|
private long lastSampleTime;
|
||||||
|
private boolean hasUpdated;
|
||||||
private boolean doReset = true;
|
private boolean doReset = true;
|
||||||
|
|
||||||
public StatisticImpl(String name, String unit, String description) {
|
public StatisticImpl(String name, String unit, String description) {
|
||||||
@ -38,17 +39,20 @@ public class StatisticImpl implements Statistic, Resettable {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
this.startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
this.lastSampleTime = this.startTime;
|
this.lastSampleTime = this.startTime;
|
||||||
|
this.hasUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void reset() {
|
public synchronized void reset() {
|
||||||
if(isDoReset()) {
|
if(isDoReset()) {
|
||||||
this.startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
this.lastSampleTime = this.startTime;
|
this.lastSampleTime = this.startTime;
|
||||||
|
this.hasUpdated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void updateSampleTime() {
|
protected synchronized void updateSampleTime() {
|
||||||
this.lastSampleTime = System.currentTimeMillis();
|
this.lastSampleTime = System.currentTimeMillis();
|
||||||
|
this.hasUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String toString() {
|
public synchronized String toString() {
|
||||||
@ -101,6 +105,9 @@ public class StatisticImpl implements Statistic, Resettable {
|
|||||||
return this.doReset;
|
return this.doReset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasUpdated(){
|
||||||
|
return hasUpdated;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @param doReset the doReset to set
|
* @param doReset the doReset to set
|
||||||
*/
|
*/
|
||||||
|
@ -30,9 +30,12 @@ public class TimeStatisticTest extends StatisticTestSupport {
|
|||||||
TimeStatisticImpl stat = new TimeStatisticImpl("myTimer", "millis", "myDescription");
|
TimeStatisticImpl stat = new TimeStatisticImpl("myTimer", "millis", "myDescription");
|
||||||
assertStatistic(stat, "myTimer", "millis", "myDescription");
|
assertStatistic(stat, "myTimer", "millis", "myDescription");
|
||||||
|
|
||||||
|
assertFalse(stat.hasUpdated());
|
||||||
|
|
||||||
assertEquals(0, stat.getCount());
|
assertEquals(0, stat.getCount());
|
||||||
|
|
||||||
stat.addTime(100);
|
stat.addTime(100);
|
||||||
|
assertTrue(stat.hasUpdated());
|
||||||
assertEquals(1, stat.getCount());
|
assertEquals(1, stat.getCount());
|
||||||
assertEquals(100, stat.getMinTime());
|
assertEquals(100, stat.getMinTime());
|
||||||
assertEquals(100, stat.getMaxTime());
|
assertEquals(100, stat.getMaxTime());
|
||||||
@ -59,6 +62,7 @@ public class TimeStatisticTest extends StatisticTestSupport {
|
|||||||
LOG.info("Stat is: " + stat);
|
LOG.info("Stat is: " + stat);
|
||||||
|
|
||||||
stat.reset();
|
stat.reset();
|
||||||
|
assertFalse(stat.hasUpdated());
|
||||||
|
|
||||||
assertEquals(0, stat.getCount());
|
assertEquals(0, stat.getCount());
|
||||||
assertEquals(0, stat.getMinTime());
|
assertEquals(0, stat.getMinTime());
|
||||||
|
@ -218,6 +218,7 @@ public class BrokerStatisticsPluginTest extends TestCase{
|
|||||||
assertEquals(1, reply.getLong("size"));
|
assertEquals(1, reply.getLong("size"));
|
||||||
assertTrue(reply.getJMSTimestamp() > 0);
|
assertTrue(reply.getJMSTimestamp() > 0);
|
||||||
assertTrue(reply.getLong("firstMessageTimestamp") > 0);
|
assertTrue(reply.getLong("firstMessageTimestamp") > 0);
|
||||||
|
assertTrue(reply.getLong("lastMessageTimestamp") > 0);
|
||||||
// Assert that we got the brokerInTime for the first message in queue as value of key "firstMessageTimestamp"
|
// Assert that we got the brokerInTime for the first message in queue as value of key "firstMessageTimestamp"
|
||||||
assertTrue(System.currentTimeMillis() >= reply.getLong("firstMessageTimestamp"));
|
assertTrue(System.currentTimeMillis() >= reply.getLong("firstMessageTimestamp"));
|
||||||
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
|
assertEquals(Message.DEFAULT_PRIORITY, reply.getJMSPriority());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user