Search in sources :

Example 1 with TableSizeAlertThreshold

use of io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold in project datarouter by hotpads.

the class TableSizeAlertThresholdHandler method displayThreshold.

@Handler(defaultHandler = true)
public Mav displayThreshold() {
    Mav mav = new Mav(files.jsp.datarouter.nodewatch.thresholdSettingsJsp);
    List<TableSizeAlertThreshold> thresholdSettings = new ArrayList<>();
    for (PhysicalNode<?, ?, ?> node : datarouterNodes.getWritableNodes(clients.getClientIds())) {
        String clientName = node.getClientId().getName();
        var key = new TableSizeAlertThresholdKey(clientName, node.getFieldInfo().getTableName());
        TableSizeAlertThreshold row = tableSizeAlertThresholdDao.find(key).orElse(new TableSizeAlertThreshold(key, 0L));
        thresholdSettings.add(row);
    }
    mav.put("thresholdSettings", thresholdSettings);
    mav.put("thresholdPath", paths.datarouter.nodewatch.threshold.toSlashedString());
    return mav;
}
Also used : TableSizeAlertThreshold(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold) Mav(io.datarouter.web.handler.mav.Mav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) ArrayList(java.util.ArrayList) TableSizeAlertThresholdKey(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with TableSizeAlertThreshold

use of io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold 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 3 with TableSizeAlertThreshold

use of io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold in project datarouter by hotpads.

the class TableSizeAlertThresholdHandler method saveThresholds.

@Handler
public Mav saveThresholds() {
    String[] daos = request.getParameterValues(PARAM_clientName);
    String[] nodes = request.getParameterValues(PARAM_tableName);
    String[] thresholds = request.getParameterValues(PARAM_threshold);
    int listSize = daos.length;
    List<TableSizeAlertThreshold> thresholdSettingList = new ArrayList<>();
    for (int i = 0; i < listSize; i++) {
        TableSizeAlertThreshold tableSizeAlertThreshold = new TableSizeAlertThreshold(daos[i], nodes[i], Long.parseLong(thresholds[i]));
        thresholdSettingList.add(tableSizeAlertThreshold);
    }
    tableSizeAlertThresholdDao.putMulti(thresholdSettingList);
    return getRedirectMav();
}
Also used : TableSizeAlertThreshold(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold) ArrayList(java.util.ArrayList) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with TableSizeAlertThreshold

use of io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold in project datarouter by hotpads.

the class TableSizeAlertThresholdHandler method updateThreshold.

@Handler
public Mav updateThreshold(String tableName, String clientName, Long threshold) {
    TableSizeAlertThreshold tableSizeAlertThreshold = new TableSizeAlertThreshold(clientName, tableName, threshold);
    tableSizeAlertThresholdDao.put(tableSizeAlertThreshold);
    var dto = new DatarouterChangelogDtoBuilder("Nodewatch", clientName + "." + tableName, "update threshold", getSessionInfo().getNonEmptyUsernameOrElse("")).build();
    changelogRecorder.record(dto);
    return getRedirectMav();
}
Also used : TableSizeAlertThreshold(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

TableSizeAlertThreshold (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold)4 BaseHandler (io.datarouter.web.handler.BaseHandler)3 ArrayList (java.util.ArrayList)3 TableSizeAlertThresholdKey (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey)2 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)1 LatestTableCount (io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)1 TableCount (io.datarouter.nodewatch.storage.tablecount.TableCount)1 ClientTableEntityPrefixNameWrapper (io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)1 NodewatchConfiguration (io.datarouter.storage.node.tableconfig.NodewatchConfiguration)1 Twin (io.datarouter.util.tuple.Twin)1 Mav (io.datarouter.web.handler.mav.Mav)1 InContextRedirectMav (io.datarouter.web.handler.mav.imp.InContextRedirectMav)1