private void accumulate(ArcState state, double value) { if (Double.IsNaN(value)) { state.setNanSteps(state.getNanSteps() + 1); } else { ConsolFun cf = new ConsolFun(ConsolFun.ValueOf(consolFun.get())); switch (cf.CSType) { case ConsolFun.ConsolFunTypes.MIN: state.setAccumValue(Util.min(state.getAccumValue(), value)); break; case ConsolFun.ConsolFunTypes.MAX: state.setAccumValue(Util.max(state.getAccumValue(), value)); break; case ConsolFun.ConsolFunTypes.LAST: state.setAccumValue(value); break; case ConsolFun.ConsolFunTypes.AVERAGE: state.setAccumValue(Util.sum(state.getAccumValue(), value)); break; case ConsolFun.ConsolFunTypes.TOTAL: state.setAccumValue(Util.sum(state.getAccumValue(), value)); break; } } }
/** * Adds single archive to RRD definition from a RRDTool-like * archive definition string. The string must have five elements separated with colons * (:) in the following order:<p> * <pre> * RRA:consolidationFunction:XFilesFactor:steps:rows * </pre> * For example:</p> * <pre> * RRA:AVERAGE:0.5:10:1000 * </pre> * For more information on archive definition parameters see <code>rrdcreate</code> * man page.<p> * @param rrdToolArcDef Archive definition string with the syntax borrowed from RRDTool. * @throws ArgumentException Thrown if invalid string is supplied. */ public void addArchive(String rrdToolArcDef) { String[] tokens = rrdToolArcDef.Split(':'); if (tokens.Length != 5) { throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef); } if (tokens[0].ToUpper().CompareTo("RRA") != 0) { throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef); } ConsolFun consolFun = new ConsolFun(ConsolFun.ValueOf(tokens[1])); double xff; try { xff = Double.Parse(tokens[2]); } catch (FormatException nfe) { throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe); } int steps; try { steps = int.Parse(tokens[3]); } catch (FormatException nfe) { throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe); } int rows; try { rows = int.Parse(tokens[4]); } catch (FormatException nfe) { throw new ArgumentException("Wrong rrdtool-like archive definition: " + rrdToolArcDef, nfe); } addArchive(new ArcDef(consolFun, xff, steps, rows)); }
/** * Returns archive consolidation function ("AVERAGE", "MIN", "MAX" or "LAST"). * * @return Archive consolidation function. * @Thrown in case of I/O error. */ public ConsolFun getConsolFun() { return(new ConsolFun(ConsolFun.ValueOf(consolFun.get()))); }