Skip to content

Instantly share code, notes, and snippets.

@dgnorton
Created March 3, 2015 20:21
Show Gist options
  • Save dgnorton/b88cfc6b7f442721301b to your computer and use it in GitHub Desktop.
Save dgnorton/b88cfc6b7f442721301b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"flag"
"fmt"
"time"
)
func main() {
intervalN := flag.Int("interval", 10, "interval")
seriesN := flag.Int("series", 1, "Number of unique series to generate.")
clientN := flag.Int("clients", 10, "Number of clients to simulate.")
flag.Parse()
t := time.Date(2010, time.January, 1, 8, 0, 0, 0, time.UTC)
oneSecond := 1 * time.Second
for i := 0; i < *clientN; i++ {
for j := 0; j < *seriesN; j++ {
points := make([]*Point, 0)
for k := 0; k < *intervalN; k++ {
t = t.Add(oneSecond)
points = append(points, &Point{
Name: "cpu",
Tags: map[string]string{"host": fmt.Sprintf("server%d", j+1)},
Fields: map[string]interface{}{"value": 100},
})
}
batch := &Batch{
Database: "db",
RetentionPolicy: "raw",
Points: points,
}
buf, _ := json.Marshal(batch)
fmt.Printf("http://localhost:8086/write POST %s\n", buf)
}
}
}
type Batch struct {
Database string `json:"database"`
RetentionPolicy string `json:"retentionPolicy"`
Points []*Point `json:"points"`
}
type Point struct {
Name string `json:"name"`
Tags map[string]string `json:"tags"`
Fields map[string]interface{} `json:"fields"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment