forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
27 additions
and
33 deletions.
There are no files selected for viewing
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
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"` | ||
} |