use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class DatabaseStatusChecker method check.
public Status check() {
boolean ok;
try {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTypeInfo();
try {
ok = resultSet.next();
} finally {
resultSet.close();
}
if (message == null) {
message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
}
if (version == 0) {
version = metaData.getDatabaseMajorVersion();
}
} finally {
connection.close();
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
ok = false;
}
return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class DatabaseStatusChecker method check.
public Status check() {
boolean ok;
try {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTypeInfo();
try {
ok = resultSet.next();
} finally {
resultSet.close();
}
if (message == null) {
message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")";
}
if (version == 0) {
version = metaData.getDatabaseMajorVersion();
}
} finally {
connection.close();
}
} catch (Throwable e) {
logger.error(e.getMessage(), e);
ok = false;
}
return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message);
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class LoadStatusChecker method check.
public Status check() {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double load;
try {
Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
} catch (Throwable e) {
load = -1;
}
int cpu = operatingSystemMXBean.getAvailableProcessors();
return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class StatusUtils method getSummaryStatus.
public static Status getSummaryStatus(Map<String, Status> statuses) {
Level level = Level.OK;
StringBuilder msg = new StringBuilder();
for (Map.Entry<String, Status> entry : statuses.entrySet()) {
String key = entry.getKey();
Status status = entry.getValue();
Level l = status.getLevel();
if (Level.ERROR.equals(l)) {
level = Level.ERROR;
if (msg.length() > 0) {
msg.append(",");
}
msg.append(key);
} else if (Level.WARN.equals(l)) {
if (!Level.ERROR.equals(level)) {
level = Level.WARN;
}
if (msg.length() > 0) {
msg.append(",");
}
msg.append(key);
}
}
return new Status(level, msg.toString());
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class SpringStatusChecker method check.
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
if (context instanceof Lifecycle) {
if (((Lifecycle) context).isRunning()) {
level = Status.Level.OK;
} else {
level = Status.Level.ERROR;
}
} else {
level = Status.Level.UNKNOWN;
}
StringBuilder buf = new StringBuilder();
try {
Class<?> cls = context.getClass();
Method method = null;
while (cls != null && method == null) {
try {
method = cls.getDeclaredMethod("getConfigLocations", new Class<?>[0]);
} catch (NoSuchMethodException t) {
cls = cls.getSuperclass();
}
}
if (method != null) {
if (!method.isAccessible()) {
method.setAccessible(true);
}
String[] configs = (String[]) method.invoke(context, new Object[0]);
if (configs != null && configs.length > 0) {
for (String config : configs) {
if (buf.length() > 0) {
buf.append(",");
}
buf.append(config);
}
}
}
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
}
return new Status(level, buf.toString());
}
Aggregations