maedhroz commented on code in PR #3742:
URL: https://github.com/apache/cassandra/pull/3742#discussion_r1887388760
##########
src/java/org/apache/cassandra/tools/NodeProbe.java:
##########
@@ -1892,7 +1892,66 @@ public Object getThreadPoolMetric(String pathName,
String poolName, String metri
}
}
- /**
+ public Object getSAIIndexMetrics(String ks, String cf, String metricName) {
+ try {
+ String scope = getScopeForMetric(metricName);
+ String objectNameStr =
String.format("org.apache.cassandra.metrics:type=StorageAttachedIndex,keyspace=%s,table=%s,scope=%s,name=%s",ks,
cf, scope, metricName);
+ ObjectName oName = new ObjectName(objectNameStr);
+
+ Set<ObjectName> matchingMBeans = mbeanServerConn.queryNames(oName,
null);
+ if (matchingMBeans.isEmpty()) {
+ return null;
+ }
+
+ return getMetricValue(metricName, oName);
+ } catch (MalformedObjectNameException e) {
+ throw new RuntimeException("Invalid ObjectName format: " +
e.getMessage(), e);
+ } catch (IOException e) {
+ throw new RuntimeException("Error accessing MBean server: " +
e.getMessage(), e);
+ }
+ }
+
+ private Object getMetricValue(String metricName, ObjectName oName) throws
IOException {
+ switch (metricName) {
+ case "QueryLatency":
+ return JMX.newMBeanProxy(mbeanServerConn, oName,
CassandraMetricsRegistry.JmxTimerMBean.class);
+ case "PostFilteringReadLatency":
+ case "SSTableIndexesHit":
+ case "IndexSegmentsHit":
+ case "RowsFiltered":
+ return JMX.newMBeanProxy(mbeanServerConn, oName,
CassandraMetricsRegistry.JmxHistogramMBean.class);
+ case "DiskUsedBytes":
+ case "TotalIndexCount":
+ case "TotalQueryableIndexCount":
+ return JMX.newMBeanProxy(mbeanServerConn, oName,
CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
+ case "TotalQueryTimeouts":
+ return JMX.newMBeanProxy(mbeanServerConn, oName,
CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
+ default:
+ throw new IllegalArgumentException("Unknown metric name: " +
metricName);
+ }
+ }
+
+ private String getScopeForMetric(String metricName) {
+ switch (metricName) {
+ case "QueryLatency":
+ case "SSTableIndexesHit":
+ case "IndexSegmentsHit":
+ case "RowsFiltered":
+ return "PerQuery";
+ case "PostFilteringReadLatency":
+ case "TotalQueryTimeouts":
+ return "TableQueryMetrics";
Review Comment:
We already have `TableQueryMetrics.TABLE_QUERY_METRIC_TYPE` and
`TableStateMetrics.TABLE_STATE_METRIC_TYPE` that we can reuse here, but I feel
like it would be a good time to do something similar for "IndexGroupMetrics"
(in `IndexGroupMetrics`) and "PerQuery" (in `PerQueryMetrics`).
I wouldn't say we have to extend this to the individual metric names, as we
shouldn't be changing those anyway (with them being a user-facing thing).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]