Codebase list golang-github-beorn7-perks / f735561
window example Blake Mizerany 11 years ago
1 changed file(s) with 29 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
77 "log"
88 "os"
99 "strconv"
10 "time"
1011 )
1112
1213 func Example_simple() {
5657 fmt.Println("perc50:", q.Query(0.90))
5758 }
5859
60 func Example_window() {
61 // Scenario: We want the 90th, 95th, and 99th percentiles for each
62 // minute.
63
64 ch := make(chan float64)
65 go readStreamValues(ch)
66
67 tick := time.NewTicker(1 * time.Minute)
68 q := quantile.NewTargeted(0.90, 0.95, 0.99)
69 for {
70 select {
71 case t := <-tick.C:
72 flushToDB(t, q.Samples())
73 q.Reset()
74 case v := <-ch:
75 q.Insert(v)
76 }
77 }
78 }
79
80 func readStreamValues(ch chan float64) {
81 // Use your imagination
82 }
83
84 func flushToDB(t time.Time, samples quantile.Samples) {
85 // Use your imagination
86 }
87
5988 // This is a stub for the above example. In reality this would hit the remote
6089 // servers via http or something like it.
6190 func getDBQuerySamples(ch chan quantile.Samples) {}