This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
feed.go
52 lines (44 loc) · 1.94 KB
/
feed.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
// 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 (
"time"
"github.com/grafana/metrictank/cmd/mt-fakemetrics/policy"
"github.com/spf13/cobra"
)
var feedCmd = &cobra.Command{
Use: "feed",
Short: "Publishes a realtime feed of data",
Run: func(cmd *cobra.Command, args []string) {
initStats(true, "feed")
period = int(periodDur.Seconds())
flush = int(flushDur.Nanoseconds() / 1000 / 1000)
out := getOutput()
vp, err := policy.ParseValuePolicy(valuePolicy)
if err != nil {
panic(err)
}
dataFeed(out, orgs, mpo, period, flush, 0, 1, false, getBuilder(metricBuilder, metricName), vp)
},
}
func init() {
rootCmd.AddCommand(feedCmd)
feedCmd.Flags().StringVar(&metricName, "metricname", "some.id.of.a.metric.%d", "the metric name to use")
feedCmd.Flags().StringVar(&metricBuilder, "metricbuilder", "simple", "the metric builder to use. (simple|tagged)")
feedCmd.Flags().IntVar(&orgs, "orgs", 1, "how many orgs to simulate")
feedCmd.Flags().IntVar(&mpo, "mpo", 100, "how many metrics per org to simulate")
feedCmd.Flags().DurationVar(&flushDur, "flush", time.Second, "how often to flush metrics")
feedCmd.Flags().DurationVar(&periodDur, "period", time.Second, "period between metric points (must be a multiple of 1s)")
feedCmd.Flags().StringVar(&valuePolicy, "value-policy", "", "a value policy (i.e. \"single:1\" \"multiple:1,2,3,4,5\" \"timestamp\" \"daily-sine:<peak>,<offset>,<stdev>\")")
}