Last active
August 29, 2015 14:11
-
-
Save ancientlore/7802445bba933a2c85a8 to your computer and use it in GitHub Desktop.
Kubismus sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/ancientlore/kubismus" | |
"log" | |
"math" | |
"math/rand" | |
"net/http" | |
"runtime" | |
"strconv" | |
"time" | |
) | |
func main() { | |
kubismus.HandleHTTP() | |
kubismus.Define("Requests", kubismus.COUNT, "Requests/Second") | |
kubismus.Define("Requests", kubismus.AVERAGE, "Average Request Size") | |
kubismus.Define("Requests", kubismus.SUM, "Bytes/Second") | |
kubismus.Define("Goroutines", kubismus.AVERAGE, "#Goroutines") | |
go func() { | |
kubismus.Note("Foo", "Bar") | |
for { | |
time.Sleep(5 * time.Second) | |
kubismus.Note("Time", time.Now().String()) | |
} | |
}() | |
go func() { | |
for { | |
time.Sleep(10 * time.Second) | |
kubismus.Note("The Other Time", time.Now().String()) | |
} | |
}() | |
go func() { | |
for { | |
time.Sleep(1 * time.Second) | |
kubismus.Note("Goroutines", strconv.Itoa(runtime.NumGoroutine())) | |
kubismus.Metric("Goroutines", 1, float64(runtime.NumGoroutine())) | |
} | |
}() | |
go func() { | |
x := 0.0 | |
V := 0.0 | |
for { | |
F := math.Sin(x) + 1.0 | |
for i := 0; i < 100; i++ { | |
time.Sleep(time.Duration(rand.Intn(50)) * time.Millisecond) | |
V += F * float64(rand.Intn(100)) | |
kubismus.Metric("Requests", 1, F) | |
} | |
x += 1.0 / (2.0 * math.Pi) | |
if x > 2.0*math.Pi { | |
x = 0.0 | |
} | |
} | |
}() | |
log.Fatal(http.ListenAndServe(":9999", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment