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


Java RrdDb.close方法代码示例

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


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

示例1: storeCyclicGpuData

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
public void storeCyclicGpuData(DeviceCyclicData gpu) throws IOException {
	RrdDb db = null;
	try {
		db = RrdDbFactory.getGpuDb(gpu.getClusterId(), gpu.getUntiId(),
				gpu.getDeviceId());
		if (db == null) {
			db = RrdDbFactory.createGpuDb(gpu.getClusterId(), gpu.getUntiId(),
					gpu.getDeviceId());
		}
		List<Integer> data = new LinkedList<>();
		data.add(new BigDecimal(new Date().getTime() / 1000).intValue());
		data.add(gpu.getGpuUsage());
		data.add(gpu.getMemoryUsed());
		data.add(gpu.getFanSpeed());
		RrdHelper.store(data, db);
	} catch (IOException ex) {
		logger.log(Level.SEVERE, "Error while persisting sequential data", ex);
	} finally {
		if (db != null) {
			db.close();
		}
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:24,代码来源:MonitoringStorage.java

示例2: run

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
/**
 * Periodically dumps the new mbean state to the data base
 */
public void run() {
    try {

        RrdDb dataBase = new RrdDb(dataBaseFile);

        logger.debug("RRD database configuration:\n" + dataBase.getRrdDef().dump());

        while (!terminate) {
            synchronized (dataSources) {

                dataSources.wait(step * 1000);

                if (terminate) {
                    break;
                }
                sample(dataBase, System.currentTimeMillis());
            }
        }
        dataBase.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:27,代码来源:RRDSigarDataStore.java

示例3: storeSequentialMessage

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
public void storeSequentialMessage(SequentialMessage message) throws IOException {
	RrdDb db = null;
	try {
		logger.info("Storing message for cluster " + message.getClusterId());
		db = RrdDbFactory.getUnitDb(message.getClusterId(), message.getUnitId());
		if (db == null) {
			db = RrdDbFactory.createUnitDb(message.getCpuCores(),
					message.getClusterId(), message.getUnitId());
		}
		List<Integer> data = new LinkedList<>();
		data.add(new BigDecimal(new Date().getTime() / 1000).intValue());
		data.add(message.getClockSpeed());
		for (int cpuUsage : message.getCpuUsage()) {
			data.add(cpuUsage);
		}
		data.add(message.getMemoryUsed());
		RrdHelper.store(data, db);

		for (DeviceCyclicData gpu : message.getGpuDevices()) {
			storeCyclicGpuData(gpu);
		}
	} catch (IOException ex) {
		logger.log(Level.SEVERE, "Error while persisting sequential data", ex);
	} finally {
		if (db != null) {
			db.close();
		}
	}

	MonitoredEntity entity = new MonitoredEntity(MonitoredEntityType.FAN);
	entity.setClusterId(message.getClusterId());
	entity.setUnitId(message.getUnitId());
	entity.setDeviceId(0);
	RrdHelper.createGraph(entity, RrdDbResolution.EXACT);
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:36,代码来源:MonitoringStorage.java

示例4: addLine

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
/**
 * Adds a line for the item to the graph definition.
 * The color of the line is determined by the counter, it simply picks the according index from LINECOLORS (and rolls over if necessary).
 * 
 * @param graphDef the graph definition to fill
 * @param item the item to add a line for
 * @param counter defines the number of the datasource and is used to determine the line color
 */
protected void addLine(RrdGraphDef graphDef, Item item, int counter) {
	Color color = LINECOLORS[counter%LINECOLORS.length];
	String label = itemUIRegistry.getLabel(item.getName());
	String rrdName = RRD4jService.DB_FOLDER + File.separator + item.getName() + ".rrd";
	ConsolFun consolFun;
	if(label!=null && label.contains("[") && label.contains("]")) {
		label = label.substring(0, label.indexOf('['));
	}
	try {
		RrdDb db = new RrdDb(rrdName);
		consolFun = db.getRrdDef().getArcDefs()[0].getConsolFun();
		db.close();
	} catch (IOException e) {
		consolFun = ConsolFun.MAX;
	}
	if(item instanceof NumberItem) {
		// we only draw a line
		graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); //RRD4jService.getConsolidationFunction(item));
		graphDef.line(Integer.toString(counter), color, label, 2);
	} else {
		// we draw a line and fill the area beneath it with a transparent color
		graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); //RRD4jService.getConsolidationFunction(item));
		Color areaColor = AREACOLORS[counter%LINECOLORS.length];

		graphDef.area(Integer.toString(counter), areaColor);
		graphDef.line(Integer.toString(counter), color, label, 2);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:37,代码来源:RRD4jChartServlet.java

示例5: addRrdData

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private Map<Long, ArrayList<String>> addRrdData(
		Map<Long, ArrayList<String>> data, String itemName,
		ConsolFun consilidationFunction, Date timeBegin, Date timeEnd,
		long resolution) throws IOException {
	RrdDb rrdDb = new RrdDb(RRD_FOLDER + File.separator + itemName + ".rrd");
	FetchRequest fetchRequest = rrdDb.createFetchRequest(
			consilidationFunction, Util.getTimestamp(timeBegin),
			Util.getTimestamp(timeEnd), resolution);
	FetchData fetchData = fetchRequest.fetchData();
	// logger.info(fetchData.toString());
	long[] timestamps = fetchData.getTimestamps();
	double[][] values = fetchData.getValues();

	logger.debug("RRD fetch returned '{}' rows and '{}' columns",
			fetchData.getRowCount(), fetchData.getColumnCount());

	for (int row = 0; row < fetchData.getRowCount(); row++) {
		// change to microseconds
		long time = timestamps[row] * 1000L;

		if (!data.containsKey(time)) {
			data.put(time, new ArrayList<String>());
		}
		ArrayList<String> vals = data.get(time);
		int indexOffset = vals.size();
		for (int dsIndex = 0; dsIndex < fetchData.getColumnCount(); dsIndex++) {
			vals.add(dsIndex + indexOffset,
					formatDouble(values[dsIndex][row], "null", true));
		}
	}
	rrdDb.close();

	return data;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:35,代码来源:RrdResource.java

示例6: log

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
@Override
public void log(Double value) {
	try {
		RrdDb rrdDb = new RrdDb(rrdPath);
		logIntoRRD(rrdDb, value);
		generateGraph(rrdDb);
		rrdDb.close();
	} catch (IOException | IllegalArgumentException e) {
		log.warn("Could not write sample to RRD.", e);
		e.printStackTrace();
	}
}
 
开发者ID:SebiGo,项目名称:BrewControlServer,代码行数:13,代码来源:RRD.java

示例7: RRD

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
/**
 * Constructs the RRD logger object with a name and a physical quantity.
 * 
 * @param name
 *            the name of the data series to be logged and displayed in the
 *            PNG.
 * @param physicalQuantity
 *            the physical quanitity of the data.
 * @throws IOException
 */
public RRD(String name, PhysicalQuantity physicalQuantity) throws IOException {
	this.name = name;
	this.physicalQuantity = physicalQuantity;
	rrdPath = name + ".rrd";
	RrdDef rrdDef = new RrdDef(rrdPath, 1);
	rrdDef.addDatasource(name, DsType.GAUGE, 60, 0D, 110D);
	rrdDef.addArchive(ConsolFun.MAX, 0.5, 1, 60 * 60 * 12);
	RrdDb rrdDb = new RrdDb(rrdDef);
	startTime = Util.getTimestamp();
	log.info("Created RRD database in " + rrdPath + ".");
	rrdDb.close();
}
 
开发者ID:SebiGo,项目名称:BrewControlServer,代码行数:23,代码来源:RRD.java

示例8: addRrdData

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private Map<Long, ArrayList<String>> addRrdData(Map<Long, ArrayList<String>> data, String itemName,
        ConsolFun consilidationFunction, Date timeBegin, Date timeEnd, long resolution) throws IOException {
    RrdDb rrdDb = new RrdDb(RRD_FOLDER + File.separator + itemName + ".rrd");
    FetchRequest fetchRequest = rrdDb.createFetchRequest(consilidationFunction, Util.getTimestamp(timeBegin),
            Util.getTimestamp(timeEnd), resolution);
    FetchData fetchData = fetchRequest.fetchData();
    // logger.info(fetchData.toString());
    long[] timestamps = fetchData.getTimestamps();
    double[][] values = fetchData.getValues();

    logger.debug("RRD fetch returned '{}' rows and '{}' columns", fetchData.getRowCount(),
            fetchData.getColumnCount());

    for (int row = 0; row < fetchData.getRowCount(); row++) {
        // change to microseconds
        long time = timestamps[row] * 1000;

        if (!data.containsKey(time)) {
            data.put(time, new ArrayList<String>());
        }
        ArrayList<String> vals = data.get(time);
        int indexOffset = vals.size();
        for (int dsIndex = 0; dsIndex < fetchData.getColumnCount(); dsIndex++) {
            vals.add(dsIndex + indexOffset, formatDouble(values[dsIndex][row], "null", true));
        }
    }
    rrdDb.close();

    return data;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:31,代码来源:ChartResource.java

示例9: closeDb

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private void closeDb() throws IOException {
    TimeTrace timeTrace = new TimeTrace();
    timeTrace.begin();
    for (RrdDb rrdDb : rrdDbs) {
        rrdDb.close();
    }
    timeTrace.end();
    System.out.printf("closeDb time(Total):%s,count:%s\r\n", timeTrace.getMills(), rrdDbs.size());
    System.out.printf("closeDb time(Avg):%s\r\n", timeTrace.getMills() / rrdDbs.size());
}
 
开发者ID:ChaosXu,项目名称:rrd4j-cassandra,代码行数:11,代码来源:PerformanceTest.java

示例10: addLine

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
/**
 * Adds a line for the item to the graph definition.
 * The color of the line is determined by the counter, it simply picks the according index from LINECOLORS (and
 * rolls over if necessary).
 * 
 * @param graphDef the graph definition to fill
 * @param item the item to add a line for
 * @param counter defines the number of the datasource and is used to determine the line color
 */
protected void addLine(RrdGraphDef graphDef, Item item, int counter) {
    Color color = LINECOLORS[counter % LINECOLORS.length];
    String label = itemUIRegistry.getLabel(item.getName());
    String rrdName = RRD4jService.DB_FOLDER + File.separator + item.getName() + ".rrd";
    ConsolFun consolFun;
    if (label != null && label.contains("[") && label.contains("]")) {
        label = label.substring(0, label.indexOf('['));
    }
    try {
        RrdDb db = new RrdDb(rrdName);
        consolFun = db.getRrdDef().getArcDefs()[0].getConsolFun();
        db.close();
    } catch (IOException e) {
        consolFun = ConsolFun.MAX;
    }
    if (item instanceof NumberItem) {
        // we only draw a line
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        graphDef.line(Integer.toString(counter), color, label, 2);
    } else {
        // we draw a line and fill the area beneath it with a transparent color
        graphDef.datasource(Integer.toString(counter), rrdName, "state", consolFun); // RRD4jService.getConsolidationFunction(item));
        Color areaColor = AREACOLORS[counter % LINECOLORS.length];

        graphDef.area(Integer.toString(counter), areaColor);
        graphDef.line(Integer.toString(counter), color, label, 2);
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:38,代码来源:RRD4jChartServlet.java

示例11: updateSREventCountGraph

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private final void updateSREventCountGraph(RrdDb rrdDb){
	try {
		Sample sample = rrdDb.createSample();
		int j = studentRecordsService.eventCount().getEventCount();
		sample.setAndUpdate("NOW:" + j);
		rrdDb.close();
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
开发者ID:AdamHansrod,项目名称:Graphr,代码行数:11,代码来源:RRD.java

示例12: updateMoodleGraph

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private final void updateMoodleGraph(RrdDb rrdDb){
	try {
		Sample sample = rrdDb.createSample();
		int j = moodleService.moodleUsers().getMoodleUsersCount();
		sample.setAndUpdate("NOW:" + j);
		rrdDb.close();
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
开发者ID:AdamHansrod,项目名称:Graphr,代码行数:11,代码来源:RRD.java

示例13: initDatabase

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
protected void initDatabase() throws IOException {
    if (!new File(dataBaseFile).exists()) {
        if (step <= 0) {
            logger.debug("Provided step is invalid, forcing it to " + DEFAULT_STEP_IN_SECONDS);
            step = DEFAULT_STEP_IN_SECONDS;
        }
        logger.info("Node's statistics are saved in " + dataBaseFile);

        RrdDef rrdDef = new RrdDef(dataBaseFile, System.currentTimeMillis() / 1000, step);

        for (String dataSource : dataSources.keySet()) {
            rrdDef.addDatasource(dataSource, DsType.GAUGE, 600, 0, Double.NaN);
        }

        // for step equals 4 seconds
        // Archive of 10 minutes = 600 seconds (4 * 1 * 150) of completely detailed data
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 1, 150);

        // An archive of 1 hour = 3600 seconds (4 * 5 * 180) i.e. 180 averages of 5 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 5, 180);

        // An archive of 4 hours = 14400 seconds (4 * 10 * 360) i.e. 360 averages of 10 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 10, 360);

        // An archive of 8 hours = 28800 seconds (4 * 20 * 360) i.e. 360 averages of 20 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 20, 360);

        // An archive of 24 hours = 86400 seconds (4 * 30 * 720) i.e. 720 averages of 30 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 30, 720);

        // An archive of 1 week = 604800 seconds (4 * 210 * 720) i.e. 720 averages of 210 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 210, 720);

        // An archive of 1 month ~= 28 days = 604800 seconds (4 * 840 * 720) i.e. 720 averages of 840 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 840, 720);

        // An archive of 1 year = 364 days = 31449600 seconds (4 * 10920 * 720) i.e. 720 averages of 10920 steps
        rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 10920, 720);

        RrdDb dataBase = new RrdDb(rrdDef);
        dataBase.close();
    } else {
        logger.info("Using existing RRD database: " + new File(dataBaseFile).getAbsolutePath());
    }
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:46,代码来源:RRDDataStore.java

示例14: getAttributesHistory

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
@Override
public String getAttributesHistory(String objectName, String[] attrs, String range) throws IOException {

    RrdDb db = new RrdDb(statBaseName, true);

    long timeEnd = db.getLastUpdateTime();
    // force float separator for JSON parsing
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    // formatting will greatly reduce response size
    DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols);

    // construct the JSON response directly in a String
    StringBuilder result = new StringBuilder();
    result.append("{");

    for (int i = 0; i < attrs.length; i++) {

        String dataSource = RRDSigarDataStore.toDataStoreName(attrs[i] + "-" + objectName);

        char zone = range.charAt(0);
        long timeStart;

        switch (zone) {
            default:
            case 'a': // 1 minute
                timeStart = timeEnd - 60;
                break;
            case 'm': // 10 minute
                timeStart = timeEnd - 60 * 10;
                break;
            case 'h': // 1 hours
                timeStart = timeEnd - 60 * 60;
                break;
            case 'H': // 8 hours
                timeStart = timeEnd - 60 * 60 * 8;
                break;
            case 'd': // 1 day
                timeStart = timeEnd - 60 * 60 * 24;
                break;
            case 'w': // 1 week
                timeStart = timeEnd - 60 * 60 * 24 * 7;
                break;
            case 'M': // 1 month
                timeStart = timeEnd - 60 * 60 * 24 * 28;
                break;
            case 'y': // 1 year
                timeStart = timeEnd - 60 * 60 * 24 * 365;
                break;
        }

        FetchRequest req = db.createFetchRequest(ConsolFun.AVERAGE, timeStart, timeEnd);
        req.setFilter(dataSource);
        FetchData fetchData = req.fetchData();
        result.append("\"").append(dataSource).append("\":[");

        double[] values = fetchData.getValues(dataSource);
        for (int j = 0; j < values.length - 1; j++) {
            if (Double.compare(Double.NaN, values[j]) == 0) {
                result.append("null");
            } else {
                result.append(formatter.format(values[j]));
            }
            if (j < values.length - 2)
                result.append(',');
        }
        result.append(']');
        if (i < attrs.length - 1)
            result.append(',');
    }
    result.append("}");

    db.close();

    return result.toString();
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:77,代码来源:SigarProcesses.java

示例15: logIntoRRD

import org.rrd4j.core.RrdDb; //导入方法依赖的package包/类
private void logIntoRRD(RrdDb rrdDb, Double value) throws IOException {
	Sample sample = rrdDb.createSample();
	sample.setValue(name, value);
	sample.update();
	rrdDb.close();
}
 
开发者ID:SebiGo,项目名称:BrewControlServer,代码行数:7,代码来源:RRD.java


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