Skip to content

Commit

Permalink
ARTEMIS-5321 expose address limit percent via metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram committed Feb 25, 2025
1 parent 996d5da commit cb0adb4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public interface AddressControl {
String UNROUTED_MESSAGE_COUNT_DESCRIPTION = "number of messages not routed to any bindings";
String ADDRESS_SIZE_DESCRIPTION = "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking";
String NUMBER_OF_PAGES_DESCRIPTION = "number of pages used by this address";
String LIMIT_PERCENT_DESCRIPTION = "the % of memory limit (global or local) that is in use by this address";

/**
* Returns the managed address.
Expand Down Expand Up @@ -124,11 +125,9 @@ public interface AddressControl {

/**
* Returns the % of memory limit that is currently in use
*
* @throws Exception
*/
@Attribute(desc = "the % of memory limit (global or local) that is in use by this address")
int getAddressLimitPercent() throws Exception;
@Attribute(desc = LIMIT_PERCENT_DESCRIPTION)
int getAddressLimitPercent();

/**
* Blocks message production to this address by limiting credit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public boolean isPaging() throws Exception {
}

@Override
public int getAddressLimitPercent() throws Exception {
public int getAddressLimitPercent() {
if (AuditLogger.isBaseLoggingEnabled()) {
AuditLogger.getAddressLimitPercent(this.addressInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public void registerAddressMeters(AddressInfo addressInfo, AddressControl addres
builder.build(AddressMetricNames.UNROUTED_MESSAGE_COUNT, addressInfo, metrics -> (double) addressInfo.getUnRoutedMessageCount(), AddressControl.UNROUTED_MESSAGE_COUNT_DESCRIPTION, Collections.emptyList());
builder.build(AddressMetricNames.ADDRESS_SIZE, addressInfo, metrics -> (double) addressControl.getAddressSize(), AddressControl.ADDRESS_SIZE_DESCRIPTION, Collections.emptyList());
builder.build(AddressMetricNames.PAGES_COUNT, addressInfo, metrics -> (double) addressControl.getNumberOfPages(), AddressControl.NUMBER_OF_PAGES_DESCRIPTION, Collections.emptyList());
builder.build(AddressMetricNames.LIMIT_PERCENT, addressInfo, metrics -> (double) addressControl.getAddressLimitPercent(), AddressControl.LIMIT_PERCENT_DESCRIPTION, Collections.emptyList());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public class AddressMetricNames {
public static final String UNROUTED_MESSAGE_COUNT = "unrouted.message.count";
public static final String ADDRESS_SIZE = "address.size";
public static final String PAGES_COUNT = "number.of.pages";
public static final String LIMIT_PERCENT = "limit.percent";

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public boolean isPaging() throws Exception {
}

@Override
public int getAddressLimitPercent() throws Exception {
public int getAddressLimitPercent() {
return (int) proxy.retrieveAttributeValue("addressLimitPercent", Integer.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,13 @@ public int hashCode() {
new Metric("artemis.unrouted.message.count", 0.0, Arrays.asList(Tag.of("address", "simpleAddress"), Tag.of("broker", "localhost"))),
new Metric("artemis.address.size", 0.0, Arrays.asList(Tag.of("address", "simpleAddress"), Tag.of("broker", "localhost"))),
new Metric("artemis.number.of.pages", 0.0, Arrays.asList(Tag.of("address", "simpleAddress"), Tag.of("broker", "localhost"))),
new Metric("artemis.limit.percent", 0.0, Arrays.asList(Tag.of("address", "simpleAddress"), Tag.of("broker", "localhost"))),
// activemq.notifications metrics
new Metric("artemis.routed.message.count", 0.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost"))),
new Metric("artemis.unrouted.message.count", 2.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost"))),
new Metric("artemis.address.size", 0.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost"))),
new Metric("artemis.number.of.pages", 0.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost")))
new Metric("artemis.number.of.pages", 0.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost"))),
new Metric("artemis.limit.percent", 0.0, Arrays.asList(Tag.of("address", "activemq.notifications"), Tag.of("broker", "localhost")))
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ public void testScale0_1() throws Exception {
int usage = addressControl1.getAddressLimitPercent();
System.out.println("Node1 (head) usage % " + usage);
return usage > 10;
} catch (javax.management.InstanceNotFoundException notYetReadyExpected) {
} catch (Exception e) {
if (!(e.getCause() instanceof javax.management.InstanceNotFoundException)) {
throw e;
}
}
return false;
}, 5000, 200), "Producer is on Head, Node1");
Expand Down Expand Up @@ -560,7 +563,10 @@ public void testScale0_1_CombinedProducerConsumerConnectionWithProducerRole() th
int usage = addressControl0.getAddressLimitPercent();
System.out.println("Head&Tail usage % " + usage);
return usage == 100;
} catch (javax.management.InstanceNotFoundException notYetReadyExpected) {
} catch (Exception e) {
if (!(e.getCause() instanceof javax.management.InstanceNotFoundException)) {
throw e;
}
}
return false;
}, 10000, 200));
Expand Down Expand Up @@ -659,7 +665,10 @@ public void testScale0_1_CombinedRoleConnection() throws Exception {
int usage = addressControl0.getAddressLimitPercent();
System.out.println("Head&Tail usage % " + usage);
return usage == 100;
} catch (javax.management.InstanceNotFoundException notYetReadyExpected) {
} catch (Exception e) {
if (!(e.getCause() instanceof javax.management.InstanceNotFoundException)) {
throw e;
}
}
return false;
}, 20000, 200));
Expand Down

0 comments on commit cb0adb4

Please sign in to comment.