Remove the old way of doing stats

parent f45d847c
......@@ -129,8 +129,6 @@ func main() {
})
check(err)
// For now, just read in the old stats and write them out to BoltDB.
statsOld(redisPool, db)
// Run the stats at regular intervals to process the hits from the previous hour.
go stats(redisPool, db)
......
......@@ -139,90 +139,3 @@ func processRandStat(pool *redis.Pool, db *bolt.DB) {
// ToDo: check if the "active:"+datetime now has zero members, and if so, remove the key
}
func statsOld(pool *redis.Pool, db *bolt.DB) {
if pool == nil {
log.Printf("Not setting up stats collection from Redis")
return
}
// get a connection
conn := pool.Get()
defer conn.Close()
// get all of the 'active' IDs
active, err := redis.Strings(conn.Do("SMEMBERS", "active"))
if err != nil {
log.Printf(err.Error())
return
}
for _, id := range active {
fmt.Printf("active=%s\n", id)
statsRandOld(pool, db, id)
}
}
func statsRandOld(pool *redis.Pool, db *bolt.DB, id string) {
// get a connection
conn := pool.Get()
defer conn.Close()
// total
total, err := redis.Int64(conn.Do("GET", "hits:"+id+":total"))
if err != nil {
log.Printf("statsRand: %s\n", err)
return
}
fmt.Printf("total = %d\n", total)
// daily
daily, err := redis.Int64Map(conn.Do("HGETALL", "hits:"+id+":day"))
if err != nil {
log.Printf("statsRand: %s\n", err)
return
}
fmt.Printf("daily = %#v\n", daily)
// hourly
hourly, err := redis.Int64Map(conn.Do("HGETALL", "hits:"+id+":hour"))
if err != nil {
log.Printf("statsRand: %s\n", err)
return
}
fmt.Printf("hourly = %#v\n", hourly)
// dotwly - day of the week(ly)
dotwly, err := redis.Int64Map(conn.Do("HGETALL", "hits:"+id+":dotw"))
if err != nil {
log.Printf("statsRand: %s\n", err)
return
}
fmt.Printf("dotwly = %#v\n", dotwly)
// put these stats into Bolt
stats := Stats{
Total: total,
Daily: daily,
Hourly: hourly,
DOTWly: dotwly,
}
err = db.Update(func(tx *bolt.Tx) error {
return rod.PutJson(tx, statsBucketNameStr, id, stats)
})
if err != nil {
log.Printf("statsRand: %s\n", err)
}
// finally, remove the keys used here, and remove it from the original set
// just inc count:20060102-15:<id>
conn.Send("MULTI")
conn.Send("DEL", "hits:"+id+":total")
conn.Send("DEL", "hits:"+id+":day")
conn.Send("DEL", "hits:"+id+":hour")
conn.Send("DEL", "hits:"+id+":dotw")
conn.Send("SREM", "active", id)
_, err = conn.Do("EXEC")
if err != nil {
log.Printf("incHits: %s\n", err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment