MongoDB聚合时间序列数据

时间:2017-06-09 13:13:26

标签: mongodb mapreduce time-series aggregation-framework

我有以下时间序列数据的文档结构(事件集合)。我根据https://docs.mongodb.com/ecosystem/use-cases/pre-aggregated-reports-mmapv1/

上的文章确定了这种结构
{
    "_id" : "06062017/cpu",
    "metadata" : {
            "host" : "localhost",
            "createdDate" : ISODate("2017-06-09T11:18:56.120Z"),
            "metric" : "cpu"
    },
    "hourly" : {
            "0" : {
                    "total" : 2,
                    "used" : 1
            },
            "1" : {
                    "total" : 3,
                    "used" : 2
            }
    },
    "minute" : {
            "0" : {
                    "0" : {
                            "total" : 9789789,
                            "used" : 353
                    },
                    "1" : {
                            "total" : 0,
                            "used" : 0
                    }
            },
            "1" : {
                    "0" : {
                            "total" : 0,
                            "used" : 0
                    },
                    "1" : {
                            "total" : 234234,
                            "used" : 123
                    }
            }
    }

}

现在我正在尝试从分钟中获取平均cpu并将其存储为每小时。聚合和映射函数在列表和数组上运行良好,我无法从分钟获得每小时的平均值以及我希望每天平均得到的平均值。

我使用java作为编程语言。在应用程序或聚合框架中计算是否更好?

非常感谢任何帮助。

0 个答案:

没有答案
相关问题