Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhenakh/a0bd43d3aac69436e117 to your computer and use it in GitHub Desktop.
Save akhenakh/a0bd43d3aac69436e117 to your computer and use it in GitHub Desktop.
influx test 2
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/influxdb/influxdb/client"
)
var c *client.Client
func mySuperFastHandler(rw http.ResponseWriter, r *http.Request) {
start := time.Now()
// sleeping some random time
rand.Seed(time.Now().Unix())
i := rand.Intn(1000)
time.Sleep(time.Duration(time.Duration(i) * time.Millisecond))
fmt.Fprintf(rw, "Waiting %dms", i)
t := time.Since(start)
// sending the serie
s := &client.Series{
Name: "myhostname.nethttp.mySuperFastHandler.resp_time",
Columns: []string{"duration", "code", "url", "method"},
Points: [][]interface{}{
[]interface{}{int64(t / time.Millisecond), 200, r.RequestURI, r.Method},
},
}
err := c.WriteSeries([]*client.Series{s})
if err != nil {
log.Println(err)
}
}
func main() {
var err error
c, err = client.NewClient(&client.ClientConfig{
Username: "root",
Password: "root",
Database: "test",
})
if err != nil {
panic(err)
}
http.HandleFunc("/", mySuperFastHandler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment