From: Tarus B. <ta...@us...> - 2006-12-21 18:03:15
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/cmd Modified Files: ColonSplitter.java RrdCmdScanner.java RrdCommander.java RrdCreateCmd.java RrdDumpCmd.java RrdFetchCmd.java RrdGraphCmd.java RrdInfoCmd.java RrdLastCmd.java RrdRestoreCmd.java RrdToolCmd.java RrdTuneCmd.java RrdUpdateCmd.java RrdXportCmd.java Log Message: Adding the new 1.5.4 code Index: RrdFetchCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdFetchCmd.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RrdFetchCmd.java 17 Feb 2005 10:43:12 -0000 1.4 --- RrdFetchCmd.java 21 Dec 2006 18:02:40 -0000 1.5 *************** *** 1,76 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.FetchRequest; ! import org.jrobin.core.FetchData; ! import org.jrobin.core.timespec.TimeParser; ! import org.jrobin.core.timespec.TimeSpec; ! ! import java.io.IOException; ! ! class RrdFetchCmd extends RrdToolCmd { ! static final String DEFAULT_START = "end-1day"; ! static final String DEFAULT_END = "now"; ! ! String getCmdType() { ! return "fetch"; ! } ! ! Object execute() throws RrdException, IOException { ! // --start ! String startStr = getOptionValue("s", "start", DEFAULT_START); ! TimeSpec spec1 = new TimeParser(startStr).parse(); ! // --end ! String endStr = getOptionValue("e", "end", DEFAULT_END); ! TimeSpec spec2 = new TimeParser(endStr).parse(); ! long[] timestamps = TimeSpec.getTimestamps(spec1, spec2); ! // --resolution ! String resolutionStr = getOptionValue("r", "resolution", "1"); ! long resolution = parseLong(resolutionStr); ! // other words ! String[] words = getRemainingWords(); ! if(words.length != 3) { ! throw new RrdException("Invalid rrdfetch syntax"); ! } ! String path = words[1]; ! String consolFun = words[2]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! FetchRequest fetchRequest = rrdDb.createFetchRequest( ! consolFun, timestamps[0], timestamps[1], resolution); ! System.out.println(fetchRequest.dump()); ! FetchData fetchData = fetchRequest.fetchData(); ! println(fetchData.toString()); ! return fetchData; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } --- 1,63 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.*; ! import org.jrobin.graph.RrdGraphConstants; ! ! import java.io.IOException; ! ! class RrdFetchCmd extends RrdToolCmd implements RrdGraphConstants { ! String getCmdType() { ! return "fetch"; ! } ! ! Object execute() throws RrdException, IOException { ! String startStr = getOptionValue("s", "start", DEFAULT_START); ! String endStr = getOptionValue("e", "end", DEFAULT_END); ! long[] timestamps = Util.getTimestamps(startStr, endStr); ! String resolutionStr = getOptionValue("r", "resolution", "1"); ! long resolution = parseLong(resolutionStr); ! // other words ! String[] words = getRemainingWords(); ! if (words.length != 3) { ! throw new RrdException("Invalid rrdfetch syntax"); ! } ! String path = words[1]; ! String consolFun = words[2]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! FetchRequest fetchRequest = rrdDb.createFetchRequest(consolFun, timestamps[0], timestamps[1], resolution); ! System.out.println(fetchRequest.dump()); ! FetchData fetchData = fetchRequest.fetchData(); ! println(fetchData.toString()); ! return fetchData; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } Index: RrdRestoreCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdRestoreCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdRestoreCmd.java 16 Jul 2004 07:40:48 -0000 1.2 --- RrdRestoreCmd.java 21 Dec 2006 18:02:40 -0000 1.3 *************** *** 1,43 **** ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.Datasource; ! ! import java.io.IOException; ! ! class RrdRestoreCmd extends RrdToolCmd { ! ! String getCmdType() { ! return "restore"; ! } ! ! Object execute() throws RrdException, IOException { ! boolean check = getBooleanOption("r", "range-check"); ! String[] words = getRemainingWords(); ! if(words.length != 3) { ! throw new RrdException("Invalid rrdrestore syntax"); ! } ! String xmlPath = words[1]; ! String rrdPath = words[2]; ! RrdDb rrdDb = getRrdDbReference(rrdPath, xmlPath); ! try { ! if(check) { ! int dsCount = rrdDb.getHeader().getDsCount(); ! for(int i = 0; i < dsCount; i++) { ! Datasource ds = rrdDb.getDatasource(i); ! double minValue = ds.getMinValue(); ! double maxValue = ds.getMaxValue(); ! // this will perform range check ! ds.setMinMaxValue(minValue, maxValue, true); ! } ! } ! return rrdPath; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! ! ! } --- 1,64 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! package org.jrobin.cmd; ! ! import org.jrobin.core.Datasource; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! ! import java.io.IOException; ! ! class RrdRestoreCmd extends RrdToolCmd { ! String getCmdType() { ! return "restore"; ! } ! ! Object execute() throws RrdException, IOException { ! boolean check = getBooleanOption("r", "range-check"); ! String[] words = getRemainingWords(); ! if (words.length != 3) { ! throw new RrdException("Invalid rrdrestore syntax"); ! } ! String xmlPath = words[1]; ! String rrdPath = words[2]; ! RrdDb rrdDb = getRrdDbReference(rrdPath, xmlPath); ! try { ! if (check) { ! int dsCount = rrdDb.getHeader().getDsCount(); ! for (int i = 0; i < dsCount; i++) { ! Datasource ds = rrdDb.getDatasource(i); ! double minValue = ds.getMinValue(); ! double maxValue = ds.getMaxValue(); ! // this will perform range check ! ds.setMinMaxValue(minValue, maxValue, true); ! } ! } ! return rrdPath; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } Index: RrdTuneCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdTuneCmd.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** RrdTuneCmd.java 6 Sep 2005 20:40:54 -0000 1.1.1.1 --- RrdTuneCmd.java 21 Dec 2006 18:02:40 -0000 1.2 *************** *** 45,52 **** String[] dsNames = getMultipleOptionValues("r", "data-source-rename"); String[] words = getRemainingWords(); ! if(words.length < 2) { throw new RrdException("File name not specified"); } ! if(words.length > 2) { throw new RrdException("Unexpected token encountered: " + words[2]); } --- 45,52 ---- String[] dsNames = getMultipleOptionValues("r", "data-source-rename"); String[] words = getRemainingWords(); ! if (words.length < 2) { throw new RrdException("File name not specified"); } ! if (words.length > 2) { throw new RrdException("Unexpected token encountered: " + words[2]); } *************** *** 55,80 **** try { // heartbeat ! for(int i = 0; i < heartbeats.length; i++) { ! tuneHeartbeat(rrd, heartbeats[i]); } // minimum ! for(int i = 0; i < minimums.length; i++) { ! tuneMinimum(rrd, minimums[i]); } // maximum ! for(int i = 0; i < maximums.length; i++) { ! tuneMaximum(rrd, maximums[i]); } // rename ! for(int i = 0; i < dsNames.length; i++) { ! tuneName(rrd, dsNames[i]); } // type ! for(int i = 0; i < dsTypes.length; i++) { ! tuneType(rrd, dsTypes[i]); } // post festum ! if(heartbeats.length == 0 && minimums.length == 0 && maximums.length == 0 && ! dsTypes.length == 0 && dsNames.length == 0) { dump(rrd); } --- 55,80 ---- try { // heartbeat ! for (String heartbeat : heartbeats) { ! tuneHeartbeat(rrd, heartbeat); } // minimum ! for (String minimum : minimums) { ! tuneMinimum(rrd, minimum); } // maximum ! for (String maximum : maximums) { ! tuneMaximum(rrd, maximum); } // rename ! for (String dsName : dsNames) { ! tuneName(rrd, dsName); } // type ! for (String dsType : dsTypes) { ! tuneType(rrd, dsType); } // post festum ! if (heartbeats.length == 0 && minimums.length == 0 && maximums.length == 0 && ! dsTypes.length == 0 && dsNames.length == 0) { dump(rrd); } *************** *** 88,92 **** private void tuneHeartbeat(RrdDb rrd, String heartbeatStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(heartbeatStr).split(); ! if(tokens.length != 2) { throw new RrdException("Invalid suntax in: " + heartbeatStr); } --- 88,92 ---- private void tuneHeartbeat(RrdDb rrd, String heartbeatStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(heartbeatStr).split(); ! if (tokens.length != 2) { throw new RrdException("Invalid suntax in: " + heartbeatStr); } *************** *** 99,103 **** private void tuneMinimum(RrdDb rrd, String minimumStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(minimumStr).split(); ! if(tokens.length != 2) { throw new RrdException("Invalid suntax in: " + minimumStr); } --- 99,103 ---- private void tuneMinimum(RrdDb rrd, String minimumStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(minimumStr).split(); ! if (tokens.length != 2) { throw new RrdException("Invalid suntax in: " + minimumStr); } *************** *** 110,114 **** private void tuneMaximum(RrdDb rrd, String maximumStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(maximumStr).split(); ! if(tokens.length != 2) { throw new RrdException("Invalid suntax in: " + maximumStr); } --- 110,114 ---- private void tuneMaximum(RrdDb rrd, String maximumStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(maximumStr).split(); ! if (tokens.length != 2) { throw new RrdException("Invalid suntax in: " + maximumStr); } *************** *** 121,125 **** private void tuneName(RrdDb rrd, String nameStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(nameStr).split(); ! if(tokens.length != 2) { throw new RrdException("Invalid suntax in: " + nameStr); } --- 121,125 ---- private void tuneName(RrdDb rrd, String nameStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(nameStr).split(); ! if (tokens.length != 2) { throw new RrdException("Invalid suntax in: " + nameStr); } *************** *** 131,135 **** private void tuneType(RrdDb rrd, String typeStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(typeStr).split(); ! if(tokens.length != 2) { throw new RrdException("Invalid suntax in: " + typeStr); } --- 131,135 ---- private void tuneType(RrdDb rrd, String typeStr) throws RrdException, IOException { String[] tokens = new ColonSplitter(typeStr).split(); ! if (tokens.length != 2) { throw new RrdException("Invalid suntax in: " + typeStr); } *************** *** 143,147 **** StringBuffer line = new StringBuffer(); int n = rrd.getDsCount(); ! for(int i = 0; i < n; i++) { Datasource ds = rrd.getDatasource(i); line.append("DS["); --- 143,147 ---- StringBuffer line = new StringBuffer(); int n = rrd.getDsCount(); ! for (int i = 0; i < n; i++) { Datasource ds = rrd.getDatasource(i); line.append("DS["); *************** *** 149,158 **** line.append("] typ: "); line.append(ds.getDsType()); ! while(line.length() < 24) { line.append(' '); } line.append("hbt: "); line.append(ds.getHeartbeat()); ! while(line.length() < 40) { line.append(' '); } --- 149,158 ---- line.append("] typ: "); line.append(ds.getDsType()); ! while (line.length() < 24) { line.append(' '); } line.append("hbt: "); line.append(ds.getHeartbeat()); ! while (line.length() < 40) { line.append(' '); } Index: RrdGraphCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdGraphCmd.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** RrdGraphCmd.java 6 Sep 2005 20:40:54 -0000 1.1.1.1 --- RrdGraphCmd.java 21 Dec 2006 18:02:40 -0000 1.2 *************** *** 204,208 **** // create diagram finally RrdGraphInfo info = new RrdGraph(gdef).getRrdGraphInfo(); ! if(info.getFilename().equals(RrdGraphConstants.IN_MEMORY_IMAGE)) { println(new String(info.getBytes())); } --- 204,208 ---- // create diagram finally RrdGraphInfo info = new RrdGraph(gdef).getRrdGraphInfo(); ! if (info.getFilename().equals(RrdGraphConstants.IN_MEMORY_IMAGE)) { println(new String(info.getBytes())); } *************** *** 210,217 **** println(info.getWidth() + "x" + info.getHeight()); String[] plines = info.getPrintLines(); ! for(int i = 0; i < plines.length; i++) { ! println(plines[i]); } ! if(info.getImgInfo() != null && info.getImgInfo().length() > 0) { println(info.getImgInfo()); } --- 210,217 ---- println(info.getWidth() + "x" + info.getHeight()); String[] plines = info.getPrintLines(); ! for (String pline : plines) { ! println(pline); } ! if (info.getImgInfo() != null && info.getImgInfo().length() > 0) { println(info.getImgInfo()); } *************** *** 347,354 **** return; } ! for (int i = 0; i < colorOptions.length; i++) { ! String[] tokens = colorOptions[i].split("#"); if (tokens.length != 2) { ! throw new RrdException("Invalid COLOR specification: " + colorOptions[i]); } String colorName = tokens[0]; --- 347,354 ---- return; } ! for (String colorOption : colorOptions) { ! String[] tokens = colorOption.split("#"); if (tokens.length != 2) { ! throw new RrdException("Invalid COLOR specification: " + colorOption); } String colorName = tokens[0]; Index: RrdCreateCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCreateCmd.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RrdCreateCmd.java 17 Feb 2005 10:43:12 -0000 1.3 --- RrdCreateCmd.java 21 Dec 2006 18:02:40 -0000 1.4 *************** *** 1,104 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDef; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.timespec.TimeParser; ! import org.jrobin.core.timespec.TimeSpec; ! ! import java.io.IOException; ! ! class RrdCreateCmd extends RrdToolCmd { ! static final String DEFAULT_START = "now-10s"; ! static final String DEFAULT_STEP = "300"; ! ! private RrdDef rrdDef; ! ! String getCmdType() { ! return "create"; ! } ! ! Object execute() throws RrdException, IOException { ! String startStr = getOptionValue("b", "start", DEFAULT_START); ! TimeSpec spec = new TimeParser(startStr).parse(); ! long start = spec.getTimestamp(); ! String stepStr = getOptionValue("s", "step", DEFAULT_STEP); ! long step = parseLong(stepStr); ! String[] words = getRemainingWords(); ! if(words.length < 2) { ! throw new RrdException("RRD file path not specified"); ! } ! String path = words[1]; ! rrdDef = new RrdDef(path, start, step); ! for(int i = 2; i < words.length; i++) { ! if(words[i].startsWith("DS:")) { ! parseDef(words[i]); ! } ! else if(words[i].startsWith("RRA:")) { ! parseRra(words[i]); ! } ! else { ! throw new RrdException("Invalid rrdcreate syntax: " + words[i]); ! } ! } ! return createRrdDb(); ! } ! ! private void parseDef(String word) throws RrdException { ! // DEF:name:type:heratbeat:min:max ! String[] tokens = word.split(":"); ! if(tokens.length < 6) { ! throw new RrdException("Invalid DS definition: " + word); ! } ! String dsName = tokens[1]; ! String dsType = tokens[2]; ! long heartbeat = parseLong(tokens[3]); ! double min = parseDouble(tokens[4]); ! double max = parseDouble(tokens[5]); ! rrdDef.addDatasource(dsName, dsType, heartbeat, min, max); ! } ! ! private void parseRra(String word) throws RrdException { ! // RRA:cfun:xff:steps:rows ! String[] tokens = word.split(":"); ! if(tokens.length < 5) { ! throw new RrdException("Invalid RRA definition: " + word); ! } ! String cf = tokens[1]; ! double xff = parseDouble(tokens[2]); ! int steps = parseInt(tokens[3]); ! int rows = parseInt(tokens[4]); ! rrdDef.addArchive(cf, xff, steps, rows); ! } ! ! private String createRrdDb() throws IOException, RrdException { ! RrdDb rrdDb = getRrdDbReference(rrdDef); ! releaseRrdDbReference(rrdDb); ! return rrdDef.getPath(); ! } ! } --- 1,102 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDef; ! import org.jrobin.core.RrdException; ! import org.jrobin.core.Util; ! ! import java.io.IOException; ! ! class RrdCreateCmd extends RrdToolCmd { ! static final String DEFAULT_START = "now-10s"; ! static final String DEFAULT_STEP = "300"; ! ! private RrdDef rrdDef; ! ! String getCmdType() { ! return "create"; ! } ! ! Object execute() throws RrdException, IOException { ! String startStr = getOptionValue("b", "start", DEFAULT_START); ! long start = Util.getTimestamp(startStr); ! String stepStr = getOptionValue("s", "step", DEFAULT_STEP); ! long step = parseLong(stepStr); ! String[] words = getRemainingWords(); ! if (words.length < 2) { ! throw new RrdException("RRD file path not specified"); ! } ! String path = words[1]; ! rrdDef = new RrdDef(path, start, step); ! for (int i = 2; i < words.length; i++) { ! if (words[i].startsWith("DS:")) { ! parseDef(words[i]); ! } ! else if (words[i].startsWith("RRA:")) { ! parseRra(words[i]); ! } ! else { ! throw new RrdException("Invalid rrdcreate syntax: " + words[i]); ! } ! } ! return createRrdDb(); ! } ! ! private void parseDef(String word) throws RrdException { ! // DEF:name:type:heratbeat:min:max ! String[] tokens = new ColonSplitter(word).split(); ! if (tokens.length < 6) { ! throw new RrdException("Invalid DS definition: " + word); ! } ! String dsName = tokens[1]; ! String dsType = tokens[2]; ! long heartbeat = parseLong(tokens[3]); ! double min = parseDouble(tokens[4]); ! double max = parseDouble(tokens[5]); ! rrdDef.addDatasource(dsName, dsType, heartbeat, min, max); ! } ! ! private void parseRra(String word) throws RrdException { ! // RRA:cfun:xff:steps:rows ! String[] tokens = new ColonSplitter(word).split(); ! if (tokens.length < 5) { ! throw new RrdException("Invalid RRA definition: " + word); ! } ! String cf = tokens[1]; ! double xff = parseDouble(tokens[2]); ! int steps = parseInt(tokens[3]); ! int rows = parseInt(tokens[4]); ! rrdDef.addArchive(cf, xff, steps, rows); ! } ! ! private String createRrdDb() throws IOException, RrdException { ! RrdDb rrdDb = getRrdDbReference(rrdDef); ! releaseRrdDbReference(rrdDb); ! return rrdDef.getPath(); ! } ! } Index: RrdCommander.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdCommander.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RrdCommander.java 16 Jul 2004 08:01:09 -0000 1.7 --- RrdCommander.java 21 Dec 2006 18:02:40 -0000 1.8 *************** *** 1,152 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! ! import java.io.IOException; ! import java.io.BufferedReader; ! import java.io.InputStreamReader; ! import java.io.File; ! ! /** ! * Class to be used to execute various RRDTool commands (original syntax of RRDTool must be used). ! */ ! public class RrdCommander { ! // just add all new commands here ! private static final RrdToolCmd[] rrdCommands = { ! new RrdCreateCmd(), ! new RrdUpdateCmd(), ! new RrdLastCmd(), ! new RrdFetchCmd(), ! new RrdDumpCmd(), ! new RrdRestoreCmd(), ! new RrdXportCmd() ! }; ! ! /** ! * Checks if the output from any RRDTool command will be visible on the standard output device ! * (console). Default setting is <code>true</code>. ! * ! * @return true, if the output will be visible on the standard output device; false, otherwise. ! */ ! public static synchronized boolean isStandardOutUsed() { ! return RrdToolCmd.isStandardOutUsed(); ! } ! ! /** ! * Method used to control access to stdout (System.out, console) for all RRDTool commands. By default, ! * all RRDTool commands are allowed to print results to stdout, in a form used by RRDTool. ! * ! * @param standardOutUsed <code>true</code> if the output should be visible on the ! * standard output device, <code>false</code> otherwise. ! */ ! public static synchronized void setStandardOutUsed(boolean standardOutUsed) { ! RrdToolCmd.setStandardOutUsed(standardOutUsed); ! } ! /** ! * Checks if the class uses {@link org.jrobin.core.RrdDbPool} internally while executing ! * RRDTool commands. ! * @return true if the pool is used, false otherwise ! */ ! public static synchronized boolean isRrdDbPoolUsed() { ! return RrdToolCmd.isRrdDbPoolUsed(); ! } ! ! /** ! * Forces or prohibits {@link org.jrobin.core.RrdDbPool} usage internally while executing ! * RRDTool commands ! * @param rrdDbPoolUsed true, to force pool usage, false otherwise. ! */ ! public static synchronized void setRrdDbPoolUsed(boolean rrdDbPoolUsed) { ! RrdToolCmd.setRrdDbPoolUsed(rrdDbPoolUsed); ! } ! ! /** ! * Executes single RRDTool command. The command string should start with some ! * well known RRDTool command word (create, update, fetch, graph...)<p> ! * @param command RRDTool command like: <p> ! * <pre> ! * create test.rrd --start "noon yesterday" --step 300 DS:x:GAUGE:600:U:U RRA:0.5:5:1000 ! * update test.rrd N:1000 ! * last test.rrd ! * ... ! * </pre> ! * @return Result of specific RRDTool command. It is guaranteed that the result of any ! * successfully executed command will be always different from null. ! * Unsuccessfully executed commands will always throw ! * an exception, so you need not check for null results.<p> ! * Exact type of the result depends from the ! * type of executed RRDTool command:<p> ! * <ul> ! * <li><b>create</b>: returns java.lang.String containing path to the newly created RRD file. ! * <li><b>last</b>: returns java.lang.Long representing timestamp of the last update. ! * <li><b>update</b>: returns java.lang.Long representing timestamp of the last update. ! *<li><b>dump</b>: returns (very long) java.lang.String representing the content of a RRD file ! * in XML format. ! * <li><b>fetch</b>: returns {@link org.jrobin.core.FetchData} object representing fetched data. ! * <li><b>restore</b>: returns java.lang.String containing path to the restored RRD file. ! * </ul> ! * @throws IOException thrown in case of I/O error ! * @throws RrdException thrown for all other errors (parsing errors, ! * unknown RRDTool syntax/command/option, internal RRD errors...) ! */ ! public static synchronized Object execute(String command) throws IOException, RrdException ! { ! String cmd = command.trim(); ! for(int i = 0; i < rrdCommands.length; i++) { ! if(cmd.startsWith(rrdCommands[i].getCmdType())) { ! return rrdCommands[i].executeCommand(cmd); ! } ! } ! throw new RrdException("Unknown RRDTool command: " + command); ! } ! ! public static void main(String[] args) throws IOException { ! System.out.println("== JRobin's RRDTool commander =="); ! System.out.println("Type a RRDTool command after the dollar sign and press Enter."); ! System.out.println("Start your RRDTool command with 'create', 'update', 'fetch' etc."); ! System.out.println("Use any word starting with a dot '.' to bail out"); ! System.out.println("Current directory is: " + new File(".").getCanonicalPath()); ! System.out.println("================================"); ! RrdToolCmd.setRrdDbPoolUsed(false); ! BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); ! while (true) { ! try { ! System.out.print("$ "); ! String s = r.readLine(); ! if(s.startsWith(".")) { ! return; ! } ! execute(s); ! } catch (IOException e) { ! e.printStackTrace(); ! } catch (RrdException e) { ! e.printStackTrace(); ! } ! } ! } ! } --- 1,174 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! ! import java.io.BufferedReader; ! import java.io.File; ! import java.io.IOException; ! import java.io.InputStreamReader; ! ! /** ! * Class to be used to execute various RRDTool commands (original syntax of RRDTool 1.0.x must be used). ! * Currently supported commands are CREATE, UPDATE, LAST, FETCH, DUMP, RESTORE, XPORT, GRAPH, TUNE, INFO ! */ ! public class RrdCommander { ! private static final RrdToolCmd[] rrdCommands = { ! new RrdCreateCmd(), ! new RrdUpdateCmd(), ! new RrdLastCmd(), ! new RrdFetchCmd(), ! new RrdDumpCmd(), ! new RrdRestoreCmd(), ! new RrdXportCmd(), ! new RrdGraphCmd(), ! new RrdTuneCmd(), ! new RrdInfoCmd() ! }; ! ! /** ! * Checks if the output from any RRDTool command will be visible on the standard output device ! * (console). Default setting is <code>true</code>. ! * ! * @return true, if the output will be visible on the standard output device; false, otherwise. ! */ ! public static synchronized boolean isStandardOutUsed() { ! return RrdToolCmd.isStandardOutUsed(); ! } ! ! /** ! * Method used to control access to stdout (System.out, console) for all RRDTool commands. By default, ! * all RRDTool commands are allowed to print results to stdout, in a form used by RRDTool. ! * ! * @param standardOutUsed <code>true</code> if the output should be visible on the ! * standard output device, <code>false</code> otherwise. ! */ ! public static synchronized void setStandardOutUsed(boolean standardOutUsed) { ! RrdToolCmd.setStandardOutUsed(standardOutUsed); ! } ! ! /** ! * Checks if the class uses {@link org.jrobin.core.RrdDbPool} internally while executing ! * RRDTool commands. ! * ! * @return true if the pool is used, false otherwise ! */ ! public static synchronized boolean isRrdDbPoolUsed() { ! return RrdToolCmd.isRrdDbPoolUsed(); ! } ! ! /** ! * Forces or prohibits {@link org.jrobin.core.RrdDbPool} usage internally while executing ! * RRDTool commands ! * ! * @param rrdDbPoolUsed true, to force pool usage, false otherwise. ! */ ! public static synchronized void setRrdDbPoolUsed(boolean rrdDbPoolUsed) { ! RrdToolCmd.setRrdDbPoolUsed(rrdDbPoolUsed); ! } ! ! /** ! * Executes single RRDTool command. The command string should start with some ! * well known RRDTool command word (create, update, fetch, graph...)<p> ! * ! * @param command RRDTool command like: <p> ! * <pre> ! * create test.rrd --start "noon yesterday" --step 300 DS:x:GAUGE:600:U:U RRA:AVERAGE:0.5:5:1000 ! * update test.rrd N:1000 ! * last test.rrd ! * ... ! * </pre> ! * @return Result of specific RRDTool command. It is guaranteed that the result of any ! * successfully executed command will be always different from null. ! * Unsuccessfully executed commands will always throw ! * an exception, so you need not check for null results.<p> ! * Exact type of the result depends from the ! * type of executed RRDTool command:<p> ! * <ul> ! * <li><b>create</b>: returns java.lang.String containing path to the newly created RRD file. ! * <li><b>last</b>: returns java.lang.Long representing timestamp of the last update. ! * <li><b>update</b>: returns java.lang.Long representing timestamp of the last update. ! * <li><b>dump</b>: returns (very long) java.lang.String representing the content of a RRD file ! * in XML format. ! * <li><b>fetch</b>: returns {@link org.jrobin.core.FetchData} object representing fetched data. ! * <li><b>restore</b>: returns path to the restored RRD file. ! * <li><b>xport</b>: returns java.lang.String containing exported data ! * <li><b>graph</b>: returns {@link org.jrobin.graph.RrdGraphInfo} object containing graph info ! * <li><b>tune</b>: returns path to the tuned RRD file ! * </ul> ! * @throws IOException thrown in case of I/O error ! * @throws RrdException thrown for all other errors (parsing errors, ! * unknown RRDTool syntax/command/option, internal RRD errors...) ! */ ! public static synchronized Object execute(String command) throws IOException, RrdException { ! String cmd = command.trim(), rrdtool = "rrdtool "; ! if (cmd.startsWith(rrdtool)) { ! cmd = cmd.substring(rrdtool.length()); ! } ! for (RrdToolCmd rrdCommand : rrdCommands) { ! if (cmd.startsWith(rrdCommand.getCmdType() + " ")) { ! return rrdCommand.executeCommand(cmd); ! } ! } ! throw new RrdException("Unknown RRDTool command: " + command); ! } ! ! /** ! * A small demo which allows you to pass arbitrary RRDTool commands to JRobin ! * ! * @param args Not used ! * @throws IOException ! */ ! public static void main(String[] args) throws IOException { ! System.out.println("== JRobin's RRDTool commander =="); ! System.out.println("Type a RRDTool command after the dollar sign and press Enter."); ! System.out.println("Start your RRDTool command with 'create', 'update', 'fetch' etc."); ! System.out.println("Start line with 'create', 'update', 'fetch' etc."); ! System.out.println("Enter dot ('.') to bail out"); ! System.out.println("Current directory is: " + new File(".").getCanonicalPath()); ! System.out.println("================================"); ! RrdToolCmd.setRrdDbPoolUsed(false); ! BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); ! while (true) { ! try { ! System.out.print("$ "); ! String s = r.readLine().trim(); ! if (s.length() > 0) { ! if (!s.startsWith(".")) { ! execute(s); ! } ! else { ! break; ! } ! } ! } ! catch (Exception e) { ! e.printStackTrace(System.err); ! } ! } ! } ! } Index: RrdDumpCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdDumpCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdDumpCmd.java 16 Jul 2004 07:40:48 -0000 1.2 --- RrdDumpCmd.java 21 Dec 2006 18:02:40 -0000 1.3 *************** *** 1,54 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDb; ! ! import java.io.IOException; ! ! class RrdDumpCmd extends RrdToolCmd { ! String getCmdType() { ! return "dump"; ! } ! ! Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); ! if(words.length != 2) { ! throw new RrdException("Invalid rrddump syntax"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! String xml = rrdDb.getXml(); ! println(xml); ! return xml; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } --- 1,54 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! ! import java.io.IOException; ! ! class RrdDumpCmd extends RrdToolCmd { ! String getCmdType() { ! return "dump"; ! } ! ! Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); ! if (words.length != 2) { ! throw new RrdException("Invalid rrddump syntax"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! String xml = rrdDb.getXml(); ! println(xml); ! return xml; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } Index: RrdUpdateCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdUpdateCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdUpdateCmd.java 17 Feb 2005 10:43:12 -0000 1.2 --- RrdUpdateCmd.java 21 Dec 2006 18:02:40 -0000 1.3 *************** *** 1,89 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.*; ! import org.jrobin.core.timespec.TimeParser; ! import org.jrobin.core.timespec.TimeSpec; ! ! import java.io.IOException; ! ! class RrdUpdateCmd extends RrdToolCmd { ! private String[] dsNames; ! ! String getCmdType() { ! return "update"; ! } ! ! Object execute() throws RrdException, IOException { ! String template = getOptionValue("t", "template"); ! if (template != null) { ! dsNames = template.split(":"); ! } ! String[] words = getRemainingWords(); ! if (words.length < 3) { ! throw new RrdException("Insufficent number of parameters for rrdupdate"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! if (dsNames != null) { ! // template specified, check datasource names ! for (int i = 0; i < dsNames.length; i++) { ! rrdDb.getDsIndex(dsNames[i]); // will throw exception if not found ! } ! } ! // parse update strings ! long timestamp = -1; ! for (int i = 2; i < words.length; i++) { ! String[] tokens = words[i].split(":"); ! if (dsNames != null && dsNames.length + 1 != tokens.length) { ! throw new RrdException("Template required " + dsNames.length + " values, " + ! (tokens.length - 1) + " value(s) found in: " + words[i]); ! } ! int dsCount = rrdDb.getHeader().getDsCount(); ! if (dsNames == null && dsCount + 1 != tokens.length) { ! throw new RrdException("Expected " + dsCount + " values, " + ! (tokens.length - 1) + " value(s) found in: " + words[i]); ! } ! TimeSpec spec = new TimeParser(tokens[0]).parse(); ! timestamp = spec.getTimestamp(); ! Sample sample = rrdDb.createSample(timestamp); ! for (int j = 1; j < tokens.length; j++) { ! if (dsNames == null) { ! sample.setValue(j - 1, parseDouble(tokens[j])); ! } else { ! sample.setValue(dsNames[j - 1], parseDouble(tokens[j])); ! } ! } ! sample.update(); ! } ! return new Long(timestamp); ! } finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } --- 1,90 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! import org.jrobin.core.Sample; ! import org.jrobin.core.Util; ! ! import java.io.IOException; ! ! class RrdUpdateCmd extends RrdToolCmd { ! String getCmdType() { ! return "update"; ! } ! ! Object execute() throws RrdException, IOException { ! String template = getOptionValue("t", "template"); ! String[] dsNames = (template != null) ? new ColonSplitter(template).split() : null; ! String[] words = getRemainingWords(); ! if (words.length < 3) { ! throw new RrdException("Insufficent number of parameters for rrdupdate command"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! if (dsNames != null) { ! // template specified, check datasource names ! for (String dsName : dsNames) { ! if (!rrdDb.containsDs(dsName)) { ! throw new RrdException("Invalid datasource name: " + dsName); ! } ! } ! } ! // parse update strings ! long timestamp = -1; ! for (int i = 2; i < words.length; i++) { ! String[] tokens = new ColonSplitter(words[i]).split(); ! if (dsNames != null && dsNames.length + 1 != tokens.length) { ! throw new RrdException("Template requires " + dsNames.length + " values, " + ! (tokens.length - 1) + " value(s) found in: " + words[i]); ! } ! int dsCount = rrdDb.getHeader().getDsCount(); ! if (dsNames == null && dsCount + 1 != tokens.length) { ! throw new RrdException("Expected " + dsCount + " values, " + ! (tokens.length - 1) + " value(s) found in: " + words[i]); ! } ! timestamp = Util.getTimestamp(tokens[0]); ! Sample sample = rrdDb.createSample(timestamp); ! for (int j = 1; j < tokens.length; j++) { ! if (dsNames == null) { ! sample.setValue(j - 1, parseDouble(tokens[j])); ! } ! else { ! sample.setValue(dsNames[j - 1], parseDouble(tokens[j])); ! } ! } ! sample.update(); ! } ! return timestamp; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } ! Index: RrdLastCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdLastCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdLastCmd.java 16 Jul 2004 07:40:48 -0000 1.2 --- RrdLastCmd.java 21 Dec 2006 18:02:40 -0000 1.3 *************** *** 1,55 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDb; ! ! import java.io.IOException; ! ! class RrdLastCmd extends RrdToolCmd { ! ! String getCmdType() { ! return "last"; ! } ! ! Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); ! if(words.length != 2) { ! throw new RrdException("Invalid rrdlast syntax"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! long lastUpdateTime = rrdDb.getLastUpdateTime(); ! println(lastUpdateTime + ""); ! return new Long(lastUpdateTime); ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } --- 1,55 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdException; ! ! import java.io.IOException; ! ! class RrdLastCmd extends RrdToolCmd { ! ! String getCmdType() { ! return "last"; ! } ! ! Object execute() throws RrdException, IOException { ! String[] words = getRemainingWords(); ! if (words.length != 2) { ! throw new RrdException("Invalid rrdlast syntax"); ! } ! String path = words[1]; ! RrdDb rrdDb = getRrdDbReference(path); ! try { ! long lastUpdateTime = rrdDb.getLastUpdateTime(); ! println(lastUpdateTime + ""); ! return lastUpdateTime; ! } ! finally { ! releaseRrdDbReference(rrdDb); ! } ! } ! } Index: RrdToolCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdToolCmd.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RrdToolCmd.java 16 Jul 2004 08:01:13 -0000 1.5 --- RrdToolCmd.java 21 Dec 2006 18:02:40 -0000 1.6 *************** *** 1,159 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdException; ! import org.jrobin.core.RrdDb; ! import org.jrobin.core.RrdDbPool; ! import org.jrobin.core.RrdDef; ! ! import java.io.IOException; ! ! abstract class RrdToolCmd { ! ! private RrdCmdScanner cmdScanner; ! ! abstract String getCmdType(); ! abstract Object execute() throws RrdException, IOException; ! ! Object executeCommand(String command) throws RrdException, IOException { ! cmdScanner = new RrdCmdScanner(command); ! return execute(); ! } ! ! String getOptionValue(String shortForm, String longForm) throws RrdException { ! return cmdScanner.getOptionValue(shortForm, longForm); ! } ! ! String getOptionValue(String shortForm, String longForm, String defaultValue) throws RrdException { ! return cmdScanner.getOptionValue(shortForm, longForm, defaultValue); ! } ! ! boolean getBooleanOption(String shortForm, String longForm) { ! return cmdScanner.getBooleanOption(shortForm, longForm); ! } ! ! String[] getRemainingWords() { ! return cmdScanner.getRemainingWords(); ! } ! ! static boolean rrdDbPoolUsed = true; ! static boolean standardOutUsed = true; ! ! static boolean isRrdDbPoolUsed() { ! return rrdDbPoolUsed; ! } ! ! static void setRrdDbPoolUsed(boolean rrdDbPoolUsed) { ! RrdToolCmd.rrdDbPoolUsed = rrdDbPoolUsed; ! } ! ! static boolean isStandardOutUsed() { ! return standardOutUsed; ! } ! ! static void setStandardOutUsed(boolean standardOutUsed) { ! RrdToolCmd.standardOutUsed = standardOutUsed; ! } ! ! static long parseLong(String value) throws RrdException { ! try { ! return Long.parseLong(value); ! } ! catch(NumberFormatException nfe) { ! throw new RrdException(nfe); ! } ! } ! ! static int parseInt(String value) throws RrdException { ! try { ! return Integer.parseInt(value); ! } ! catch(NumberFormatException nfe) { ! throw new RrdException(nfe); ! } ! } ! ! static double parseDouble(String value) throws RrdException { ! if(value.equals("U")) { ! return Double.NaN; ! } ! try { ! return Double.parseDouble(value); ! } ! catch(NumberFormatException nfe) { ! throw new RrdException(nfe); ! } ! } ! ! static void print(String s) { ! if(standardOutUsed) { ! System.out.print(s); ! } ! } ! ! static void println(String s) { ! if(standardOutUsed) { ! System.out.println(s); ! } ! } ! ! static RrdDb getRrdDbReference(String path) throws IOException, RrdException { ! if(rrdDbPoolUsed) { ! return RrdDbPool.getInstance().requestRrdDb(path); ! } ! else { ! return new RrdDb(path); ! } ! } ! ! static RrdDb getRrdDbReference(String path, String xmlPath) throws IOException, RrdException { ! if(rrdDbPoolUsed) { ! return RrdDbPool.getInstance().requestRrdDb(path, xmlPath); ! } ! else { ! return new RrdDb(path, xmlPath); ! } ! } ! ! static RrdDb getRrdDbReference(RrdDef rrdDef) throws IOException, RrdException { ! if(rrdDbPoolUsed) { ! return RrdDbPool.getInstance().requestRrdDb(rrdDef); ! } ! else { ! return new RrdDb(rrdDef); ! } ! } ! ! static void releaseRrdDbReference(RrdDb rrdDb) throws IOException, RrdException { ! if(rrdDbPoolUsed) { ! RrdDbPool.getInstance().release(rrdDb); ! } ! else { ! rrdDb.close(); ! } ! } ! } --- 1,164 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.cmd; ! ! import org.jrobin.core.RrdDb; ! i... [truncated message content] |