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


Java Sample.setValue方法代码示例

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


在下文中一共展示了Sample.setValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: execute

import org.jrobin.core.Sample; //导入方法依赖的package包/类
Object execute() throws RrdException, IOException {
	String template = getOptionValue("t", "template");
	String[] dsNames = (template != null) ? new ColonSplitter(template).split() : null;
	String[] words = getRemainingWords();
	if (words.length < 3) {
		throw new RrdException("Insufficent number of parameters for rrdupdate command");
	}
	String path = words[1];
	RrdDb rrdDb = getRrdDbReference(path);
	try {
		if (dsNames != null) {
			// template specified, check datasource names
			for (String dsName : dsNames) {
				if (!rrdDb.containsDs(dsName)) {
					throw new RrdException("Invalid datasource name: " + dsName);
				}
			}
		}
		// parse update strings
		long timestamp = -1;
		for (int i = 2; i < words.length; i++) {
			String[] tokens = new ColonSplitter(words[i]).split();
			if (dsNames != null && dsNames.length + 1 != tokens.length) {
				throw new RrdException("Template requires " + dsNames.length + " values, " +
						(tokens.length - 1) + " value(s) found in: " + words[i]);
			}
			int dsCount = rrdDb.getHeader().getDsCount();
			if (dsNames == null && dsCount + 1 != tokens.length) {
				throw new RrdException("Expected " + dsCount + " values, " +
						(tokens.length - 1) + " value(s) found in: " + words[i]);
			}
			timestamp = Util.getTimestamp(tokens[0]);
			Sample sample = rrdDb.createSample(timestamp);
			for (int j = 1; j < tokens.length; j++) {
				if (dsNames == null) {
					sample.setValue(j - 1, parseDouble(tokens[j]));
				}
				else {
					sample.setValue(dsNames[j - 1], parseDouble(tokens[j]));
				}
			}
			sample.update();
		}
		return timestamp;
	}
	finally {
		releaseRrdDbReference(rrdDb);
	}
}
 
开发者ID:OpenNMS,项目名称:jrobin,代码行数:50,代码来源:RrdUpdateCmd.java


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