This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
storageconf.go
97 lines (89 loc) · 2.58 KB
/
storageconf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright © 2018 Grafana Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
"fmt"
"time"
"github.com/grafana/metrictank/cmd/mt-fakemetrics/out"
"github.com/grafana/metrictank/schema"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// storageconfCmd represents the storageconf command
var storageconfCmd = &cobra.Command{
Use: "storageconf",
Short: "Sends out one or more set of 10 metrics which you can test aggregation and retention rules on",
Run: func(cmd *cobra.Command, args []string) {
initStats(true, "storageconf")
if mpo%10 != 0 {
log.Fatal("mpo must divide by 10")
}
period = int(periodDur.Seconds())
flush = int(flushDur.Nanoseconds() / 1000 / 1000)
out := getOutput()
to := time.Now().Unix()
from := to - 24*60*60
names := []string{
"mt-fakemetrics.raw.%d.min",
"mt-fakemetrics.raw.%d.max",
"mt-fakemetrics.raw.%d.sum",
"mt-fakemetrics.raw.%d.lst",
"mt-fakemetrics.raw.%d.default",
"mt-fakemetrics.agg.%d.min",
"mt-fakemetrics.agg.%d.max",
"mt-fakemetrics.agg.%d.sum",
"mt-fakemetrics.agg.%d.lst",
"mt-fakemetrics.agg.%d.default",
}
var metrics []*schema.MetricData
sets := mpo / 10
for set := 1; set <= sets; set++ {
for _, name := range names {
metrics = append(metrics, buildMetric(name, set, 1))
}
}
do(metrics, from, to, out)
},
}
func init() {
rootCmd.AddCommand(storageconfCmd)
storageconfCmd.Flags().IntVar(&mpo, "mpo", 10, "how many metrics per org to simulate (must be multiple of 10)")
}
func buildMetric(name string, set, org int) *schema.MetricData {
out := &schema.MetricData{
Name: fmt.Sprintf(name, set),
OrgId: org,
Interval: 1,
Unit: "ms",
Mtype: "gauge",
Tags: nil,
}
out.SetId()
return out
}
func do(metrics []*schema.MetricData, from, to int64, out out.Out) {
for ts := from; ts < to; ts++ {
if ts%3600 == 0 {
fmt.Println("doing ts", ts)
}
for i := range metrics {
metrics[i].Time = int64(ts)
metrics[i].Value = float64(ts % 10)
}
err := out.Flush(metrics)
if err != nil {
log.Error(err.Error())
}
}
}