0.5.0 • Published 10 years ago
rts v0.5.0
rts
Use redis as time series data store.
- Data for the line chart of a period time, can be use to stat sum/avg/max/min/count of a behavior.
e.g. Every 5 minutes, sum of user click of the website.
e.g. Every Day, average consume money of the website.
- Aggregate data of DayOfWeek or HoursOfDay, to analytisic behavior.
e.g. The sum of click from Monday to SunDay.
Init
var rts = require('rts')(options);
var rts = require('rts')({
redis: redis,
gran: '5m, 1h, 1d, 1w',
points: 500,
prefix: ''
});Options:
redisthe redis clientgrangranularity of recored time. Format is '{number}{unit}, {number}{unit}...'. The unit can bessecond,mminute,hhour,dday,wweek,Mmonth,yyear. e.g.5m, 1h, store data for 5 mintues and 1 hour.pointshow many data will be keep. We care about recentlynpoints of data for each granularity. Think about1sdata, if store 1 day data, it is 86400 rows data, we should reduce it to5mdata, it is only 288 rows. We just care small granularity data for recently, for the history, we just care large granualrity, like revenue of2010-11, not revenue of2010-11-05 12 o'clock.prefixthe redis key prefix.
Record
record(behavior, [behaviorValue], [statistics], [aggregations])
behaviorbehaviorValuestatistics: Array of statistic type, avariable member ofsum,count,avg,max,min. defaultsum.aggragationshmhour of day, splite data every monthhqhour of day, splite data every seasonhyhour of day, splite data every yeardmday of week, splite data every month.dqday of week, splite data every seasondyday of week, splite data every year
ts.record('click') // recore a click
ts.record('consume', 5, null, ['hm', 'dq']) // recored behavior with value, and aggragation.
ts.record('delay', 100, ['avg','max','min'])Query
ts.getStat(statistic, behavior, granularity, fromDate, toDate, callback)
ts[statistic](behavior, granularity, fromDate, toDate, callback)
ts.aggr{statistic}(behavior, aggragation, date, callback)
statisticsum,avg,count,max,min. Must be a member when statistics whenrecord!behaviorgranularityThe time unit, seeOptions, Must be a part ofoptions.granfromDatetoDate
ts.sum('click', '5m', fromDate, \[toDate\], callback)
ts.count('delay', '5m', fromDate, \[toDate\], callback)
ts.avg('delay', '5m', fromDate, \[toDate\], callback)
ts.max('delay', '5m', fromDate, \[toDate\], callback)
ts.min('delay', '5m', fromDate, \[toDate\], callback)
ts.aggravg('click', 'hm', date, callback)