Last active
August 29, 2015 14:08
-
-
Save akhenakh/a0bd43d3aac69436e117 to your computer and use it in GitHub Desktop.
influx test 2
This file contains 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 ( | |
"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