Search in sources :

Example 1 with ReadingsRepository

use of com.axway.ats.monitoring.model.readings.ReadingsRepository in project ats-framework by Axway.

the class SystemStatsLoggerTask method logResultsForOneTimestamp.

private int logResultsForOneTimestamp(MonitorResults resultsLine) {
    ReadingsRepository readingsRepository = ReadingsRepository.getInstance();
    int resultsAddeed = 0;
    // transform all reading info into 2 Strings: one for DB IDs and one for their values
    StringBuilder statisticDbIds = new StringBuilder();
    StringBuilder statisticValues = new StringBuilder();
    for (BasicReadingBean reading : resultsLine.getReadings()) {
        String readingId = reading.getId();
        if (readingId == null) {
            log.error("This reading [" + reading.toString() + "] does not have set a reading ID which indicates an error in some of the attached monitors. We will not insert this reading in the database.");
            continue;
        }
        Integer readingDbId = readingsRepository.getReadingDbId(readingId);
        if (readingDbId == null) {
            log.error("We do not have information in the database about this reading [" + reading.toString() + "]. We will not insert this reading in the database.");
            continue;
        }
        String readingValue = reading.getValue();
        if (readingValue == null) {
            log.error("Null value is passed for this reading [" + reading.toString() + "]. We will not insert this reading in the database.");
            continue;
        }
        statisticDbIds.append(readingDbId);
        statisticDbIds.append("_");
        statisticValues.append(readingValue);
        statisticValues.append("_");
        resultsAddeed++;
        if (statisticDbIds.length() > MAX_LENGTH_STATISTIC_IDS || statisticValues.length() > MAX_LENGTH_STATISTIC_VALUES) {
            // we have to send a chunk
            statisticDbIds.setLength(statisticDbIds.length() - 1);
            statisticValues.setLength(statisticValues.length() - 1);
            log.insertSystemStatistcs(monitoredHost, statisticDbIds.toString(), statisticValues.toString(), resultsLine.getTimestamp());
            statisticDbIds.setLength(0);
            statisticValues.setLength(0);
        }
    }
    if (statisticDbIds.length() > 0) {
        // send the last(or only) chunk
        statisticDbIds.setLength(statisticDbIds.length() - 1);
        statisticValues.setLength(statisticValues.length() - 1);
        log.insertSystemStatistcs(monitoredHost, statisticDbIds.toString(), statisticValues.toString(), resultsLine.getTimestamp());
    }
    return resultsAddeed;
}
Also used : BasicReadingBean(com.axway.ats.common.performance.monitor.beans.BasicReadingBean) ReadingsRepository(com.axway.ats.monitoring.model.readings.ReadingsRepository)

Aggregations

BasicReadingBean (com.axway.ats.common.performance.monitor.beans.BasicReadingBean)1 ReadingsRepository (com.axway.ats.monitoring.model.readings.ReadingsRepository)1