long totalElapsedMillis = Math.max(now - getStartTime(), 1); long currentEnqueuedOps = (getEnqueuedOperations() - lastEnqueued); long currentDequeuedOps = (getDequeuedOperations() - lastDequeued); long currentDequeuedItems = (getDequeuedItems() - lastDequeuedItems); long currentSigOpsEnqueued = (getSignificantOpsEnqueued() - lastSignificantEnqueued); long currentSigOpsDequeued = (getSignificantOpsDequeued() - lastSignificantDequeued); long currentSigEnqueueRate = (long) (currentSigOpsEnqueued * 1000.0 / currentElapsedMillis); long currentInsigEnqueueRate = (long) ((currentEnqueuedOps - currentSigOpsEnqueued) * 1000.0 / currentElapsedMillis); long overallEnqueueRate = (long) (getEnqueuedOperations() * 1000.0 / totalElapsedMillis); long overallSigEnqueueRate = (long) (getSignificantOpsEnqueued() * 1000.0 / totalElapsedMillis); long overallInsigEnqueueRate = (long) ((getEnqueuedOperations() - getSignificantOpsEnqueued()) * 1000.0 / totalElapsedMillis); long overallDequeueRate = (long) (getDequeuedOperations() * 1000.0 / totalElapsedMillis); long overallSigDequeueRate = (long) (getSignificantOpsDequeued() * 1000.0 / totalElapsedMillis); long overallInsigDequeueRate = (long) ((getDequeuedOperations() - getSignificantOpsDequeued()) * 1000.0 / totalElapsedMillis); long overallItemDequeueRate = (long) (getDequeuedItems() * 1000.0 / totalElapsedMillis); String stats = "\nQS:\t" + "totalOperationsPending=" + getTotalOperationsPending() + ", significantOpsPending=" + (getSignificantOpsEnqueued() - getSignificantOpsCompleted()) + ", filesWithSignificantWork=" + filesWithSignificantWork.size() + ", filesWithInsignificantWork=" + filesWithInsignificantWork.size() + "\nQS:\t" + ", createsCompleted=" + getCreatesCompleted() + ", updatesCompleted=" + getUpdatesCompleted() + ", errors=" + getErrors() +
/** * close the rrd file */ private void processClose(final Object rrd) { if (rrd != null) { try { m_delegate.closeFile(rrd); } catch (final Throwable e) { setErrors(getErrors() + 1); logLapTime("Error closing rrd " + rrd + ": " + e.getMessage()); m_log.debug("Error closing rrd {}: {}", rrd, e.getMessage(), e); } } }
/** * Ensure that files with insignificant changes are getting promoted if * necessary * */ private synchronized void promoteAgedFiles() { // no need to do this is we aren't prioritizing if (!m_prioritizeSignificantUpdates) return; // the num seconds to update files is 0 then use unfair prioritization if (m_maxInsigUpdateSeconds == 0 || filesWithInsignificantWork.isEmpty()) return; // calculate the elapsed time we first queued updates long now = System.currentTimeMillis(); long elapsedMillis = Math.max(now - getStartTime(), 1); // calculate the milliseconds between promotions necessary to age // insignificant files into // the significant queue double millisPerPromotion = ((m_maxInsigUpdateSeconds * 1000.0) / filesWithInsignificantWork.size()); // calculate the number of millis since start until the next file needs // to be promotoed long nextPromotionMillis = (long) (millisPerPromotion * getPromotionCount()); // if more time has elapsed than the next promotion time then promote a // file if (elapsedMillis > nextPromotionMillis) { String file = filesWithInsignificantWork.removeFirst(); filesWithSignificantWork.addFirst(file); setPromotionCount(getPromotionCount() + 1); } }
completeAssignment(); while ((newAssignment = selectNewAssignment()) == null) { try { wait(); if (getStartTime() == 0) setStartTime(System.currentTimeMillis()); ops = takeAssignment(newAssignment); setTotalOperationsPending(getTotalOperationsPending()-op.getCount()); setDequeuedOperations(getDequeuedOperations() + op.getCount()); if (op.isSignificant()) { setSignificantOpsDequeued(getSignificantOpsDequeued() + op.getCount()); setDequeuedItems(getDequeuedItems() + 1);
/** * Add an operation to the queue. * * @param op a {@link org.opennms.netmgt.rrd.QueuingRrdStrategy.Operation} object. */ private void addOperation(final Operation op) { synchronized (this) { if (queueIsFull()) { m_log.error("RRD Data Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } if (op.isSignificant() && sigQueueIsFull()) { m_log.error("RRD Data Significant Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } if (!op.isSignificant() && inSigQueueIsFull()) { m_log.error("RRD Insignificant Data Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } storeAssignment(op); setTotalOperationsPending(getTotalOperationsPending() + 1); setEnqueuedOperations(getEnqueuedOperations() + 1); if (op.isSignificant()) setSignificantOpsEnqueued(getSignificantOpsEnqueued() + 1); notifyAll(); ensureThreadsStarted(); } }
@Override public void run() { Object rrd = null; String fileName = null; try { final LinkedList<Operation> ops = getNext(); if (ops == null) { return; } // update stats correctly we update them even if an exception occurs // while we are processing for (final Operation op : ops) { if (op.isSignificant()) { setSignificantOpsCompleted(getSignificantOpsCompleted() + 1); } } // now we actually process the events for (final Operation op : ops) { fileName = op.getFileName(); rrd = op.process(rrd); } } catch (final Throwable e) { setErrors(getErrors() + 1); logLapTime("Error updating file " + fileName + ": " + e.getMessage()); m_log.debug("Error updating file {}: {}", fileName, e.getMessage(), e); } finally { processClose(rrd); } } });
@Override Object process(Object rrd) throws Exception { // if the rrd is already open we are confused if (rrd != null) { m_log.debug("WHAT! rrd open but not created?"); m_delegate.closeFile(rrd); rrd = null; } // create the file m_delegate.createFile(getData()); // keep stats setCreatesCompleted(getCreatesCompleted() + 1); // return the file return rrd; }
/** * <p>getDequeuedOperations</p> * * @return a long. */ @Override public long getDequeuedOperations() { if (getStatsStatus()) { return getRrdStrategy().getDequeuedOperations(); } else { return 0; } }
/** * <p>getErrors</p> * * @return a long. */ @Override public long getErrors() { if (getStatsStatus()) { return getRrdStrategy().getErrors(); } else { return 0; } }
/** * <p>getEnqueuedOperations</p> * * @return a long. */ @Override public long getEnqueuedOperations() { if (getStatsStatus()) { return getRrdStrategy().getEnqueuedOperations(); } else { return 0; } }
/** * <p>getSignificantOpsDequeued</p> * * @return a long. */ @Override public long getSignificantOpsDequeued() { if (getStatsStatus()) { return getRrdStrategy().getSignificantOpsDequeued(); } else { return 0; } }
/** * <p>getSignificantOpsCompleted</p> * * @return a long. */ @Override public long getSignificantOpsCompleted() { if (getStatsStatus()) { return getRrdStrategy().getSignificantOpsCompleted(); } else { return 0; } }
/** * <p>getStartTime</p> * * @return a long. */ @Override public long getStartTime() { if (getStatsStatus()) { return getRrdStrategy().getStartTime(); } else { return 0; } }
/** * <p>getPromotionCount</p> * * @return a long. */ @Override public long getPromotionCount() { if (getStatsStatus()) { return getRrdStrategy().getPromotionCount(); } else { return 0; } }
/** * <p>getDequeuedItems</p> * * @return a long. */ @Override public long getDequeuedItems() { if (getStatsStatus()) { return getRrdStrategy().getDequeuedItems(); } else { return 0; } }
/** * <p>getCreatesCompleted</p> * * @return a long. */ @Override public long getCreatesCompleted() { if (getStatsStatus()) { return getRrdStrategy().getCreatesCompleted(); } else { return 0; } }
/** * <p>getSignificantOpsEnqueued</p> * * @return a long. */ @Override public long getSignificantOpsEnqueued() { if (getStatsStatus()) { return getRrdStrategy().getSignificantOpsEnqueued(); } else { return 0; } }
completeAssignment(); while ((newAssignment = selectNewAssignment()) == null) { try { wait(); if (getStartTime() == 0) setStartTime(System.currentTimeMillis()); ops = takeAssignment(newAssignment); setTotalOperationsPending(getTotalOperationsPending()-op.getCount()); setDequeuedOperations(getDequeuedOperations() + op.getCount()); if (op.isSignificant()) { setSignificantOpsDequeued(getSignificantOpsDequeued() + op.getCount()); setDequeuedItems(getDequeuedItems() + 1);
/** * Add an operation to the queue. * * @param op a {@link org.opennms.netmgt.rrd.QueuingRrdStrategy.Operation} object. */ private void addOperation(final Operation op) { synchronized (this) { if (queueIsFull()) { m_log.error("RRD Data Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } if (op.isSignificant() && sigQueueIsFull()) { m_log.error("RRD Data Significant Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } if (!op.isSignificant() && inSigQueueIsFull()) { m_log.error("RRD Insignificant Data Queue is Full!! Discarding operation for file {}", op.getFileName()); return; } storeAssignment(op); setTotalOperationsPending(getTotalOperationsPending() + 1); setEnqueuedOperations(getEnqueuedOperations() + 1); if (op.isSignificant()) setSignificantOpsEnqueued(getSignificantOpsEnqueued() + 1); notifyAll(); ensureThreadsStarted(); } }
@Override public void run() { Object rrd = null; String fileName = null; try { final LinkedList<Operation> ops = getNext(); if (ops == null) { return; } // update stats correctly we update them even if an exception occurs // while we are processing for (final Operation op : ops) { if (op.isSignificant()) { setSignificantOpsCompleted(getSignificantOpsCompleted() + 1); } } // now we actually process the events for (final Operation op : ops) { fileName = op.getFileName(); rrd = op.process(rrd); } } catch (final Throwable e) { setErrors(getErrors() + 1); logLapTime("Error updating file " + fileName + ": " + e.getMessage()); m_log.debug("Error updating file {}: {}", fileName, e.getMessage(), e); } finally { processClose(rrd); } } });