private byte[] createGraphAsByteArray(String command, File workDir) throws IOException, RrdException { String[] commandArray = StringUtils.createCommandArray(command); Process process; try { process = Runtime.getRuntime().exec(commandArray, null, workDir); } catch (IOException e) { IOException newE = new IOException("IOException thrown while executing command '" + command + "' in " + workDir.getAbsolutePath() + ": " + e); newE.initCause(e); throw newE; } // this closes the stream when its finished byte[] byteArray = FileCopyUtils.copyToByteArray(process.getInputStream()); // this close the stream when its finished String errors = FileCopyUtils.copyToString(new InputStreamReader(process.getErrorStream())); // one particular warning message that originates in libart should be ignored if (errors.length() > 0 && errors.contains(IGNORABLE_LIBART_WARNING_STRING)) { LOG.debug("Ignoring libart warning message in rrdtool stderr stream: {}", IGNORABLE_LIBART_WARNING_STRING); errors = errors.replaceAll(IGNORABLE_LIBART_WARNING_REGEX, ""); } if (errors.length() > 0) { throw new RrdException(errors); } return byteArray; }
private void assertGraphProduced() throws RrdException { if (m_rrdGraph.getRrdGraphInfo().getBytes() == null) { String message = "no graph was produced by JRobin for command '" + getGraphCommand() + "'. Does the command have any drawing commands (e.g.: LINE1, LINE2, LINE3, AREA, STACK, GPRINT)?"; LOG.error(message); throw new RrdException(message); } } }
pngStream = new ByteArrayInputStream(byteArray); } catch (Throwable e) { throw new RrdException("Can't execute command " + command, e); } finally { if (!pngFile.delete()) {
} catch (Throwable e) { LOG.error("updateRRD: Error updating RRD file {} with values '{}'", rrdFile, updateVal, e); throw new org.opennms.netmgt.rrd.RrdException("Error updating RRD file " + rrdFile + " with values '" + updateVal + "': " + e, e); } finally { try { throw new org.opennms.netmgt.rrd.RrdException("Exception closing RRD file " + rrdFile + ": " + e, e);
throw new org.opennms.netmgt.rrd.RrdException("Exception occurred fetching data from " + fileName, e); } catch (RrdException e) { throw new org.opennms.netmgt.rrd.RrdException("Exception occurred fetching data from " + fileName, e); } finally { if (rrd != null) {
} catch (Throwable e) { LOG.error("updateRRD: Error updating RRD file {} with values '{}'", rrdFile, updateVal, e); throw new org.opennms.netmgt.rrd.RrdException("Error updating RRD file " + rrdFile + " with values '" + updateVal + "': " + e, e); } finally { try { throw new org.opennms.netmgt.rrd.RrdException("Exception closing RRD file " + rrdFile + ": " + e, e);
/** {@inheritDoc} */ @Override public Double fetchLastValue(final String fileName, final String ds, final String consolidationFunction, final int interval) throws org.opennms.netmgt.rrd.RrdException { RrdDb rrd = null; try { long now = System.currentTimeMillis(); long collectTime = (now - (now % interval)) / 1000L; rrd = new RrdDb(fileName, true); FetchData data = rrd.createFetchRequest(consolidationFunction, collectTime, collectTime).fetchData(); LOG.debug(data.toString()); double[] vals = data.getValues(ds); if (vals.length > 0) { return new Double(vals[vals.length - 1]); } return null; } catch (IOException e) { throw new org.opennms.netmgt.rrd.RrdException("Exception occurred fetching data from " + fileName, e); } catch (RrdException e) { throw new org.opennms.netmgt.rrd.RrdException("Exception occurred fetching data from " + fileName, e); } finally { if (rrd != null) { try { rrd.close(); } catch (IOException e) { LOG.error("Failed to close rrd file: {}", fileName, e); } } } }
/** * <p>createRRD</p> * * @param creator a {@link java.lang.String} object. * @param directory a {@link java.lang.String} object. * @param rrdName a {@link java.lang.String} object. * @param step a int. * @param dataSources a {@link java.util.List} object. * @param rraList a {@link java.util.List} object. * @return a boolean. * @throws org.opennms.netmgt.rrd.RrdException if any. */ private static boolean createRRD(RrdStrategy<?, ?> rrdStrategy, String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws RrdException { Object def = null; try { RrdStrategy<Object, Object> strategy = toGenericType(rrdStrategy); def = strategy.createDefinition(creator, directory, rrdName, step, dataSources, rraList); // def can be null if the rrd-db exists already, but doesn't have to be (see MultiOutput/QueuingRrdStrategy strategy.createFile(def); return true; } catch (Throwable e) { String path = directory + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); LOG.error("createRRD: An error occurred creating rrdfile {}", path, e); throw new org.opennms.netmgt.rrd.RrdException("An error occurred creating rrdfile " + path + ": " + e, e); } }
/** * <p>createRRD</p> * * @param creator a {@link java.lang.String} object. * @param directory a {@link java.lang.String} object. * @param rrdName a {@link java.lang.String} object. * @param step a int. * @param dataSources a {@link java.util.List} object. * @param rraList a {@link java.util.List} object. * @return a boolean. * @throws org.opennms.netmgt.rrd.RrdException if any. */ private static boolean createRRD(RrdStrategy<?, ?> rrdStrategy, String creator, String directory, String rrdName, int step, List<RrdDataSource> dataSources, List<String> rraList) throws RrdException { Object def = null; try { RrdStrategy<Object, Object> strategy = toGenericType(rrdStrategy); def = strategy.createDefinition(creator, directory, rrdName, step, dataSources, rraList); // def can be null if the rrd-db exists already, but doesn't have to be (see MultiOutput/QueuingRrdStrategy strategy.createFile(def); return true; } catch (Throwable e) { String path = directory + File.separator + rrdName + rrdStrategy.getDefaultFileExtension(); LOG.error("createRRD: An error occurred creating rrdfile {}", path, e); throw new org.opennms.netmgt.rrd.RrdException("An error occurred creating rrdfile " + path + ": " + e, e); } }
} catch (Throwable e) { LOG.error("JRobin: exception occurred creating graph", e); throw new org.opennms.netmgt.rrd.RrdException("An exception occurred creating the graph: " + e.getMessage(), e);