use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class DataSourceStatusChecker method check.
@SuppressWarnings("unchecked")
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
if (dataSources == null || dataSources.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
DataSource dataSource = entry.getValue();
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(entry.getKey());
try {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTypeInfo();
try {
if (!resultSet.next()) {
level = Status.Level.ERROR;
}
} finally {
resultSet.close();
}
buf.append(metaData.getURL());
buf.append("(");
buf.append(metaData.getDatabaseProductName());
buf.append("-");
buf.append(metaData.getDatabaseProductVersion());
buf.append(")");
} finally {
connection.close();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
return new Status(level, e.getMessage());
}
}
return new Status(level, buf.toString());
}
use of com.alibaba.dubbo.common.status.Status in project dubbo by alibaba.
the class RegistryStatusChecker method check.
public Status check() {
Collection<Registry> regsitries = AbstractRegistryFactory.getRegistries();
if (regsitries == null || regsitries.isEmpty()) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (Registry registry : regsitries) {
if (buf.length() > 0) {
buf.append(",");
}
buf.append(registry.getUrl().getAddress());
if (!registry.isAvailable()) {
level = Status.Level.ERROR;
buf.append("(disconnected)");
} else {
buf.append("(connected)");
}
}
return new Status(level, buf.toString());
}
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 StatusManager 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());
}
Aggregations