Search in sources :

Example 1 with CollectorData

use of alma.acs.monitoring.blobber.CollectorList.CollectorData in project ACS by ACS-Community.

the class BlobberWorker method run.

/**
	 * This method will be called at fixed intervals. It gathers the data from all registered collectors and stores it
	 * in the database, using the layer from module TMCBD/DAO.
	 * 
	 * @see java.lang.Runnable#run()
	 */
@Override
public void run() {
    cycleCount.incrementAndGet();
    myLogger.fine("Running BlobberWorker cycle " + cycleCount);
    int collectorCount = 0;
    int insertCount = 0;
    StopWatch stopWatchAllCollectors = new StopWatch(myLogger);
    // Checking memory requires a GC run (and no other components running in the same container)
    // to give reasonable results. Running GC from inside the program we don't want to do as default,
    // thus the use of the cheating property.
    long usedMemKBBeforeCycle = -1;
    if (Boolean.getBoolean(BLOBBER_CHECK_JVM_MEMORY_PROPERTYNAME)) {
        System.gc();
        Runtime rt = Runtime.getRuntime();
        usedMemKBBeforeCycle = (rt.totalMemory() - rt.freeMemory()) / 1024;
        myLogger.fine("Used JVM memory in kB after GC before blobber cycle: " + usedMemKBBeforeCycle);
    }
    // loop over all collectors. Note that collectors can be added and removed during this loop,
    // so that the initial list size does not necessarily show the number of executed collectors.
    CollectorData collectorData = null;
    myCollectorList.resetIterator();
    while (myCollectorList.hasNext()) {
        try {
            collectorData = myCollectorList.next();
            // has this thread been requested to terminate?
            if (shouldTerminate) {
                myLogger.info("Loop over collectors terminated prematurely, skipping '" + collectorData.getCollectorId() + "' and subsequent collectors.");
                break;
            }
            collectorCount++;
            StopWatch stopWatchCurrentCollector = new StopWatch(myLogger);
            // Get the corba ref for the current collector
            MonitorCollectorOperations collector = getMonitorCollector(collectorData.getCollectorId());
            // The data retrieval, processing, and storage happens here
            insertCount += harvestCollector(collectorData, collector);
            stopWatchCurrentCollector.logLapTime("process monitoring data from collector " + collectorData.getCollectorId());
        } catch (Exception e) {
            myLogger.log(Level.WARNING, "Exception caught while processing monitor collector " + collectorData.getCollectorId() + "; the data cache for this collector will be cleared, the data is LOST FOREVER", e);
        // @TODO Shouldn't we raise an alarm also here, now that we do when blobber comp fails to initialize?
        // Then it would need to be cleared once (the same collector's??) data is processed ok in the next round.
        }
    }
    if (Boolean.getBoolean(BLOBBER_CHECK_JVM_MEMORY_PROPERTYNAME)) {
        System.gc();
        Runtime rt = Runtime.getRuntime();
        long usedMemKBAfterCycle = (rt.totalMemory() - rt.freeMemory()) / 1024;
        myLogger.fine("Used JVM memory in kB after GC after blobber cycle: " + usedMemKBAfterCycle);
    }
    long totalTimeMillis = stopWatchAllCollectors.getLapTimeMillis();
    if (totalTimeMillis < collectIntervalSec * 1000) {
        // the good case: all collectors were processed within the foreseen time window
        String msg = "Processed monitoring data from " + collectorCount + " collector(s) in " + totalTimeMillis + " ms (within the time limit).";
        myLogger.fine(msg);
        if (isProfilingEnabled) {
            debugDataSender.sendUDPPacket(msg, cycleCount.longValue());
            debugDataSender.sendUDPPacket("Total inserts for cycle " + cycleCount + " were " + insertCount, cycleCount.longValue());
        }
    } else {
        // the bad case: this run took too long.
        String msg = "Processed monitoring data from " + collectorCount + " collector(s) in " + totalTimeMillis + " ms (exceeding the time limit of " + collectIntervalSec + " s).";
        myLogger.warning(msg);
        if (isProfilingEnabled) {
            debugDataSender.sendUDPPacket(msg, cycleCount.longValue());
            debugDataSender.sendUDPPacket("Total inserts for cycle " + cycleCount + " were " + insertCount, cycleCount.longValue());
        }
    }
}
Also used : MonitorCollectorOperations(alma.TMCDB.MonitorCollectorOperations) CollectorData(alma.acs.monitoring.blobber.CollectorList.CollectorData) UnknownHostException(java.net.UnknownHostException) StopWatch(alma.acs.util.StopWatch)

Aggregations

MonitorCollectorOperations (alma.TMCDB.MonitorCollectorOperations)1 CollectorData (alma.acs.monitoring.blobber.CollectorList.CollectorData)1 StopWatch (alma.acs.util.StopWatch)1 UnknownHostException (java.net.UnknownHostException)1