本文整理汇总了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);
}
}
示例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
);
}
示例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();
}
示例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();
}
示例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 + "]");
}
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
示例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));
}
}
示例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();
}
}
示例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();
}