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


Java Sample类代码示例

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


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

示例1: addValue

import org.jrobin.core.Sample; //导入依赖的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: testSampleSetFloatingPointValueWithComma

import org.jrobin.core.Sample; //导入依赖的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

示例3: testSampleSetFloatingPointValueWithExtraJunk

import org.jrobin.core.Sample; //导入依赖的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

示例4: testEntriesZeroTo100InRrd

import org.jrobin.core.Sample; //导入依赖的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

示例5: testEntriesNeg50To0InRrd

import org.jrobin.core.Sample; //导入依赖的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

示例6: createRRDInitData

import org.jrobin.core.Sample; //导入依赖的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

示例7: testCreate

import org.jrobin.core.Sample; //导入依赖的package包/类
@Test
public void testCreate() throws Exception {
    File rrdFile = createRrdFile();
    
    RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
    //m_strategy.updateFile(openedFile, "huh?", "N:1,234234");
    
    Sample sample = ((RrdDb) openedFile).createSample();
    sample.set("N:1.234 something not that politically incorrect");
    System.err.println(sample.dump());

    m_strategy.closeFile(openedFile);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:14,代码来源:JRobinRrdStrategyTest.java

示例8: testSampleSetFloatingPointValueGood

import org.jrobin.core.Sample; //导入依赖的package包/类
@Test
public void testSampleSetFloatingPointValueGood() 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,代码行数:15,代码来源:JRobinRrdStrategyTest.java

示例9: write

import org.jrobin.core.Sample; //导入依赖的package包/类
public void write(final RrdEntry entry) throws IOException, RrdException {
        final Sample s = m_rrd.createSample(entry.getTimestamp());
        final double[] values = new double[entry.getDsNames().size()];
        int i = 0;
        for (final String dsName : entry.getDsNames()) {
            if (dsName != null) {
                Double value = entry.getValue(dsName);
                final Datasource dataSource = m_rrd.getDatasource(dsName);
                if (value != null) {
                    if (dataSource.getDsType().equals("COUNTER")) {
                        final double counterValue = getLastValue(dsName) + (value * m_step);
                        if (Double.isInfinite(counterValue)) {
                            // if we've overrun the counter, calculate our own counter loop
                            final BigDecimal bigValue = BigDecimal.valueOf(value);
                            final BigDecimal bigLastValue = BigDecimal.valueOf(getLastValue(dsName));
                            final BigDecimal bigStep = BigDecimal.valueOf(m_step);
                            final BigDecimal newValue = bigLastValue.multiply(bigStep).add(bigValue).subtract(m_doubleMax);
                            value = newValue.doubleValue();
                        } else {
                            value = counterValue;
                        }
                    }
                    values[i] = value;
                    setLastValue(dsName, value);
                }
            }
            i++;
        }
        s.setValues(values);
//        LogUtils.debugf(this, "writing sample to %s: %s", outputRrd, s);
        s.update();
    }
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:33,代码来源:RrdDatabaseWriter.java

示例10: testRrdUpdate

import org.jrobin.core.Sample; //导入依赖的package包/类
@Test
	public void testRrdUpdate() throws Exception {
		Sample sample = null;
		long startTime = System.currentTimeMillis() - 1000;
//		for (int i = 0; i < 1000000; i++) {
			sample = m_db.createSample();
			sample.setAndUpdate(startTime + ":" + m_random.nextInt());
			//sample.setAndUpdate(startTime++ + ":" + m_random.nextInt());
//		}
	}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:11,代码来源:JRobinTest.java

示例11: testOneEntryInRrd

import org.jrobin.core.Sample; //导入依赖的package包/类
@Test
public void testOneEntryInRrd() throws IOException, RrdException, FontFormatException {
	createGaugeRrd(100);
	RrdDb rrd = new RrdDb(jrbFileName);
	long nowSeconds = new Date().getTime();
	long fiveMinutesAgo = nowSeconds - (5 * 60);
	Sample sample = rrd.createSample();
	sample.setAndUpdate(fiveMinutesAgo+":10");
	rrd.close();
	prepareGraph();
	checkForBasicGraph();
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:13,代码来源:ValueAxisTest.java

示例12: testTwoEntriesInRrd

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

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

	expectMajorGridLine("  90");
	expectMinorGridLines(1);
	expectMajorGridLine(" 100");
	expectMinorGridLines(1);
	expectMajorGridLine(" 110");
	expectMinorGridLines(1);
	expectMajorGridLine(" 120");
	expectMinorGridLines(1);

	replay(imageWorker);

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

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

示例13: testEntriesNeg50To100InRrd

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

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

	replay(imageWorker);

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

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

示例14: testEntriesNeg55To105InRrd

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

	for(int i=0; i<160; i++) {
		long timestamp = startTime + 1 + (i * 60);
		Sample sample = rrd.createSample();
		sample.setAndUpdate(timestamp + ":" + (i -55));
	}
	rrd.close();
	prepareGraph();
	/**
	 * Prior to JRB-12 fix, this was the behaviour.  Note the lack of a decent negative label
	expectMinorGridLines(3);
	expectMajorGridLine("   0");
	expectMinorGridLines(4);
	expectMajorGridLine(" 100");
	expectMinorGridLines(1);
	 */
	//New behaviour is better; no minor grid lines, which is interesting, but much better representation
	expectMajorGridLine(" -50");
	expectMajorGridLine("   0");
	expectMajorGridLine("  50");
	expectMajorGridLine(" 100");



	replay(imageWorker);

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

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

示例15: testEntriesNeg80To90InRrd

import org.jrobin.core.Sample; //导入依赖的package包/类
/**
 * Test specifically for JRB-12 (http://issues.opennms.org/browse/JRB-12)
 * In the original, when the values go from -80 to 90 on a default height graph
 * (i.e. limited pixels available for X-axis labelling),ValueAxis gets all confused
 * and decides it can only display "0" on the X-axis  (there's not enough pixels
 * for more labels, and none of the Y-label factorings available work well enough
 * @throws FontFormatException
 */
@Test
public void testEntriesNeg80To90InRrd() throws IOException, RrdException, FontFormatException {
	createGaugeRrd(180);
	RrdDb rrd = new RrdDb(jrbFileName);

	for(int i=0; i<170; i++) {
		long timestamp = startTime + 1 + (i * 60);
		Sample sample = rrd.createSample();
		sample.setAndUpdate(timestamp + ":" + (i -80));
	}
	rrd.close();
	prepareGraph();
	/**
	 * Original behaviour; a single major X-axis label (0) only.
	expectMinorGridLines(4);
	expectMajorGridLine("   0");
	expectMinorGridLines(4);
	 */
	//New behaviour post JRB-12 fix:
	expectMajorGridLine(" -50");
	expectMajorGridLine("   0");
	expectMajorGridLine("  50");

	replay(imageWorker);

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

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


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