use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.
the class DataSourceProxyImpl method getCompositeData.
public CompositeDataSupport getCompositeData() throws JMException {
JdbcDataSourceStat stat = this.getDataSourceStat();
Map<String, Object> map = new HashMap<String, Object>();
map.put("ID", id);
map.put("URL", this.getUrl());
map.put("Name", this.getName());
map.put("FilterClasses", getFilterClasses());
map.put("CreatedTime", getCreatedTime());
map.put("RawDriverClassName", getRawDriverClassName());
map.put("RawUrl", getRawUrl());
map.put("RawDriverMajorVersion", getRawDriverMajorVersion());
map.put("RawDriverMinorVersion", getRawDriverMinorVersion());
map.put("Properties", getProperties());
if (stat != null) {
map.put("ConnectionActiveCount", stat.getConnectionActiveCount());
map.put("ConnectionActiveCountMax", stat.getConnectionStat().getActiveMax());
map.put("ConnectionCloseCount", stat.getConnectionStat().getCloseCount());
map.put("ConnectionCommitCount", stat.getConnectionStat().getCommitCount());
map.put("ConnectionRollbackCount", stat.getConnectionStat().getRollbackCount());
map.put("ConnectionConnectLastTime", stat.getConnectionStat().getConnectLastTime());
map.put("ConnectionConnectErrorCount", stat.getConnectionStat().getConnectErrorCount());
Throwable lastConnectionConnectError = stat.getConnectionStat().getConnectErrorLast();
if (lastConnectionConnectError != null) {
map.put("ConnectionConnectErrorLastTime", stat.getConnectionStat().getErrorLastTime());
map.put("ConnectionConnectErrorLastMessage", lastConnectionConnectError.getMessage());
map.put("ConnectionConnectErrorLastStackTrace", Utils.getStackTrace(lastConnectionConnectError));
} else {
map.put("ConnectionConnectErrorLastTime", null);
map.put("ConnectionConnectErrorLastMessage", null);
map.put("ConnectionConnectErrorLastStackTrace", null);
}
map.put("StatementCreateCount", stat.getStatementStat().getCreateCount());
map.put("StatementPrepareCount", stat.getStatementStat().getPrepareCount());
map.put("StatementPreCallCount", stat.getStatementStat().getPrepareCallCount());
map.put("StatementExecuteCount", stat.getStatementStat().getExecuteCount());
map.put("StatementRunningCount", stat.getStatementStat().getRunningCount());
map.put("StatementConcurrentMax", stat.getStatementStat().getConcurrentMax());
map.put("StatementCloseCount", stat.getStatementStat().getCloseCount());
map.put("StatementErrorCount", stat.getStatementStat().getErrorCount());
Throwable lastStatementError = stat.getStatementStat().getLastException();
if (lastStatementError != null) {
map.put("StatementLastErrorTime", stat.getStatementStat().getLastErrorTime());
map.put("StatementLastErrorMessage", lastStatementError.getMessage());
map.put("StatementLastErrorStackTrace", Utils.getStackTrace(lastStatementError));
} else {
map.put("StatementLastErrorTime", null);
map.put("StatementLastErrorMessage", null);
map.put("StatementLastErrorStackTrace", null);
}
map.put("StatementExecuteMillisTotal", stat.getStatementStat().getMillisTotal());
map.put("StatementExecuteLastTime", stat.getStatementStat().getExecuteLastTime());
map.put("ConnectionConnectingCount", stat.getConnectionStat().getConnectingCount());
map.put("ResultSetCloseCount", stat.getResultSetStat().getCloseCount());
map.put("ResultSetOpenCount", stat.getResultSetStat().getOpenCount());
map.put("ResultSetOpenningCount", stat.getResultSetStat().getOpeningCount());
map.put("ResultSetOpenningMax", stat.getResultSetStat().getOpeningMax());
map.put("ResultSetFetchRowCount", stat.getResultSetStat().getFetchRowCount());
map.put("ResultSetLastOpenTime", stat.getResultSetStat().getLastOpenTime());
map.put("ResultSetErrorCount", stat.getResultSetStat().getErrorCount());
map.put("ResultSetOpenningMillisTotal", stat.getResultSetStat().getAliveMillisTotal());
map.put("ResultSetLastErrorTime", stat.getResultSetStat().getLastErrorTime());
Throwable lastResultSetError = stat.getResultSetStat().getLastError();
if (lastResultSetError != null) {
map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
map.put("ResultSetLastErrorStackTrace", Utils.getStackTrace(lastResultSetError));
} else {
map.put("ResultSetLastErrorMessage", null);
map.put("ResultSetLastErrorStackTrace", null);
}
map.put("ConnectionConnectCount", stat.getConnectionStat().getConnectCount());
Throwable lastConnectionError = stat.getConnectionStat().getErrorLast();
if (lastConnectionError != null) {
map.put("ConnectionErrorLastMessage", lastConnectionError.getMessage());
map.put("ConnectionErrorLastStackTrace", Utils.getStackTrace(lastConnectionError));
} else {
map.put("ConnectionErrorLastMessage", null);
map.put("ConnectionErrorLastStackTrace", null);
}
map.put("ConnectionConnectMillisTotal", stat.getConnectionStat().getConnectMillis());
map.put("ConnectionConnectingCountMax", stat.getConnectionStat().getConnectingMax());
map.put("ConnectionConnectMillisMax", stat.getConnectionStat().getConnectMillisMax());
map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
} else {
map.put("ConnectionActiveCount", null);
map.put("ConnectionActiveCountMax", null);
map.put("ConnectionCloseCount", null);
map.put("ConnectionCommitCount", null);
map.put("ConnectionRollbackCount", null);
map.put("ConnectionConnectLastTime", null);
map.put("ConnectionConnectErrorCount", null);
map.put("ConnectionConnectErrorLastTime", null);
map.put("ConnectionConnectErrorLastMessage", null);
map.put("ConnectionConnectErrorLastStackTrace", null);
map.put("StatementCreateCount", null);
map.put("StatementPrepareCount", null);
map.put("StatementPreCallCount", null);
map.put("StatementExecuteCount", null);
map.put("StatementRunningCount", null);
map.put("StatementConcurrentMax", null);
map.put("StatementCloseCount", null);
map.put("StatementErrorCount", null);
map.put("StatementLastErrorTime", null);
map.put("StatementLastErrorMessage", null);
map.put("StatementLastErrorStackTrace", null);
map.put("StatementExecuteMillisTotal", null);
map.put("ConnectionConnectingCount", null);
map.put("StatementExecuteLastTime", null);
map.put("ResultSetCloseCount", null);
map.put("ResultSetOpenCount", null);
map.put("ResultSetOpenningCount", null);
map.put("ResultSetOpenningMax", null);
map.put("ResultSetFetchRowCount", null);
map.put("ResultSetLastOpenTime", null);
map.put("ResultSetErrorCount", null);
map.put("ResultSetOpenningMillisTotal", null);
map.put("ResultSetLastErrorTime", null);
map.put("ResultSetLastErrorMessage", null);
map.put("ResultSetLastErrorStackTrace", null);
map.put("ConnectionConnectCount", null);
map.put("ConnectionErrorLastMessage", null);
map.put("ConnectionErrorLastStackTrace", null);
map.put("ConnectionConnectMillisTotal", null);
map.put("ConnectionConnectingCountMax", null);
map.put("ConnectionConnectMillisMax", null);
map.put("ConnectionErrorLastTime", null);
map.put("ConnectionAliveMillisMax", null);
map.put("ConnectionAliveMillisMin", null);
map.put("ConnectionHistogram", new long[0]);
map.put("StatementHistogram", new long[0]);
}
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
}
use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.
the class JdbcStatManager method getSqlList.
@Override
public TabularData getSqlList() throws JMException {
CompositeType rowType = JdbcSqlStat.getCompositeType();
String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames);
TabularData data = new TabularDataSupport(tabularType);
JdbcDataSourceStat globalStat = JdbcDataSourceStat.getGlobal();
if (globalStat != null) {
Map<String, JdbcSqlStat> statMap = globalStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", globalStat.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
for (DataSourceProxyImpl dataSource : DruidDriver.getProxyDataSources().values()) {
JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
if (druidDataSourceStat == globalStat) {
continue;
}
Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", dataSource.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
if (druidDataSourceStat == globalStat) {
continue;
}
Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
continue;
}
Map<String, Object> map = entry.getValue().getData();
map.put("URL", dataSource.getUrl());
data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
}
}
return data;
}
use of javax.management.openmbean.CompositeDataSupport in project jmxtrans by jmxtrans.
the class JmxResultProcessor method getResult.
/**
* Populates the Result objects. This is a recursive function. Query
* contains the keys that we want to get the values of.
*/
private void getResult(Builder<Result> accumulator, String attributeName, CompositeData cds) {
CompositeType t = cds.getCompositeType();
Map<String, Object> values = newHashMap();
Set<String> keys = t.keySet();
for (String key : keys) {
Object value = cds.get(key);
if (value instanceof TabularDataSupport) {
TabularDataSupport tds = (TabularDataSupport) value;
processTabularDataSupport(accumulator, attributeName + "." + key, tds);
// continue because we added tabular contents within above, but need primitives at this level
} else if (value instanceof CompositeDataSupport) {
// now recursively go through everything.
CompositeDataSupport cds2 = (CompositeDataSupport) value;
getResult(accumulator, attributeName, cds2);
// because we don't want to add to the list yet.
return;
} else {
values.put(key, value);
}
}
Result r = getNewResultObject(attributeName, values);
accumulator.add(r);
}
use of javax.management.openmbean.CompositeDataSupport in project nhin-d by DirectProject.
the class DNSServer method registerMBean.
/**
* Register the MBean
*/
private void registerMBean(DNSServerSettings settings) {
String[] itemNames = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
String[] itemDesc = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
OpenType<?>[] types = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER };
Object[] settingsValues = { settings.getPort(), settings.getBindAddress(), settings.getMaxRequestSize(), settings.getMaxOutstandingAccepts(), settings.getMaxActiveRequests(), settings.getMaxConnectionBacklog(), settings.getReadBufferSize(), settings.getSendTimeout(), settings.getReceiveTimeout(), settings.getSocketCloseTimeout() };
try {
CompositeType settingsType = new CompositeType(DNSServerSettings.class.getSimpleName(), "DNS server settings.", itemNames, itemDesc, types);
settingsData = new CompositeDataSupport(settingsType, itemNames, settingsValues);
} catch (OpenDataException e) {
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
return;
}
Class<?> clazz = this.getClass();
final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
objectNameBuilder.append(":type=").append(clazz.getSimpleName());
objectNameBuilder.append(",name=").append(UUID.randomUUID());
try {
final StandardMBean mbean = new StandardMBean(this, DNSServerMBean.class);
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
} catch (JMException e) {
LOGGER.error("Unable to register the DNSServer MBean", e);
}
}
use of javax.management.openmbean.CompositeDataSupport in project jdk8u_jdk by JetBrains.
the class CompositeDataStringTest method main.
public static void main(String[] args) throws Exception {
CompositeType basicCT = new CompositeType("basicCT", "basic CompositeType", new String[] { "name", "value" }, new String[] { "name", "value" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER });
CompositeType ct = new CompositeType("noddy", "descr", new String[] { "strings", "ints", "cds" }, new String[] { "string array", "int array", "composite data array" }, new OpenType<?>[] { ArrayType.getArrayType(SimpleType.STRING), ArrayType.getPrimitiveArrayType(int[].class), ArrayType.getArrayType(basicCT) });
CompositeData basicCD1 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "ceathar", 4 });
CompositeData basicCD2 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "naoi", 9 });
CompositeData cd = new CompositeDataSupport(ct, new String[] { "strings", "ints", "cds" }, new Object[] { new String[] { "fred", "jim", "sheila" }, new int[] { 2, 3, 5, 7 }, new CompositeData[] { basicCD1, basicCD2 } });
String s = cd.toString();
System.out.println("CompositeDataSupport.toString(): " + s);
String[] expected = { "fred, jim, sheila", "2, 3, 5, 7", "ceathar", "naoi" };
boolean ok = true;
for (String expect : expected) {
if (s.contains(expect))
System.out.println("OK: string contains <" + expect + ">");
else {
ok = false;
System.out.println("NOT OK: string does not contain <" + expect + ">");
}
}
if (ok)
System.out.println("TEST PASSED");
else
throw new Exception("TEST FAILED: string did not contain expected substrings");
}
Aggregations