Exemplo n.º 1
0
func (api *PerfDashApi) setRequestDefaults(req *PerfDashRequest) {
	if len(req.Config.Timestamp_field) == 0 {
		req.Config.Timestamp_field = "timestamp"
	}
	if req.Timerange.IsZero() {
		req.Timerange.From = datetime.JsTime(time.Now().Add(-1 * time.Hour))
		req.Timerange.To = datetime.JsTime(time.Now())
	}
}
Exemplo n.º 2
0
// Fills in the request with an omitted configuration options that
// have defaults.
func (api *ByDimensionApi) setRequestDefaults(req *ByDimensionRequest) {
	c := &req.Config

	if len(c.Primary_dimension) == 0 {
		c.Primary_dimension = "service"
	}
	if len(c.Secondary_dimension) == 0 {
		c.Secondary_dimension = "host"
	}
	if len(c.Responsetime_field) == 0 {
		c.Responsetime_field = "responsetime"
	}
	if len(c.Status_field) == 0 {
		c.Status_field = "status"
	}
	if len(c.Status_value_ok) == 0 {
		c.Status_value_ok = "ok"
	}
	if len(c.Count_field) == 0 {
		c.Count_field = "count"
	}
	if len(c.Timestamp_field) == 0 {
		c.Timestamp_field = "timestamp"
	}
	if len(c.Percentiles) == 0 {
		c.Percentiles = []float32{50, 90, 99, 99.5}
	}
	if c.Histogram_points == 0 {
		c.Histogram_points = 10
	}

	if req.Timerange.IsZero() {
		req.Timerange.From = datetime.JsTime(time.Now().Add(-1 * time.Hour))
		req.Timerange.To = datetime.JsTime(time.Now())
	}
}
Exemplo n.º 3
0
func (v volumeLine) fromEsResponse(resp map[string]json.RawMessage,
	config ConfigRaw, interval Interval) (MapStr, error) {

	var volume_hist struct {
		Buckets []struct {
			Key_as_string elasticsearch.Time
			Volume        struct {
				Value float32
			}
		}
	}

	val, exists := resp[fmt.Sprintf("v%d_%s", config.Index, config.Name)]
	if !exists {
		return nil, errors.New("Elasticsearch didn't return the aggregation")
	}

	err := json.Unmarshal(val, &volume_hist)
	if err != nil {
		return nil, err
	}

	values := []MapStr{}
	for _, bucket := range volume_hist.Buckets {
		bucket_secs := computeRealSecondsInInterval(interval,
			time.Time(bucket.Key_as_string))

		values = append(values, MapStr{
			"ts":    datetime.JsTime(bucket.Key_as_string),
			"value": bucket.Volume.Value / bucket_secs,
		})
	}

	return MapStr{
		"data": values,
	}, nil
}
Exemplo n.º 4
0
func (api *ByDimensionApi) bucketToPrimary(req *ByDimensionRequest,
	bucket map[string]json.RawMessage) (*PrimaryDimension, error) {

	var primary PrimaryDimension

	err := json.Unmarshal(bucket["key"], &primary.Name)
	if err != nil {
		return nil, err
	}

	// transform metrics
	primary.Metrics = map[string]float32{}
	for _, metric := range req.Metrics {
		switch metric {
		case "volume":
			var volume struct {
				Value float32
			}

			err = json.Unmarshal(bucket["volume"], &volume)
			if err != nil {
				return nil, err
			}

			primary.Metrics["volume"] = volume.Value / req.interval_seconds
		case "rt_max":
		case "rt_avg":
			var stats struct {
				Max float32
				Avg float32
			}
			err = json.Unmarshal(bucket["rt_stats"], &stats)
			if err != nil {
				return nil, err
			}

			primary.Metrics["rt_max"] = stats.Max
			primary.Metrics["rt_avg"] = stats.Avg

		case "rt_percentiles":
			var percentiles struct {
				Values map[string]float32
			}
			err = json.Unmarshal(bucket["rt_percentiles"], &percentiles)
			for key, value := range percentiles.Values {
				primary.Metrics[fmt.Sprintf("rt_%sp", key)] = value
			}

		case "secondary_count":
			var secondary struct {
				Value float32
			}

			err = json.Unmarshal(bucket["secondary_card"], &secondary)
			if err != nil {
				return nil, err
			}

			primary.Metrics["secondary_count"] = secondary.Value
		case "errors_rate":
			var errors_count struct {
				Count struct {
					Value float32
				}
			}
			var volume1 struct {
				Value float32
			}

			err = json.Unmarshal(bucket["errors_count"], &errors_count)
			if err != nil {
				return nil, err
			}
			err = json.Unmarshal(bucket["volume"], &volume1)
			if err != nil {
				return nil, err
			}

			primary.Metrics["errors_rate"] = errors_count.Count.Value /
				volume1.Value
		}
	}

	// transform histogram metrics
	primary.Hist_metrics = map[string][]HistogramValue{}
	for _, metric := range req.HistogramMetrics {
		switch metric {
		case "volume":
			var volume_hist struct {
				Buckets []struct {
					Key_as_string elasticsearch.Time
					Volume        struct {
						Value float32
					}
				}
			}

			err = json.Unmarshal(bucket["volume_hist"], &volume_hist)
			if err != nil {
				return nil, err
			}

			values := []HistogramValue{}

			for _, bucket := range volume_hist.Buckets {
				bucket_secs := computeRealSecondsInInterval(req.histogram_seconds,
					time.Time(bucket.Key_as_string), &req.Timerange)

				values = append(values, HistogramValue{
					Ts:    datetime.JsTime(bucket.Key_as_string),
					Value: bucket.Volume.Value / bucket_secs,
				})
			}

			primary.Hist_metrics["volume"] = values
		}
	}

	return &primary, nil
}