maedhroz commented on code in PR #3742:
URL: https://github.com/apache/cassandra/pull/3742#discussion_r1887470333


##########
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) {

Review Comment:
   nit: { on newline



-- 
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]

Reply via email to