Search in sources :

Example 1 with RequestCounter

use of voldemort.store.stats.RequestCounter in project voldemort by voldemort.

the class StatusServlet method outputJSON.

protected void outputJSON(HttpServletResponse response) {
    StringBuilder sb = new StringBuilder("{\n");
    sb.append("  \"servertime\": \"");
    sb.append(new Date());
    sb.append("\",");
    sb.append("\n  \"server\": \"");
    sb.append(myMachine);
    sb.append("\",");
    sb.append("\n  \"node\": \"");
    sb.append(server.getMetadataStore().getNodeId());
    sb.append("\",");
    sb.append("\n  \"uptime\": \"");
    sb.append(abstractSocketService.getStatusManager().getFormattedUptime());
    sb.append("\",");
    sb.append("\n  \"num_workers\": ");
    sb.append(abstractSocketService.getStatusManager().getActiveWorkersCount());
    sb.append(",");
    sb.append("\n  \"pool_size\": ");
    sb.append(abstractSocketService.getStatusManager().getWorkerPoolSize());
    sb.append(",");
    sb.append("\n  \"stores\": {");
    int i = 0;
    for (Store<ByteArray, byte[], byte[]> store : server.getStoreRepository().getAllLocalStores()) {
        if (i++ > 0) {
            sb.append(",");
        }
        sb.append("\n    \"");
        sb.append(store.getName());
        sb.append("\" : {\n");
        if (store instanceof StatTrackingStore) {
            StatTrackingStore statStore = (StatTrackingStore) store;
            Map<Tracked, RequestCounter> stats = statStore.getStats().getCounters();
            for (Tracked t : Tracked.values()) {
                if (t == Tracked.EXCEPTION) {
                    continue;
                }
                sb.append(fillCommonStats(stats, t));
            }
            sb.append(",\n        \"num_exceptions\": ");
            sb.append(statStore.getStats().getCount(Tracked.EXCEPTION));
            sb.append("\n");
            sb.append("    }");
        }
        if (store instanceof QuotaLimitingStore) {
            QuotaLimitingStore quotaStore = (QuotaLimitingStore) store;
            Map<Tracked, RequestCounter> stats = quotaStore.getStats().getCounters();
            for (Tracked t : Tracked.values()) {
                if (t == Tracked.EXCEPTION) {
                    continue;
                }
                sb.append(fillCommonStats(stats, t));
            }
            sb.append(",\n        \"num_exceptions\": ");
            sb.append(quotaStore.getStats().getCount(Tracked.EXCEPTION));
            sb.append("\n");
            sb.append("    }");
        }
    }
    sb.append("\n  }\n");
    sb.append("}\n");
    try {
        response.setContentType("text/plain");
        OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
        writer.write(sb.toString());
        writer.flush();
    } catch (Exception e) {
        throw new VoldemortException(e);
    }
}
Also used : VoldemortException(voldemort.VoldemortException) Date(java.util.Date) ServletException(javax.servlet.ServletException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StatTrackingStore(voldemort.store.stats.StatTrackingStore) Tracked(voldemort.store.stats.Tracked) RequestCounter(voldemort.store.stats.RequestCounter) ByteArray(voldemort.utils.ByteArray) QuotaLimitingStore(voldemort.store.quota.QuotaLimitingStore) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnknownHostException (java.net.UnknownHostException)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1 VoldemortException (voldemort.VoldemortException)1 QuotaLimitingStore (voldemort.store.quota.QuotaLimitingStore)1 RequestCounter (voldemort.store.stats.RequestCounter)1 StatTrackingStore (voldemort.store.stats.StatTrackingStore)1 Tracked (voldemort.store.stats.Tracked)1 ByteArray (voldemort.utils.ByteArray)1