本文整理汇总了Java中org.jrobin.core.Sample.update方法的典型用法代码示例。如果您正苦于以下问题:Java Sample.update方法的具体用法?Java Sample.update怎么用?Java Sample.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jrobin.core.Sample
的用法示例。
在下文中一共展示了Sample.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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();
}
}
示例3: 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();
}
示例4: 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);
}
}