3

我有服务器日志记录了一个月的流量。下面的部分示例

"UploadDateGMT","UserFileSize","TotalBusinessUnits"
"2012-01-01 00:00:38","1223","1"
"2012-01-01 00:01:16","1302","1"
"2012-01-01 00:08:10","1302","1"

我想将其转换为一个数据集,在其中我可以滚动计算每五分钟窗口中提交的字节数。(即 0-5、1-6、2-7 等)从中,我可以提取最大负载、95% 负载、制作漂亮的负载图表等。

4

2 回答 2

4

要扩展@PLapointe 的答案

endp <- endpoints(tab2, on="mins", k=1) # 1 minute endpoints
onemin <- period.apply(tab2,endp,sum)   # sum per 1-minute period
onemin <- align.time(onemin)            # align to end-of-period times
# all one-minute increments from start--end of onemin
allonemin <- seq(start(onemin), end(onemin), by="1 min")
onemin <- merge(onemin, xts(,allonemin))
fivemin <-  rollapplyr(onemin, 5, sum, na.rm=TRUE, fill=NA)
于 2012-05-24T16:53:48.840 回答
3

xts 包可以解决问题:

library(xts)
tab <-read.table(text="UploadDateGMT,UserFileSize,TotalBusinessUnits
'2012-01-01 00:00:38',1223,1
'2012-01-01 00:01:16',1302,1
'2012-01-01 00:08:10',1302,1", header=TRUE, as.is=TRUE,sep = ",")

tab2<-xts(tab$UserFileSize,order.by=as.POSIXct(tab$UploadDateGMT) ) #create xts object
endp <-endpoints(tab2, on="mins", k=5) #5 minutes endpoints
fivemin <-period.apply(tab2,endp,sum) #sum per 5-minute period
fivemin

                    [,1]
2012-01-01 00:01:16 2525
2012-01-01 00:08:10 1302

如果您希望时间列以 5 分钟为增量:

res<- align.time( fivemin[endpoints(fivemin, on="mins", k=5)], n=60*5)
于 2012-05-24T16:27:57.440 回答