Search in sources :

Example 1 with TableCount

use of io.datarouter.nodewatch.storage.tablecount.TableCount in project datarouter by hotpads.

the class TableCountHandler method singleTable.

@Handler
private Mav singleTable(String clientName, String tableName) {
    ZoneId userZoneId = getUserZoneId();
    Mav mav = new Mav(files.jsp.datarouter.nodewatch.singleTableCountsJsp);
    mav.put("clientName", clientName);
    mav.put("tableName", tableName);
    List<TableCount> results = tableCountDao.getForTable(clientName, tableName);
    Collections.sort(results, new TableCount.TableCountLatestEntryComparator());
    mav.put("results", Scanner.of(results).map(count -> new TableCountJspDto(count, userZoneId)).list());
    mav.put("jsonData", getRowCountData(clientName, tableName));
    return mav;
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) Mav(io.datarouter.web.handler.mav.Mav) ZoneId(java.time.ZoneId) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with TableCount

use of io.datarouter.nodewatch.storage.tablecount.TableCount in project datarouter by hotpads.

the class TableSamplerService method getCurrentTableCountFromSamples.

public TableCount getCurrentTableCountFromSamples(String clientName, String tableName) {
    // not distinguishing sub-entities at the moment
    TableSampleKey clientTablePrefix = new TableSampleKey(clientName, tableName, null, null);
    long totalRows = 0;
    long totalCountTimeMs = 0;
    long numSpans = 0;
    long numSlowSpans = 0;
    for (TableSample sample : tableSampleDao.scanWithPrefix(clientTablePrefix).iterable()) {
        totalRows += sample.getNumRows();
        totalCountTimeMs += sample.getCountTimeMs();
        numSpans++;
        if (sample.getCountTimeMs() > COUNT_TIME_MS_SLOW_SPAN_THRESHOLD) {
            numSlowSpans++;
        }
    }
    logger.info("total of {} rows for {}.{}", totalRows, clientName, tableName);
    return new TableCount(clientName, tableName, System.currentTimeMillis(), totalRows, totalCountTimeMs, numSpans, numSlowSpans);
}
Also used : TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount) TableSample(io.datarouter.nodewatch.storage.tablesample.TableSample) TableSampleKey(io.datarouter.nodewatch.storage.tablesample.TableSampleKey)

Example 3 with TableCount

use of io.datarouter.nodewatch.storage.tablecount.TableCount in project datarouter by hotpads.

the class TableSizeMonitoringService method getAboveThresholdLists.

public Twin<List<CountStat>> getAboveThresholdLists() {
    List<CountStat> aboveThresholdList = new ArrayList<>();
    List<CountStat> abovePercentageList = new ArrayList<>();
    for (PhysicalNode<?, ?, ?> node : datarouterNodes.getWritableNodes(clients.getClientIds())) {
        ClientTableEntityPrefixNameWrapper nodeNames = new ClientTableEntityPrefixNameWrapper(node);
        String tableName = nodeNames.getTableName();
        String clientName = nodeNames.getClientName();
        NodewatchConfiguration nodeConfig = null;
        Long threshold = null;
        boolean enablePercentChangeAlert = true;
        boolean enableThresholdAlert = true;
        nodeConfig = tableConfigurationService.getTableConfigMap().get(nodeNames);
        if (nodeConfig != null) {
            threshold = nodeConfig.maxThreshold;
            enablePercentChangeAlert = nodeConfig.enablePercentageAlert;
            enableThresholdAlert = nodeConfig.enableThresholdAlert;
        }
        // continue if the nodeConfig isCountable is set to false
        if (nodeConfig != null && !nodeConfig.isCountable) {
            continue;
        }
        List<TableCount> tableCountRecords = tableCountDao.getForTable(clientName, tableName);
        if (tableCountRecords.size() < 2) {
            continue;
        }
        Collections.sort(tableCountRecords, new TableCount.TableCountLatestEntryComparator());
        TableCount latest = tableCountRecords.get(0);
        TableCount previous = tableCountRecords.get(1);
        if (previous.getNumRows() == 0) {
            continue;
        }
        // skip if the table has records less than the count_threshold
        if (smallEnoughToIgnore(latest.getNumRows()) && smallEnoughToIgnore(previous.getNumRows())) {
            continue;
        }
        if (enableThresholdAlert) {
            Optional<TableSizeAlertThreshold> thresholdEntry = tableSizeAlertThresholdDao.find(new TableSizeAlertThresholdKey(clientName, tableName));
            // override manual thresholdEntry if exists
            if (thresholdEntry.isPresent() && thresholdEntry.get().getMaxRows() > 0) {
                threshold = thresholdEntry.get().getMaxRows();
            }
            // check if node numRows exceeds threshold
            if (threshold != null && latest.getNumRows() >= threshold) {
                aboveThresholdList.add(calculateStats(latest, threshold));
            }
        }
        if (enablePercentChangeAlert) {
            // check % growth if no absolute threshold set & !enablePercentChangeAlert
            CountStat growthIncrease = calculateStats(latest, previous.getNumRows());
            if (growthIncrease == null) {
                continue;
            }
            if (Math.abs(growthIncrease.percentageIncrease) > PERCENTAGE_THRESHOLD) {
                abovePercentageList.add(growthIncrease);
            }
        }
    }
    return new Twin<>(aboveThresholdList, abovePercentageList);
}
Also used : NodewatchConfiguration(io.datarouter.storage.node.tableconfig.NodewatchConfiguration) ArrayList(java.util.ArrayList) Twin(io.datarouter.util.tuple.Twin) TableSizeAlertThreshold(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount) TableSizeAlertThresholdKey(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)

Example 4 with TableCount

use of io.datarouter.nodewatch.storage.tablecount.TableCount in project datarouter by hotpads.

the class TableCountHandler method getRowCountJson.

private JsonArray getRowCountJson(List<TableCount> records) {
    var jsonArray = new JsonArray();
    for (TableCount record : records) {
        JsonObject json = new JsonObject();
        Long date = record.getDateUpdated().getTime();
        Long rows = record.getNumRows();
        json.addProperty("date", date);
        json.addProperty("rows", rows);
        jsonArray.add(json);
    }
    return jsonArray;
}
Also used : JsonArray(com.google.gson.JsonArray) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount) JsonObject(com.google.gson.JsonObject)

Example 5 with TableCount

use of io.datarouter.nodewatch.storage.tablecount.TableCount in project datarouter by hotpads.

the class TableCountHandler method getRowCountData.

private JsonArray getRowCountData(String clientName, String tableName) {
    List<TableCount> data = tableCountDao.getForTable(clientName, tableName);
    JsonArray jsonData = getRowCountJson(data);
    return jsonData;
}
Also used : JsonArray(com.google.gson.JsonArray) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount)

Aggregations

TableCount (io.datarouter.nodewatch.storage.tablecount.TableCount)5 LatestTableCount (io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)4 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)1 TableSizeAlertThreshold (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold)1 TableSizeAlertThresholdKey (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey)1 TableSample (io.datarouter.nodewatch.storage.tablesample.TableSample)1 TableSampleKey (io.datarouter.nodewatch.storage.tablesample.TableSampleKey)1 ClientTableEntityPrefixNameWrapper (io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)1 NodewatchConfiguration (io.datarouter.storage.node.tableconfig.NodewatchConfiguration)1 Twin (io.datarouter.util.tuple.Twin)1 BaseHandler (io.datarouter.web.handler.BaseHandler)1 Mav (io.datarouter.web.handler.mav.Mav)1 InContextRedirectMav (io.datarouter.web.handler.mav.imp.InContextRedirectMav)1 MessageMav (io.datarouter.web.handler.mav.imp.MessageMav)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1