• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FetchData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.rrd4j.core.FetchData的典型用法代码示例。如果您正苦于以下问题:Java FetchData类的具体用法?Java FetchData怎么用?Java FetchData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FetchData类属于org.rrd4j.core包,在下文中一共展示了FetchData类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: query

import org.rrd4j.core.FetchData; //导入依赖的package包/类
public double query(String dsName, long startTimestamp, long endTimestamp, ConsolFun consolidationFunction) {
    long tStart = convertToUnixTimestamp(startTimestamp);
    long tEnd = convertToUnixTimestamp(endTimestamp);
    if (tStart == tEnd) {
        this.logger.warn("Shifting end time by 1 second because it is identical with the start time.");
        tEnd++;
    }
    try {
        final FetchRequest request = this.rrdDb.createFetchRequest(consolidationFunction, tStart, tEnd);
        final FetchData fetchData = request.fetchData();
        return fetchData.getAggregate(dsName, consolidationFunction);
    } catch (IOException e) {
        e.printStackTrace();
        return Double.NaN;
    }
}
 
开发者ID:daqcri,项目名称:rheem,代码行数:17,代码来源:RrdAccessor.java


示例2: addRrdData

import org.rrd4j.core.FetchData; //导入依赖的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


示例3: addRrdData

import org.rrd4j.core.FetchData; //导入依赖的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


示例4: getAttributesHistory

import org.rrd4j.core.FetchData; //导入依赖的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


示例5: testSpike

import org.rrd4j.core.FetchData; //导入依赖的package包/类
@Test
public void testSpike() throws IOException {
    RrdDef rrdDef = new RrdDef("testSpike.rrd", 0, 60);
    rrdDef.setVersion(2);
    rrdDef.addDatasource("ds", GAUGE, 3600, -5, 30);
    rrdDef.addArchive(AVERAGE, 0.5, 60, 999);
    RrdDb rrdDb = new RrdDb(rrdDef,factory);

    Calendar testTime = Calendar.getInstance();
    testTime.set(Calendar.MINUTE, 0);
    testTime.set(Calendar.SECOND, 0);
    testTime.set(Calendar.MILLISECOND, 0);
    System.out.println(testTime);
    //testTime.add(Calendar.HOUR, -1);
    long start =  Util.getTimestamp(testTime);
    long timeStamp = start;

    for(int i = 0; i < 180; i++) {
        long  sampleTime = timeStamp;
        if(i == 117) {
            sampleTime += -1;
        }
        rrdDb.createSample(sampleTime).setValue("ds", 30).update();
        timeStamp += 60;
    }

    long end = timeStamp;
    FetchData f = rrdDb.createFetchRequest(AVERAGE, start, end).fetchData();
    System.out.println(f.dump());
    double[] values = f.getValues("ds");

    assertTrue("Data before first entry", Double.isNaN(values[0]));
    assertEquals("Bad average in point 1", 30, values[1], 1e-3);
    assertEquals("Bad average in point 2", 30, values[2], 1e-3);
    assertTrue("Data after last entry", Double.isNaN(values[3]));

    rrdDb.close();

    RrdDb rrdDbForRead = new RrdDb("testSpike.rrd",factory);
    FetchData result = rrdDbForRead.createFetchRequest(AVERAGE, start, end).fetchData();
    System.out.println(f.dump());
    double[] resultData = result.getValues("ds");

    assertTrue("Data before first entry", Double.isNaN(resultData[0]));
    assertEquals("Bad average in point 1", 30, resultData[1], 1e-3);
    assertEquals("Bad average in point 2", 30, resultData[2], 1e-3);
    assertTrue("Data after last entry", Double.isNaN(resultData[3]));

    rrdDbForRead.close();
}
 
开发者ID:ChaosXu,项目名称:rrd4j-cassandra,代码行数:51,代码来源:CassandraBackendTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EmptyWatcher类代码示例发布时间:2022-05-22
下一篇:
Java EmbeddedJMS类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap