本文整理汇总了Java中org.jrobin.core.RrdDb.createSample方法的典型用法代码示例。如果您正苦于以下问题:Java RrdDb.createSample方法的具体用法?Java RrdDb.createSample怎么用?Java RrdDb.createSample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jrobin.core.RrdDb
的用法示例。
在下文中一共展示了RrdDb.createSample方法的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);
}
}
示例2: 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);
}
示例3: 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();
}
示例4: 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);
}
示例5: 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);
}
示例6: 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();
}
}
示例7: testSampleSetFloatingPointValueGood
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
示例8: testOneEntryInRrd
import org.jrobin.core.RrdDb; //导入方法依赖的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();
}
示例9: testTwoEntriesInRrd
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
示例10: testEntriesNeg50To100InRrd
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
示例11: testEntriesNeg55To105InRrd
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
示例12: testEntriesNeg80To90InRrd
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
示例13: testEntriesNeg80To80InRrd
import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
/**
* Test specifically for JRB-12 (http://issues.opennms.org/browse/JRB-12)
* Related to testEntriesNeg80To90InRrd, except in the original code
* this produced sensible labelling. Implemented to check that the
* changes don't break the sanity.
* @throws FontFormatException
*/
@Test
public void testEntriesNeg80To80InRrd() throws IOException, RrdException, FontFormatException {
createGaugeRrd(180);
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 -80));
}
rrd.close();
prepareGraph();
// Original
expectMinorGridLines(3);
expectMajorGridLine(" -50");
expectMinorGridLines(4);
expectMajorGridLine(" 0");
expectMinorGridLines(4);
expectMajorGridLine(" 50");
expectMinorGridLines(3);
replay(imageWorker);
this.valueAxis.draw();
//Validate the calls to the imageWorker
verify(imageWorker);
}
示例14: execute
import org.jrobin.core.RrdDb; //导入方法依赖的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);
}
}
示例15: updateFile
import org.jrobin.core.RrdDb; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* Creates a sample from the JRobin RrdDb and passes in the data provided.
*/
public void updateFile(final RrdDb rrdFile, final String owner, final String data) throws Exception {
Sample sample = rrdFile.createSample();
sample.setAndUpdate(data);
}