示例#1
0
func (api *ByDimensionApi) buildRequestHistogramAggs(req *ByDimensionRequest) (*MapStr, error) {

	var interval string
	req.histogram_seconds, interval = computeHistogramInterval(&req.Timerange,
		req.Config.Histogram_points)

	aggs := MapStr{}
	for _, metric := range req.HistogramMetrics {
		switch metric {
		case "volume":
			aggs["volume_hist"] = MapStr{
				"date_histogram": MapStr{
					"field":         "timestamp",
					"interval":      interval,
					"min_doc_count": 0,
					"extended_bounds": MapStr{
						"min": elasticsearch.Time(req.Timerange.From),
						"max": elasticsearch.Time(req.Timerange.To),
					},
				},
				"aggs": MapStr{
					"volume": MapStr{
						"sum": MapStr{
							"field": req.Config.Count_field,
						},
					},
				},
			}
		default:
			return nil, fmt.Errorf("Unknown histogram metric name '%s'", metric)
		}

	}
	return &aggs, nil
}
示例#2
0
文件: perfdash.go 项目: sk163/bonito
func esBuildTimeFilter(tsField string, tr datetime.Timerange) MapStr {
	return MapStr{
		"range": MapStr{
			tsField: MapStr{
				"lte": elasticsearch.Time(tr.To),
				"gte": elasticsearch.Time(tr.From),
			},
		},
	}
}
示例#3
0
文件: test_data.go 项目: sk163/bonito
func (gen *TestTransactionsGenerator) GenerateInChan(transactions chan TestTransaction) {

	if gen.Increment == 0 {
		gen.Increment = time.Millisecond
	}

	i := 0
	for ts := gen.From; ts.Before(gen.To); ts = ts.Add(gen.Increment) {
		var trans TestTransaction

		trans.Timestamp = elasticsearch.Time(ts)
		trans.Service = fmt.Sprintf("Service%d", i%gen.NrServices)
		trans.Host = fmt.Sprintf("Service%d-Host%d",
			i%gen.NrServices, i%gen.NrHosts)
		trans.Count = gen.CountMin + rand.Intn(gen.CountMax-gen.CountMin)
		trans.Responsetime = gen.RtMin + rand.Intn(gen.RtMax-gen.RtMin)
		if rand.Float32() < gen.ErrorProb {
			trans.Status = "Error"
		} else {
			trans.Status = "OK"
		}

		transactions <- trans
		i++
	}

	close(transactions)
}
示例#4
0
func (v volumeLine) buildEsAggs(config ConfigRaw, interval Interval) (MapStr, error) {

	var cfg volumeLineConfig
	err := json.Unmarshal(config.Config, &cfg)
	if err != nil {
		return nil, err
	}

	if len(cfg.Count_field) == 0 {
		return nil, errors.New("count_field is required")
	}

	if len(cfg.Ts_field) == 0 {
		return nil, errors.New("count_field is required")
	}

	return MapStr{
		fmt.Sprintf("v%d_%s", config.Index, config.Name): MapStr{
			"date_histogram": MapStr{
				"field":         cfg.Ts_field,
				"interval":      interval.BucketTsSize,
				"min_doc_count": 0,
				"extended_bounds": MapStr{
					"min": elasticsearch.Time(interval.From),
					"max": elasticsearch.Time(interval.To),
				},
			},
			"aggs": MapStr{
				"volume": MapStr{
					"sum": MapStr{
						"field": cfg.Count_field,
					},
				},
			},
		},
	}, nil
}
示例#5
0
文件: gen.go 项目: sk163/bonito
func main() {
	to := time.Now()
	from := to.Add(-1 * time.Hour)

	samples := 100
	options := gengenOptionsForServices(samples, to, from)
	gen, err := testdata.NewGenGen(*options)
	if err != nil {
		fmt.Println(err)
		return
	}

	transChan := make(chan testdata.TestTransaction, 100)

	index_name := "packetbeat-test"
	es := elasticsearch.NewElasticsearch()

	// make sure we start fresh
	_, err = es.DeleteIndex(index_name)
	if err != nil {
		fmt.Println("Error: ", err)
		return
	}

	// create index with custom settings
	resp, err := es.Request("PUT", index_name, "", bytes.NewBufferString(
		`{"settings": {"index": {"refresh_interval": "-1"}}}`,
	))
	if err != nil {
		fmt.Println(elasticsearch.ResponseBody(resp))
		fmt.Println("Error: ", err)
		return
	}

	// generate in channel
	go func() {
		for i := 0; i < samples; i++ {
			for _, trans := range gen.Generate(i) {
				transChan <- testdata.TestTransaction{
					Timestamp:    elasticsearch.Time(trans["timestamp"].(time.Time)),
					Service:      trans["service"].(string),
					Host:         trans["host"].(string),
					Count:        int(trans["count"].(float64)),
					Responsetime: trans["responsetime"].(int),
					Status:       trans["status"].(string),
				}
			}
		}
		close(transChan)
	}()

	inserted, err := testdata.InsertInEsFromChan(es, index_name, transChan)
	if err != nil {
		fmt.Println("Error: ", err)
	}

	fmt.Printf("%d transactions inserted into %s\n", inserted, index_name)

	// set back the refreshing interval
	_, err = es.Request("PUT", index_name, "_settings", bytes.NewBufferString(
		`{"index": {"refresh_interval": "1s"}}`,
	))
	if err != nil {
		fmt.Println("Error: ", err)
	}
}
示例#6
0
				Config: json.RawMessage(`{
					"ts_field": "timestamp",
					"count_field": "count"}`,
				),
			}

			aggs, err := viz.buildEsAggs(config, interval)
			Expect(err).NotTo(HaveOccurred())
			Expect(aggs).To(BeEquivalentTo(MapStr{
				"v1_volumehist": MapStr{
					"date_histogram": MapStr{
						"field":         "timestamp",
						"interval":      "30s",
						"min_doc_count": 0,
						"extended_bounds": MapStr{
							"min": elasticsearch.Time(interval.From),
							"max": elasticsearch.Time(interval.To),
						},
					},
					"aggs": MapStr{
						"volume": MapStr{
							"sum": MapStr{
								"field": "count",
							},
						},
					},
				},
			}))
		})

		Context("fromEsResponse", func() {