Search in sources :

Example 1 with RrdGraphDetails

use of org.opennms.netmgt.rrd.RrdGraphDetails in project opennms by OpenNMS.

the class DefaultRrdDaoIntegrationTest method testNMS4861.

public void testNMS4861() throws Exception {
    //long endTime = 1312775700L;
    //long endTime = 1312838400L;
    long endTime = 1312839213L;
    long startTime = endTime - 86400L;
    String command = "/sw/bin/rrdtool graph -" + " --imgformat PNG" + " --font DEFAULT:7" + " --font TITLE:10" + " --start " + startTime + " --end " + endTime + " --title=\"Netscreen Memory Utilization\"" + " --units-exponent=0 " + " --lower-limit=0" + " DEF:value1=netscreen-host-resources.jrb:NetScrnMemAlloc:AVERAGE" + " DEF:value1min=netscreen-host-resources.jrb:NetScrnMemAlloc:MIN" + " DEF:value1max=netscreen-host-resources.jrb:NetScrnMemAlloc:MAX" + " DEF:value2=netscreen-host-resources.jrb:NetScrnMemLeft:AVERAGE" + " DEF:value2min=netscreen-host-resources.jrb:NetScrnMemLeft:MIN" + " DEF:value2max=netscreen-host-resources.jrb:NetScrnMemLeft:MAX" + " DEF:value3=netscreen-host-resources.jrb:NetScrnMemFrag:AVERAGE" + " DEF:value3min=netscreen-host-resources.jrb:NetScrnMemFrag:MIN" + " DEF:value3max=netscreen-host-resources.jrb:NetScrnMemFrag:MAX" + " LINE2:value1#0000ff:\"1  minute\"" + " GPRINT:value1:AVERAGE:\"Avg \\: %10.2lf\"" + " GPRINT:value1:MIN:\"Min \\: %10.2lf\"" + " GPRINT:value1:MAX:\"Max \\: %10.2lf\\n\"" + " LINE2:value2#00ff00:\"5  minute\"" + " GPRINT:value2:AVERAGE:\"Avg \\: %10.2lf\"" + " GPRINT:value2:MIN:\"Min \\: %10.2lf\"" + " GPRINT:value2:MAX:\"Max \\: %10.2lf\\n\"" + " LINE2:value3#ff0000:\"15 minute\"" + " GPRINT:value3:AVERAGE:\"Avg \\: %10.2lf\"" + " GPRINT:value3:MIN:\"Min \\: %10.2lf\"" + " GPRINT:value3:MAX:\"Max \\: %10.2lf\\n\"" + "";
    final File workDir = new File("src/test/resources");
    final RrdGraphDetails details = m_rrdStrategy.createGraphReturnDetails(command, workDir);
    final File outputFile = File.createTempFile("img", "png");
    IOUtils.copy(details.getInputStream(), new FileOutputStream(outputFile));
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) RrdGraphDetails(org.opennms.netmgt.rrd.RrdGraphDetails)

Example 2 with RrdGraphDetails

use of org.opennms.netmgt.rrd.RrdGraphDetails in project opennms by OpenNMS.

the class JRobinRrdStrategyTest method testPrintThroughInterface.

@Test
public void testPrintThroughInterface() throws Exception {
    long end = System.currentTimeMillis();
    long start = end - (24 * 60 * 60 * 1000);
    String[] command = new String[] { "--start=" + start, "--end=" + end, "CDEF:something=1", "PRINT:something:AVERAGE:\"%le\"" };
    RrdGraphDetails graphDetails = m_strategy.createGraphReturnDetails(StringUtils.arrayToDelimitedString(command, " "), new File(""));
    assertNotNull("graph details object", graphDetails);
    String[] printLines = graphDetails.getPrintLines();
    assertNotNull("graph printLines", printLines);
    assertEquals("graph printLines size", 1, printLines.length);
    assertEquals("graph printLines item 0", "1.000000e+00", printLines[0]);
    double d = Double.parseDouble(printLines[0]);
    assertEquals("graph printLines item 0 as a double", 1.0, d, 0.0);
}
Also used : File(java.io.File) RrdGraphDetails(org.opennms.netmgt.rrd.RrdGraphDetails) Test(org.junit.Test)

Example 3 with RrdGraphDetails

use of org.opennms.netmgt.rrd.RrdGraphDetails in project opennms by OpenNMS.

the class DefaultRrdDao method getPrintValues.

/**
     * <p>getPrintValues</p>
     *
     * @param attribute a {@link org.opennms.netmgt.model.OnmsAttribute} object.
     * @param rraConsolidationFunction a {@link java.lang.String} object.
     * @param startTimeInMillis a long.
     * @param endTimeInMillis a long.
     * @param printFunctions a {@link java.lang.String} object.
     * @return an array of double.
     */
@Override
public double[] getPrintValues(OnmsAttribute attribute, String rraConsolidationFunction, long startTimeInMillis, long endTimeInMillis, String... printFunctions) {
    Assert.notNull(attribute, "attribute argument must not be null");
    Assert.notNull(rraConsolidationFunction, "rraConsolicationFunction argument must not be null");
    Assert.isTrue(endTimeInMillis > startTimeInMillis, "end argument must be after start argument");
    Assert.isAssignable(attribute.getClass(), RrdGraphAttribute.class, "attribute argument must be assignable to RrdGraphAttribute");
    // if no printFunctions are given just use the rraConsolidationFunction
    if (printFunctions.length < 1) {
        printFunctions = new String[] { rraConsolidationFunction };
    }
    RrdGraphAttribute rrdAttribute = (RrdGraphAttribute) attribute;
    String[] command = new String[] { m_rrdBinaryPath, "graph", "-", "--start=" + (startTimeInMillis / 1000), "--end=" + (endTimeInMillis / 1000), "DEF:ds1=" + RrdFileConstants.escapeForGraphing(rrdAttribute.getRrdRelativePath()) + ":" + attribute.getName() + ":" + rraConsolidationFunction };
    String[] printDefs = new String[printFunctions.length];
    for (int i = 0; i < printFunctions.length; i++) {
        printDefs[i] = "PRINT:ds1:" + printFunctions[i] + ":\"%le\"";
    }
    String commandString = StringUtils.arrayToDelimitedString(command, " ") + ' ' + StringUtils.arrayToDelimitedString(printDefs, " ");
    LOG.debug("commandString: {}", commandString);
    RrdGraphDetails graphDetails;
    try {
        graphDetails = m_rrdStrategy.createGraphReturnDetails(commandString, m_rrdBaseDirectory);
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Failure when generating graph to get data with command '" + commandString + "'", e);
    }
    String[] printLines;
    try {
        printLines = graphDetails.getPrintLines();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Failure to get print lines from graph after graphing with command '" + commandString + "'", e);
    }
    if (printLines.length != printFunctions.length) {
        throw new DataAccessResourceFailureException("Returned number of print lines should be " + printFunctions.length + ", but was " + printLines.length + " from command: " + commandString);
    }
    double[] values = new double[printLines.length];
    for (int i = 0; i < printLines.length; i++) {
        if (printLines[i].toLowerCase().endsWith("nan")) {
            values[i] = Double.NaN;
        } else {
            try {
                // To avoid NMS-5592 ~ 2,670374e+03 floating point issue.
                values[i] = Double.parseDouble(printLines[i].replace(",", "."));
            } catch (NumberFormatException e) {
                throw new DataAccessResourceFailureException("Value of line " + (i + 1) + " of output from RRD is not a valid floating point number: '" + printLines[i] + "'");
            }
        }
    }
    return values;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) RrdGraphDetails(org.opennms.netmgt.rrd.RrdGraphDetails)

Aggregations

RrdGraphDetails (org.opennms.netmgt.rrd.RrdGraphDetails)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)1 Test (org.junit.Test)1 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1