Skip to content

Commit

Permalink
Rewrite urlgen in Go
Browse files Browse the repository at this point in the history
Cut-n-paste Ben's code.

Fix bugs re args.

Sandardize on 1-based for time and servers.

Keep incrementing time for subsequent clients -- I don't see the
point in overwriting data.
  • Loading branch information
rothrock committed Mar 3, 2015
1 parent 3901ea8 commit b020d3f
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions tests/urlgen/urlgen.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"time"
)

var (
i, s, c int
)

func init() {
flag.IntVar(&i, "i", 10, "interval")
flag.IntVar(&s, "s", 1, "Number of unique series to generate.")
flag.IntVar(&c, "c", 10, "Number of clients to simulate.")
}

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()

var (
pointsInSeries string
j int = 1
k int
printComma string = ","
jsonTemplate string = `{"name": "cpu", "tags": {"host": "server%d"}, "timestamp": "%s","fields": {"value": 100}}%s`
urlTemplate string = `http://localhost:8086/write POST {"database" : "db", "retentionPolicy" : "raw", "points": [%s]}`
)

t := time.Date(2010, time.January, 1, 8, 0, 0, 0, time.UTC)
for ; c > 0; c-- {
for ; j < s+1; j++ {
for ; k < i; k++ {
if k == i-1 {
printComma = ""
}
pointsInSeries = pointsInSeries + fmt.Sprintf(jsonTemplate, j, t.Format(time.RFC3339), printComma)
t = t.Add(1 * time.Second)
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",
Timestamp: t,
Tags: map[string]string{"host": fmt.Sprintf("server%d", j+1)},
Fields: map[string]interface{}{"value": 100},
})
}
fmt.Printf(urlTemplate, pointsInSeries)
fmt.Println()
pointsInSeries = ""
k = 0
printComma = ","
buf, _ := json.Marshal(points)

fmt.Printf("http://localhost:8086/write POST %s\n", buf)
}
j = 1
}
}

type Point struct {
Name string `json:"name"`
Timestamp time.Time `json:"timestamp"`
Tags map[string]string `json:"tags"`
Fields map[string]interface{} `json:"fields"`
}

0 comments on commit b020d3f

Please sign in to comment.