use of javax.management.openmbean.CompositeData in project neo4j by neo4j.
the class Dbinfo method printAttribute.
private void printAttribute(JSONObject json, Object value) throws RemoteException, ShellException {
try {
Attribute attribute = (Attribute) value;
Object attributeValue = attribute.getValue();
if (attributeValue != null && attributeValue.getClass().isArray()) {
Object[] arrayValue = (Object[]) attributeValue;
JSONArray array = new JSONArray();
for (Object item : (Object[]) arrayValue) {
if (item instanceof CompositeData) {
array.put(compositeDataAsMap((CompositeData) item));
} else {
array.put(item.toString());
}
}
json.put(attribute.getName(), array);
} else {
json.put(attribute.getName(), attributeValue);
}
} catch (JSONException e) {
throw ShellException.wrapCause(e);
}
}
use of javax.management.openmbean.CompositeData in project cassandra by apache.
the class ColumnFamilyStoreMBeanIterator method getPartitionSample.
public Map<Sampler, CompositeData> getPartitionSample(String ks, String cf, int capacity, int duration, int count, List<Sampler> samplers) throws OpenDataException {
ColumnFamilyStoreMBean cfsProxy = getCfsProxy(ks, cf);
for (Sampler sampler : samplers) {
cfsProxy.beginLocalSampling(sampler.name(), capacity);
}
Uninterruptibles.sleepUninterruptibly(duration, TimeUnit.MILLISECONDS);
Map<Sampler, CompositeData> result = Maps.newHashMap();
for (Sampler sampler : samplers) {
result.put(sampler, cfsProxy.finishLocalSampling(sampler.name(), count));
}
return result;
}
use of javax.management.openmbean.CompositeData in project cassandra by apache.
the class FailureDetectorInfo method execute.
@Override
public void execute(NodeProbe probe) {
TabularData data = probe.getFailureDetectorPhilValues();
System.out.printf("%10s,%16s%n", "Endpoint", "Phi");
for (Object o : data.keySet()) {
@SuppressWarnings({ "rawtypes", "unchecked" }) CompositeData datum = data.get(((List) o).toArray(new Object[((List) o).size()]));
System.out.printf("%10s,%16.8f%n", datum.get("Endpoint"), datum.get("PHI"));
}
}
use of javax.management.openmbean.CompositeData in project cassandra by apache.
the class TopPartitions method execute.
@Override
public void execute(NodeProbe probe) {
checkArgument(args.size() == 3, "toppartitions requires keyspace, column family name, and duration");
checkArgument(topCount < size, "TopK count (-k) option must be smaller then the summary capacity (-s)");
String keyspace = args.get(0);
String cfname = args.get(1);
Integer duration = Integer.valueOf(args.get(2));
// generate the list of samplers
List<Sampler> targets = Lists.newArrayList();
for (String s : samplers.split(",")) {
try {
targets.add(Sampler.valueOf(s.toUpperCase()));
} catch (Exception e) {
throw new IllegalArgumentException(s + " is not a valid sampler, choose one of: " + join(Sampler.values(), ", "));
}
}
Map<Sampler, CompositeData> results;
try {
results = probe.getPartitionSample(keyspace, cfname, size, duration, topCount, targets);
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
boolean first = true;
for (Entry<Sampler, CompositeData> result : results.entrySet()) {
CompositeData sampling = result.getValue();
// weird casting for http://bugs.sun.com/view_bug.do?bug_id=6548436
List<CompositeData> topk = (List<CompositeData>) (Object) Lists.newArrayList(((TabularDataSupport) sampling.get("partitions")).values());
Collections.sort(topk, new Ordering<CompositeData>() {
public int compare(CompositeData left, CompositeData right) {
return Long.compare((long) right.get("count"), (long) left.get("count"));
}
});
if (!first)
System.out.println();
System.out.println(result.getKey().toString() + " Sampler:");
System.out.printf(" Cardinality: ~%d (%d capacity)%n", sampling.get("cardinality"), size);
System.out.printf(" Top %d partitions:%n", topCount);
if (topk.size() == 0) {
System.out.println("\tNothing recorded during sampling period...");
} else {
int offset = 0;
for (CompositeData entry : topk) offset = Math.max(offset, entry.get("string").toString().length());
System.out.printf("\t%-" + offset + "s%10s%10s%n", "Partition", "Count", "+/-");
for (CompositeData entry : topk) System.out.printf("\t%-" + offset + "s%10d%10d%n", entry.get("string").toString(), entry.get("count"), entry.get("error"));
}
first = false;
}
}
use of javax.management.openmbean.CompositeData in project twitter4j by yusuke.
the class MBeansTest method testAPIStatisticsOpenMBean.
/**
* Tests exposure of API statistics via a dynamic MBean
*/
public void testAPIStatisticsOpenMBean() throws Exception {
APIStatistics stats = new APIStatistics(5);
APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(stats);
// sanity check to ensure metadata accurately describes dynamic attributes
MBeanInfo info = openMBean.getMBeanInfo();
assertEquals(5, info.getAttributes().length);
assertEquals(1, info.getOperations().length);
List<String> attrNames = new ArrayList<String>();
for (MBeanAttributeInfo attr : info.getAttributes()) {
assertNotNull(openMBean.getAttribute(attr.getName()));
attrNames.add(attr.getName());
}
AttributeList attrList = openMBean.getAttributes(attrNames.toArray(new String[attrNames.size()]));
assertNotNull(attrList);
assertEquals(5, attrList.size());
// check stats (empty case)
Long callCount = (Long) openMBean.getAttribute("callCount");
assertEquals(0, callCount.longValue());
Long errorCount = (Long) openMBean.getAttribute("errorCount");
assertEquals(0, callCount.longValue());
Long totalTime = (Long) openMBean.getAttribute("totalTime");
assertEquals(0, totalTime.longValue());
Long averageTime = (Long) openMBean.getAttribute("averageTime");
assertEquals(0, averageTime.longValue());
// check table (empty case)
TabularData table = (TabularData) openMBean.getAttribute("statisticsTable");
assertTrue(table.isEmpty());
stats.methodCalled("foo", 100, true);
// check stats (populated case)
callCount = (Long) openMBean.getAttribute("callCount");
assertEquals(1, callCount.longValue());
errorCount = (Long) openMBean.getAttribute("errorCount");
assertEquals(0, errorCount.longValue());
totalTime = (Long) openMBean.getAttribute("totalTime");
assertEquals(100, totalTime.longValue());
averageTime = (Long) openMBean.getAttribute("averageTime");
assertEquals(100, averageTime.longValue());
// check table (populated case)
table = (TabularData) openMBean.getAttribute("statisticsTable");
assertFalse(table.isEmpty());
assertEquals(1, table.keySet().size());
CompositeData data = table.get(new Object[] { "foo" });
assertNotNull(data);
String[] columnNames = new String[] { "methodName", "callCount", "totalTime", "avgTime" };
Object[] columnValues = data.getAll(columnNames);
assertEquals(columnNames.length, columnValues.length);
assertEquals("foo", columnValues[0]);
assertEquals(1, ((Long) columnValues[1]).longValue());
assertEquals(100, ((Long) columnValues[2]).longValue());
assertEquals(100, ((Long) columnValues[3]).longValue());
// check reset
openMBean.invoke("reset", new Object[0], new String[0]);
checkCalculator(stats, 0, 0, 0, 0);
assertFalse(stats.getInvocationStatistics().iterator().hasNext());
}
Aggregations