From: Sasa M. <sa...@us...> - 2004-04-28 11:12:02
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21117/org/jrobin/core Modified Files: RrdDef.java Log Message: added methods to add datasource and archive definition using RRDTool's syntax (DS:... RRA:...) Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RrdDef.java 1 Mar 2004 08:50:24 -0000 1.9 --- RrdDef.java 28 Apr 2004 11:11:47 -0000 1.10 *************** *** 29,32 **** --- 29,33 ---- import java.util.Date; import java.util.GregorianCalendar; + import java.util.StringTokenizer; import java.io.*; *************** *** 209,212 **** --- 210,273 ---- /** + * Adds single datasource to RRD definition from a RRDTool-like + * datasource definition string. The string must have six elements separated with colons + * (:) in the following order:<p> + * <pre> + * DS:name:type:heartbeat:minValue:maxValue + * </pre> + * For example:</p> + * <pre> + * DS:input:COUNTER:600:0:U + * </pre> + * For more information on datasource definition parameters see <code>rrdcreate</code> + * man page.<p> + * @param rrdToolDsDef Datasource definition string with the syntax borrowed from RRDTool. + * @throws RrdException Thrown if invalid string is supplied. + */ + public void addDatasource(String rrdToolDsDef) throws RrdException { + RrdException rrdException = new RrdException( + "Wrong rrdtool-like datasource definition: " + rrdToolDsDef); + StringTokenizer tokenizer = new StringTokenizer(rrdToolDsDef, ":"); + if (tokenizer.countTokens() != 6) { + throw rrdException; + } + String[] tokens = new String[6]; + for (int curTok = 0; tokenizer.hasMoreTokens(); curTok++) { + tokens[curTok] = tokenizer.nextToken(); + } + if (!tokens[0].equalsIgnoreCase("DS")) { + throw rrdException; + } + String dsName = tokens[1]; + String dsType = tokens[2]; + long dsHeartbeat; + try { + dsHeartbeat = Long.parseLong(tokens[3]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + double minValue = Double.NaN; + if(!tokens[4].equalsIgnoreCase("U")) { + try { + minValue = Double.parseDouble(tokens[4]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + } + double maxValue = Double.NaN; + if(!tokens[5].equalsIgnoreCase("U")) { + try { + maxValue = Double.parseDouble(tokens[5]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + } + addDatasource(new DsDef(dsName, dsType, dsHeartbeat, minValue, maxValue)); + } + + /** * Adds data source definitions to RRD definition in bulk. * @param dsDefs Array of data source definition objects. *************** *** 262,265 **** --- 323,381 ---- } + /** + * 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 RrdException Thrown if invalid string is supplied. + */ + public void addArchive(String rrdToolArcDef) throws RrdException { + RrdException rrdException = new RrdException( + "Wrong rrdtool-like archive definition: " + rrdToolArcDef); + StringTokenizer tokenizer = new StringTokenizer(rrdToolArcDef, ":"); + if (tokenizer.countTokens() != 5) { + throw rrdException; + } + String[] tokens = new String[5]; + for (int curTok = 0; tokenizer.hasMoreTokens(); curTok++) { + tokens[curTok] = tokenizer.nextToken(); + } + if (!tokens[0].equalsIgnoreCase("RRA")) { + throw rrdException; + } + String consolFun = tokens[1]; + double xff; + try { + xff = Double.parseDouble(tokens[2]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + int steps; + try { + steps = Integer.parseInt(tokens[3]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + int rows; + try { + rows = Integer.parseInt(tokens[4]); + } + catch(NumberFormatException nfe) { + throw rrdException; + } + addArchive(new ArcDef(consolFun, xff, steps, rows)); + } + void validate() throws RrdException { if(dsDefs.size() == 0) { |