当前位置: 首页>>代码示例>>Java>>正文


Java RrdDb类代码示例

本文整理汇总了Java中org.jrobin.core.RrdDb的典型用法代码示例。如果您正苦于以下问题:Java RrdDb类的具体用法?Java RrdDb怎么用?Java RrdDb使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RrdDb类属于org.jrobin.core包,在下文中一共展示了RrdDb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addValue

import org.jrobin.core.RrdDb; //导入依赖的package包/类
private void addValue(double value) throws IOException {
  try {
    // Open the existing file in r/w mode:
    RrdDb rrdDb = new RrdDb(_rrdPath, false, _rrdBackendFactory);
    try {
      // Create sample with the current timestamp:
      Sample sample = rrdDb.createSample();
      if (sample.getTime() > rrdDb.getLastUpdateTime()) {
        sample.setValue(_name, value);
        sample.update();
      }
    }
    finally {
      rrdDb.close();
    }
  }
  catch (RrdException e) {
    String msg = "Accessing JRobin statistics file '" + _rrdPath + "' failed! If the problem persists, delete the file so it will be recreated.";
    LOG.error(msg, e);
    throw new IOException(msg, e);
  }
}
 
开发者ID:purej,项目名称:purej-vminspect,代码行数:23,代码来源:Statistics.java

示例2: getCurrentValue

import org.jrobin.core.RrdDb; //导入依赖的package包/类
public double[] getCurrentValue(String key) {
    if (ClusterManager.isSeniorClusterMember()) {
        return new double[] { engine.getDefinition(key)[0].getLastSample() };
    }
    else {
        try {
            if (RrdSqlBackend.exists(key)) {
                RrdDb db = new RrdDb(key, true);
                return new double[] { db.getLastDatasourceValues()[0] };
            }
        } catch (Exception e) {
            Log.error("Error retrieving last sample value for: " + key, e);
        }
        return new double[] { 0 };
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:17,代码来源:DefaultStatsViewer.java

示例3: setConfigurationProperties

import org.jrobin.core.RrdDb; //导入依赖的package包/类
/** {@inheritDoc} */
public void setConfigurationProperties(final Properties configurationParameters) {
    m_configurationProperties = configurationParameters;
    if(!s_initialized) {
        String factory = null;
        if (m_configurationProperties == null) {
            factory = DEFAULT_BACKEND_FACTORY;
        } else {
            factory = (String)m_configurationProperties.get(BACKEND_FACTORY_PROPERTY);
        }
        try {
            RrdDb.setDefaultFactory(factory);
            s_initialized=true;
        } catch (RrdException e) {
            log().error("Could not set default JRobin RRD factory: " + e.getMessage(), e);
        }
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:JRobinRrdStrategy.java

示例4: createFile

import org.jrobin.core.RrdDb; //导入依赖的package包/类
/**
 * Creates the JRobin RrdDb from the def by opening the file and then
 * closing.
 *
 * @param rrdDef a {@link org.jrobin.core.RrdDef} object.
 * @throws java.lang.Exception if any.
 */
public void createFile(final RrdDef rrdDef,  Map<String, String> attributeMappings) throws Exception {
    if (rrdDef == null) {
    	log().debug("createRRD: skipping RRD file");
        return;
    }
    log().info("createRRD: creating RRD file " + rrdDef.getPath());
    
    RrdDb rrd = new RrdDb(rrdDef);
    rrd.close();

    String filenameWithoutExtension = rrdDef.getPath().replace(RrdUtils.getExtension(), "");
    int lastIndexOfSeparator = filenameWithoutExtension.lastIndexOf(File.separator);

    RrdUtils.createMetaDataFile(
        filenameWithoutExtension.substring(0, lastIndexOfSeparator),
        filenameWithoutExtension.substring(lastIndexOfSeparator),
        attributeMappings
    );
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:27,代码来源:JRobinRrdStrategy.java

示例5: testSampleSetFloatingPointValueWithComma

import org.jrobin.core.RrdDb; //导入依赖的package包/类
/**
 * This test fails because of
 * <a href="http://bugzilla.opennms.org/show_bug.cgi?id=2272">bug #2272</a>
 * in org.jrobin.core.Sample.
 */
@Test
@Ignore("fails due to bug 2272")
public void testSampleSetFloatingPointValueWithComma() throws Exception {
    File rrdFile = createRrdFile();
    
    RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
    
    Sample sample = openedFile.createSample();
    sample.set("N:1,234");
    m_strategy.closeFile(openedFile);
    
    double[] values = sample.getValues();
    assertEquals("values list size", 1, values.length);
    assertEquals("values item 0", 1.234, values[0], 0.0);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:21,代码来源:JRobinRrdStrategyTest.java

示例6: testSampleSetFloatingPointValueWithExtraJunk

import org.jrobin.core.RrdDb; //导入依赖的package包/类
/**
 * This test fails because of
 * <a href="http://bugzilla.opennms.org/show_bug.cgi?id=2272">bug #2272</a>
 * in org.jrobin.core.Sample.
 */
@Test
@Ignore("fails due to bug 2272")
public void testSampleSetFloatingPointValueWithExtraJunk() throws Exception {
    File rrdFile = createRrdFile();
    
    RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
    
    Sample sample = openedFile.createSample();
    
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new Exception("Some exception that complains about bogus data"));
    try {
        sample.set("N:1.234 extra junk");
    } catch (Throwable t) {
        ta.throwableReceived(t);
    } finally {
        m_strategy.closeFile(openedFile);
    }
    ta.verifyAnticipated();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:JRobinRrdStrategyTest.java

示例7: consolidateRrdFile

import org.jrobin.core.RrdDb; //导入依赖的package包/类
public void consolidateRrdFile(final File groupFile, final File outputFile) throws IOException, RrdException, ConverterException {
    final List<RrdDatabase> rrds = new ArrayList<RrdDatabase>();
    rrds.add(new RrdDatabase(new RrdDb(groupFile, true)));
    for (final File individualFile : getMatchingGroupRrds(groupFile)) {
        final RrdDb individualRrd = new RrdDb(individualFile, true);
        rrds.add(new RrdDatabase(individualRrd));
    }
    final TimeSeriesDataSource dataSource = new AggregateTimeSeriesDataSource(rrds);

    final RrdDb outputRrd = new RrdDb(outputFile);
    final RrdDatabaseWriter writer = new RrdDatabaseWriter(outputRrd);

    final long endTime = dataSource.getEndTime();
    // 1 year
    final long startTime = endTime - ONE_YEAR_IN_SECONDS;
    for (long time = startTime; time <= endTime; time += dataSource.getNativeStep()) {
        final RrdEntry entry = dataSource.getDataAt(time);
        writer.write(entry);
    }
    dataSource.close();
    outputRrd.close();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:23,代码来源:JRobinConverter.java

示例8: initializeRrd

import org.jrobin.core.RrdDb; //导入依赖的package包/类
private void initializeRrd(final File fileName, final String[] dsNames, final String[] archives) throws RrdException, IOException {
    final RrdDef rrdDef = new RrdDef(fileName.getAbsolutePath());
    rrdDef.setStartTime(0);
    final DsDef[] dsDefs = new DsDef[dsNames.length];
    for (int i = 0; i < dsNames.length; i++) {
        dsDefs[i] = new DsDef(dsNames[i], "COUNTER", 600, 0, Double.NaN);
    }
    rrdDef.addDatasource(dsDefs);
    final ArcDef[] arcDefs = new ArcDef[archives.length];
    for (int i = 0; i < archives.length; i++) {
        String[] entry = archives[i].split(":");
        Integer steps = Integer.valueOf(entry[0]);
        Integer rows = Integer.valueOf(entry[1]);
        arcDefs[i] = new ArcDef("AVERAGE", 0.5D, steps, rows);
    }
    rrdDef.addArchive(arcDefs);
    final RrdDb db = new RrdDb(rrdDef);
    db.close();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:20,代码来源:JRobinConverterTest.java

示例9: testRrdDatabaseAndAggregateRrdDatabase

import org.jrobin.core.RrdDb; //导入依赖的package包/类
@Test
public void testRrdDatabaseAndAggregateRrdDatabase() throws Exception {
    createMockSineRrds(null);
    long dbTime = 0;
    long aggTime = 0;
    for (int i = 0; i < 20; i++) {
        RrdDb source = new RrdDb(m_sineSource);
        RrdDatabase sourceDatabase = new RrdDatabase(source);

        TimeSeriesDataSource aggregate = new AggregateTimeSeriesDataSource(Collections.singletonList(sourceDatabase));

        long dbStart = System.nanoTime();
        List<RrdEntry> rawEntries = sourceDatabase.getData(150);
        dbTime += System.nanoTime() - dbStart;
        
        long aggStart = System.nanoTime();
        List<RrdEntry> aggregateEntries = aggregate.getData(150);
        aggTime += System.nanoTime() - aggStart;

        assertEquals(aggregate.getEndTime() + 150, aggregateEntries.get(aggregateEntries.size() - 1).getTimestamp());
        assertEquals(rawEntries.size(), aggregateEntries.size());
    }
    LogUtils.debugf(this, "dbTime = %d (%f)", dbTime, dbTime / 1000000.0 / 20.0);
    LogUtils.debugf(this, "aggTime = %d (%f)", aggTime, aggTime / 1000000.0 / 20.0);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:JRobinConverterTest.java

示例10: testRrdDatabaseAndAggregateRrdDatabaseGetDataAt

import org.jrobin.core.RrdDb; //导入依赖的package包/类
@Test
public void testRrdDatabaseAndAggregateRrdDatabaseGetDataAt() throws Exception {
    createMockSineRrds(null);
    long dbTime = 0;
    long aggTime = 0;
    for (int i = 0; i < 20; i++) {
        RrdDb source = new RrdDb(m_sineSource);
        RrdDatabase sourceDatabase = new RrdDatabase(source);

        TimeSeriesDataSource aggregate = new AggregateTimeSeriesDataSource(Collections.singletonList(sourceDatabase));

        long dbStart = System.nanoTime();
        List<RrdEntry> rawEntries = getAllData(sourceDatabase);
        dbTime += System.nanoTime() - dbStart;
        
        long aggStart = System.nanoTime();
        List<RrdEntry> aggregateEntries = getAllData(aggregate);
        aggTime += System.nanoTime() - aggStart;

        assertEquals(aggregate.getEndTime() + 150, aggregateEntries.get(aggregateEntries.size() - 1).getTimestamp());
        assertEquals(rawEntries.size(), aggregateEntries.size());
    }
    LogUtils.debugf(this, "dbTime = %d (%f)", dbTime, dbTime / 1000000.0 / 20.0);
    LogUtils.debugf(this, "aggTime = %d (%f)", aggTime, aggTime / 1000000.0 / 20.0);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:JRobinConverterTest.java

示例11: testAggregateWithOverlappingData

import org.jrobin.core.RrdDb; //导入依赖的package包/类
@Test
public void testAggregateWithOverlappingData() throws Exception {
    createMockVariationRrds(null);
    RrdDatabase overlappingDatabase = new RrdDatabase(new RrdDb(m_overlapping, true));
    RrdDatabase variationDatabase = new RrdDatabase(new RrdDb(m_variation, true));
    List<RrdDatabase> datasources = new ArrayList<RrdDatabase>();
    datasources.add(overlappingDatabase);
    datasources.add(variationDatabase);

    TimeSeriesDataSource aggregate = new AggregateTimeSeriesDataSource(datasources);
    final List<String> aggregateDsNames = Arrays.asList(new String[] { "c", "d", "a", "b" });

    assertEquals(variationDatabase.getStartTime(), overlappingDatabase.getStartTime());
    assertEquals(variationDatabase.getStartTime(), aggregate.getStartTime());
    assertEquals(variationDatabase.getEndTime(), overlappingDatabase.getEndTime());
    assertEquals(variationDatabase.getEndTime(), aggregate.getEndTime());
    assertEquals(aggregateDsNames, aggregate.getDsNames());

    assertEquals(1.0933333333333D, aggregate.getDataAt(1297956000).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
    assertEquals(1.1966666666666D, aggregate.getDataAt(1297956300).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
    assertEquals(1.1000000000000D, aggregate.getDataAt(1297956600).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
    assertEquals(1.1033333333333D, aggregate.getDataAt(1297956900).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:24,代码来源:JRobinConverterTest.java

示例12: testCombine

import org.jrobin.core.RrdDb; //导入依赖的package包/类
@Test
public void testCombine() throws Exception {
    createMockSineRrds(null);
    final File newFile = m_converter.createTempRrd(m_sineFull);
    try {
        m_converter.consolidateRrdFile(m_sineFull, newFile);
        RrdDb newRrd = new RrdDb(newFile.getPath(), true);
        TimeSeriesDataSource rrdDatabase = new RrdDatabase(newRrd);

        assertEquals(m_baseTime, newRrd.getLastArchiveUpdateTime());
        Archive archive = newRrd.getArchive(0);
        Robin robin = archive.getRobin(newRrd.getDsIndex("a"));
        assertEquals(4032, robin.getSize());
        assertEquals(Double.NaN, rrdDatabase.getDataAt(1293195600).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
        assertEquals(0.049532528339D, rrdDatabase.getDataAt(1293210000).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
        assertEquals(0.023333333333D, rrdDatabase.getDataAt(1298046000).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
    } finally {
        newFile.delete();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:21,代码来源:JRobinConverterTest.java

示例13: convertFile

import org.jrobin.core.RrdDb; //导入依赖的package包/类
private void convertFile(String path) {
	long start = System.currentTimeMillis();
	totalCount++;
	try {
		File rrdFile = new File(path);
		print(countFormatter.format(totalCount) + "/" + countFormatter.format(files.length) +
				" " + rrdFile.getName() + " ");
		String sourcePath = rrdFile.getCanonicalPath();
		String destPath = sourcePath + SUFFIX;
		RrdDb rrd = new RrdDb(destPath, RrdDb.PREFIX_RRDTool + sourcePath);
		rrd.close();
		goodCount++;
		double seconds = (System.currentTimeMillis() - start) / 1000.0;
		println("[OK, " + secondsFormatter.format(seconds) + " sec]");
	}
	catch (Exception e) {
		badCount++;
		println("[" + e + "]");
	}
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:21,代码来源:Convertor.java

示例14: execute

import org.jrobin.core.RrdDb; //导入依赖的package包/类
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);
	}
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:17,代码来源:RrdDumpCmd.java

示例15: execute

import org.jrobin.core.RrdDb; //导入依赖的package包/类
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);
	}
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:17,代码来源:RrdLastCmd.java


注:本文中的org.jrobin.core.RrdDb类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。