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


Java RrdDb.close方法代码示例

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


在下文中一共展示了RrdDb.close方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: setUp

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
@Before
public void setUp() throws RrdException, IOException {
	// Don't use stdout; this silences output if we're outputting to "-"
	// If debugging, you may wish to turn this to true, in case there's
	// output that is helpful in figuring
	// But, note that then you'll get the GIF file printed to stdout as well
	RrdToolCmd.setStandardOutUsed(false);

	// Create a simple JRB file called test-graph-cmd with an RRA called
	// "testvalue" (AVERAGE). Enough to generate graphs using RrdGraphCmd.
	// Note we're not testing the graphing itself, just the parsing
	this.jrbFileName = "target/test-graph-cmd.jrb";
	RrdDef def = new RrdDef(this.jrbFileName);
	def.setStartTime(1000);
	def.setStep(1);
	def.addDatasource("testvalue", "GAUGE", 2, Double.NaN, Double.NaN);
	def.addArchive("RRA:AVERAGE:0.5:1:100");
	RrdDb rrd = new RrdDb(def);
	rrd.close();

	this.graphCmd = new RrdGraphCmd();

}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:24,代码来源:RrdGraphCmdTest.java

示例7: testEntriesZeroTo100InRrd

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
@Test
public void testEntriesZeroTo100InRrd() throws IOException, RrdException, FontFormatException {
	createGaugeRrd(105); //Make sure all entries are recorded (5 is just a buffer for consolidation)
	RrdDb rrd = new RrdDb(jrbFileName);

	for(int i=0; i<100; i++) {
		long timestamp = startTime + 1 + (i * 60);
		Sample sample = rrd.createSample();
		sample.setAndUpdate(timestamp + ":" + i);
	}
	rrd.close();
	prepareGraph();
	expectMinorGridLines(4);
	expectMajorGridLine("  50");
	expectMinorGridLines(4);
	expectMajorGridLine(" 100");

	replay(imageWorker);

	this.valueAxis.draw();
	//Validate the calls to the imageWorker
	verify(imageWorker);

}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:25,代码来源:ValueAxisTest.java

示例8: testEntriesNeg50To0InRrd

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
@Test
public void testEntriesNeg50To0InRrd() throws IOException, RrdException, FontFormatException {
	createGaugeRrd(100);
	RrdDb rrd = new RrdDb(jrbFileName);

	for(int i=0; i<50; i++) {
		long timestamp = startTime + 1 + (i * 60);
		Sample sample = rrd.createSample();
		sample.setAndUpdate(timestamp + ":" + (i -50));
	}
	rrd.close();
	prepareGraph();
	expectMinorGridLines(2);
	expectMajorGridLine(" -40");
	expectMinorGridLines(3);
	expectMajorGridLine(" -20");
	expectMinorGridLines(3);

	replay(imageWorker);

	this.valueAxis.draw();
	//Validate the calls to the imageWorker
	verify(imageWorker);

}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:26,代码来源:ValueAxisTest.java

示例9: createRRDInitData

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
/**
 * 通过RrdDef创建RRD文件并初始化数据
 */
private void createRRDInitData(long startTime, long endTime,
							   String rootPath, String rrdName, RrdDef rrdDef) {
	try {

		RrdDb rrdDb = new RrdDb(rrdDef);
		// / by this point, rrd file can be found on your disk

		// 模拟一些测试数据
		//Math.sin(2 * Math.PI * (t / 86400.0)) * baseval;
		int baseval = 50;
		for (long t = startTime; t < endTime; t += 300) {
			Sample sample = rrdDb.createSample(t);
			double tmpval = Math.random() * baseval;
			double tmpval2 = Math.random() * baseval;
			sample.setValue("input", tmpval + 50);
			sample.setValue("output", tmpval2 + 50);
			sample.update();
		}
		System.out.println("[RrdDb init data success]");
		System.out.println("[Rrd path]:" + rrdDef.getPath());

		// rrdDb.dumpXml(rootPath + rrdName + "_rrd.xml")
		rrdDb.exportXml(rootPath + rrdName + ".xml");

		// If your RRD files are updated rarely, open them only when
		// necessary and close them as soon as possible.
		rrdDb.close();

		System.out.println("[RrdDb export xml success]");
	} catch (Exception e) {
		e.printStackTrace();

	}
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:38,代码来源:TestCoreRrd.java

示例10: releaseRrdDbReference

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
static void releaseRrdDbReference(RrdDb rrdDb) throws IOException, RrdException {
    if (rrdDbPoolUsed) {
        RrdDbPool.getInstance().release(rrdDb);
    }
    else {
        rrdDb.close();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:9,代码来源:RrdToolCmd.java

示例11: createTempRrd

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
public File createTempRrd(final File rrdFile) throws IOException, RrdException {
        final File parentFile = rrdFile.getParentFile();
        final File outputFile = new File(parentFile, rrdFile.getName() + ".temp");
        outputFile.delete(); // just in case there's an old one lying around
        parentFile.mkdirs();
//        LogUtils.debugf(this, "created temporary RRD: %s", outputFile);
        final RrdDb oldRrd = new RrdDb(rrdFile.getAbsolutePath(), true);
        final RrdDef rrdDef = oldRrd.getRrdDef();
        rrdDef.setPath(outputFile.getAbsolutePath());
        rrdDef.setStartTime(0);
        final RrdDb newRrd = new RrdDb(rrdDef);
        newRrd.close();

        return outputFile;
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:16,代码来源:JRobinConverter.java

示例12: updateJrb

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
/**
 * Update JRB.
 *
 * @param jrbFile the JRB file
 * @throws Exception the exception
 */
private void updateJrb(File jrbFile) throws Exception {
    RrdDb rrdDb = new RrdDb(jrbFile);
    for (String ds : rrdDb.getDsNames()) {
        String newDs = getFixedDsName(ds);
        if (!ds.equals(newDs)) {
            log("Updating internal DS name from %s to %s\n", ds, newDs);
            rrdDb.getDatasource(ds).setDsName(newDs);
        }
    }
    rrdDb.close();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:18,代码来源:JmxRrdMigratorOffline.java

示例13: testUpgradeMultiMetric

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
/**
 * Test upgrade (multi-metric JRBs, i.e. storeByGroup=true).
 *
 * @throws Exception the exception
 */
@Test
public void testUpgradeMultiMetric() throws Exception {
    FileUtils.copyDirectory(new File("src/test/resources/rrd2"), new File("target/home/rrd"));

    File config = new File("target/home/etc/opennms.properties");
    Properties p = new Properties();
    p.load(new FileReader(config));
    p.setProperty("org.opennms.rrd.storeByGroup", "true");
    p.store(new FileWriter(config), null);

    executeMigrator();

    File jrbFile = new File("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.jrb");
    Assert.assertTrue(jrbFile.exists());
    RrdDb jrb = new RrdDb(jrbFile, true);
    String[] dataSources = jrb.getDsNames();
    jrb.close();

    Properties dsProp = new Properties();
    dsProp.load(new FileReader("target/home/rrd/1/opennms-jvm/ds.properties"));

    Properties meta = new Properties();
    meta.load(new FileReader("target/home/rrd/1/opennms-jvm/java_lang_type_MemoryPool_name_Survivor_Space.meta"));

    for (String ds : dataSources) {
        Assert.assertFalse(ds.contains("."));
        Assert.assertEquals("java_lang_type_MemoryPool_name_Survivor_Space", dsProp.getProperty(ds));
        Assert.assertEquals(ds, meta.getProperty("JMX_java.lang:type=MemoryPool.name.Survivor Space." + ds));
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:36,代码来源:JmxRrdMigratorOfflineTest.java

示例14: releaseRrdDbReference

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
static void releaseRrdDbReference(RrdDb rrdDb) throws IOException, RrdException {
	if (rrdDbPoolUsed) {
		RrdDbPool.getInstance().release(rrdDb);
	}
	else {
		rrdDb.close();
	}
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:9,代码来源:RrdToolCmd.java

示例15: createGaugeRrd

import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
private void createGaugeRrd(int rowCount) throws IOException, RrdException {
	RrdDef def = new RrdDef(jrbFileName);
	def.setStartTime(startTime);
	def.setStep(60);
	def.addDatasource("testvalue", "GAUGE", 120, Double.NaN, Double.NaN);
	def.addArchive("RRA:AVERAGE:0.5:1:"+rowCount);

	//Create the empty rrd.  Other code may open and append data
	RrdDb rrd = new RrdDb(def);
	rrd.close();
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:12,代码来源:ValueAxisTest.java


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