Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;

import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.metrics2.MetricsCollector;
import org.apache.hadoop.metrics2.MetricsSource;
import org.apache.hadoop.metrics2.MetricsSystem;
Expand Down Expand Up @@ -66,6 +67,11 @@ public void unRegister() {
public void getMetrics(MetricsCollector collector, boolean all) {
Map<String, Integer> stateCount = scmmxBean.getContainerStateCount();

int totalContainers = 0;
for (HddsProtos.LifeCycleState state : HddsProtos.LifeCycleState.values()) {
totalContainers = totalContainers + stateCount.get(state.toString());
}

collector.addRecord(SOURCE)
.addGauge(Interns.info("OpenContainers",
"Number of open containers"),
Expand All @@ -84,6 +90,9 @@ public void getMetrics(MetricsCollector collector, boolean all) {
stateCount.get(DELETING.toString()))
.addGauge(Interns.info("DeletedContainers",
"Number of containers in deleted state"),
stateCount.get(DELETED.toString()));
stateCount.get(DELETED.toString()))
.addGauge(Interns.info("TotalContainers",
"Number of all containers"),
totalContainers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ public void testSCMContainerMetrics() {
"Number of containers in deleting state"), 6);
verify(mb, times(1)).addGauge(Interns.info("DeletedContainers",
"Number of containers in deleted state"), 7);
verify(mb, times(1)).addGauge(Interns.info("TotalContainers",
"Number of all containers"), 27);
}
}