Search in sources :

Example 1 with DedupedLogEvent

use of org.apache.accumulo.server.monitor.DedupedLogEvent in project accumulo by apache.

the class StatusResource method getTables.

/**
 * Generates the JSON object with the status
 *
 * @return Status report
 */
@GET
public StatusInformation getTables() {
    StatusInformation status;
    Status masterStatus;
    Status gcStatus;
    Status tServerStatus = Status.ERROR;
    if (Monitor.getMmi() != null) {
        if (Monitor.getGcStatus() != null) {
            gcStatus = Status.OK;
        } else {
            gcStatus = Status.ERROR;
        }
        List<String> tservers = new ArrayList<>();
        for (TabletServerStatus up : Monitor.getMmi().tServerInfo) {
            tservers.add(up.name);
        }
        for (DeadServer down : Monitor.getMmi().deadTabletServers) {
            tservers.add(down.server);
        }
        List<String> masters = Monitor.getContext().getInstance().getMasterLocations();
        masterStatus = masters.size() == 0 ? Status.ERROR : Status.OK;
        int tServerUp = Monitor.getMmi().getTServerInfoSize();
        int tServerDown = Monitor.getMmi().getDeadTabletServersSize();
        int tServerBad = Monitor.getMmi().getBadTServersSize();
        /*
       * If there are no dead or bad servers and there are tservers up, status is OK, if there are dead or bad servers and there is at least a tserver up,
       * status is WARN, otherwise, the status is an error.
       */
        if ((tServerDown > 0 || tServerBad > 0) && tServerUp > 0) {
            tServerStatus = Status.WARN;
        } else if ((tServerDown == 0 || tServerBad == 0) && tServerUp > 0) {
            tServerStatus = Status.OK;
        } else if (tServerUp == 0) {
            tServerStatus = Status.ERROR;
        }
    } else {
        masterStatus = Status.ERROR;
        if (null == Monitor.getGcStatus()) {
            gcStatus = Status.ERROR;
        } else {
            gcStatus = Status.OK;
        }
        tServerStatus = Status.ERROR;
    }
    List<DedupedLogEvent> logs = LogService.getInstance().getEvents();
    boolean logsHaveError = false;
    for (DedupedLogEvent dedupedLogEvent : logs) {
        if (dedupedLogEvent.getEvent().getLevel().isGreaterOrEqual(Level.ERROR)) {
            logsHaveError = true;
            break;
        }
    }
    int numProblems = Monitor.getProblemSummary().entrySet().size();
    status = new StatusInformation(masterStatus.toString(), gcStatus.toString(), tServerStatus.toString(), logs.size(), logsHaveError, numProblems);
    return status;
}
Also used : TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) ArrayList(java.util.ArrayList) DeadServer(org.apache.accumulo.core.master.thrift.DeadServer) DedupedLogEvent(org.apache.accumulo.server.monitor.DedupedLogEvent) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) GET(javax.ws.rs.GET)

Example 2 with DedupedLogEvent

use of org.apache.accumulo.server.monitor.DedupedLogEvent in project accumulo by apache.

the class LogResource method getRecentLogs.

/**
 * Generates log event list as a JSON object
 *
 * @return log event array
 */
@GET
public List<LogEvent> getRecentLogs() {
    List<DedupedLogEvent> dedupedLogEvents = LogService.getInstance().getEvents();
    ArrayList<LogEvent> logEvents = new ArrayList<>(dedupedLogEvents.size());
    for (DedupedLogEvent dev : dedupedLogEvents) {
        LoggingEvent ev = dev.getEvent();
        Object application = ev.getMDC("application");
        if (application == null)
            application = "";
        String msg = ev.getMessage().toString();
        StringBuilder text = new StringBuilder();
        for (int i = 0; i < msg.length(); i++) {
            char c = msg.charAt(i);
            int type = Character.getType(c);
            boolean notPrintable = type == Character.UNASSIGNED || type == Character.LINE_SEPARATOR || type == Character.NON_SPACING_MARK || type == Character.PRIVATE_USE;
            text.append(notPrintable ? '?' : c);
        }
        StringBuilder builder = new StringBuilder(text.toString());
        if (ev.getThrowableStrRep() != null)
            for (String line : ev.getThrowableStrRep()) builder.append("\n\t").append(line);
        msg = sanitize(builder.toString().trim());
        // Add a new log event to the list
        logEvents.add(new LogEvent(ev.getTimeStamp(), application, dev.getCount(), ev.getLevel().toString(), msg.toString().trim()));
    }
    return logEvents;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) DedupedLogEvent(org.apache.accumulo.server.monitor.DedupedLogEvent) ArrayList(java.util.ArrayList) DedupedLogEvent(org.apache.accumulo.server.monitor.DedupedLogEvent) GET(javax.ws.rs.GET)

Aggregations

ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 DedupedLogEvent (org.apache.accumulo.server.monitor.DedupedLogEvent)2 DeadServer (org.apache.accumulo.core.master.thrift.DeadServer)1 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1