Search in sources :

Example 1 with Status

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);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 2 with Status

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);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 3 with Status

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);
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Method(java.lang.reflect.Method) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 4 with Status

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());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Level(com.alibaba.dubbo.common.status.Status.Level) Map(java.util.Map)

Example 5 with Status

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());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) Lifecycle(org.springframework.context.Lifecycle) Method(java.lang.reflect.Method) ApplicationContext(org.springframework.context.ApplicationContext)

Aggregations

Status (com.alibaba.dubbo.common.status.Status)14 Method (java.lang.reflect.Method)4 Map (java.util.Map)4 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)3 Connection (java.sql.Connection)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Level (com.alibaba.dubbo.common.status.Status.Level)2 StatusChecker (com.alibaba.dubbo.common.status.StatusChecker)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ApplicationContext (org.springframework.context.ApplicationContext)2 DataStore (com.alibaba.dubbo.common.store.DataStore)1 Page (com.alibaba.dubbo.container.page.Page)1 Registry (com.alibaba.dubbo.registry.Registry)1 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1