-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJMX.java
91 lines (58 loc) · 2.66 KB
/
JMX.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.JMX;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
public class Main {
public static void main(String args[])throws Exception {
try {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://[172.20.22.6]:7199/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
Set<ObjectInstance> objs = mbsc.queryMBeans(ObjectName.getInstance("org.apache.cassandra.metrics:type=Table,name=ViewLockAcquireTime"), null);
for (ObjectInstance obj : objs) {
Object proxy = JMX.newMBeanProxy(mbsc, obj.getObjectName(),CassandraMetricsRegistry.JmxTimerMBean.class);
if (proxy instanceof CassandraMetricsRegistry.JmxTimerMBean) {
System.out.println(((CassandraMetricsRegistry.JmxTimerMBean) proxy).get50thPercentile());
}
}
jmxc.close();
}
catch (Exception e) {
e.printStackTrace();
}
while (true) {
}
}
}
import java.util.HashMap;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class Main {
public static void main( String[] args ) throws Exception {
String node = args[0];
String port = args[1];
String username = args[2];
String password = args[3];
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://" + node + ":" + port + "/jmxrmi" );
String[] credentials = {username, password};
Map<String, String[]> environment = new HashMap<>();
environment.put( JMXConnector.CREDENTIALS, credentials );
JMXConnector jmxConnector = JMXConnectorFactory.connect( url, environment );
MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();//Get metrics bean
ObjectName oName = new ObjectName( "org.apache.cassandra.net:type=FailureDetector" );//create JMX object name
int downNodes = (int) mbsc.getAttribute( oName, "DownEndpointCount" ); //get number of unavailable nodes
System.out.println("Down node count: " + downNodes);
}
}