// sumForEachInstance sum the value in Response of each instance from Prometheus
sumForEachInstance sum the value in Response of each instance from Prometheus
// sumForEachInstance sum the value in Response of each instance from Prometheus
func sumForEachInstance(instances []string, resp *Response) (float64, error) {
	if resp == nil {
		return 0, fmt.Errorf("metrics response from Promethus can't be empty")
	}
	s := sets.String{}
	for _, instance := range instances {
		s.Insert(instance)
	}
	sum := 0.0
	if len(resp.Data.Result) < 1 {
		return 0, fmt.Errorf("metrics Response return zero info")
	}
	for _, r := range resp.Data.Result {
		if s.Has(r.Metric.Instance) {
			v, err := strconv.ParseFloat(r.Value[1].(string), 64)
			if err != nil {
				return 0.0, err
			}
			sum = sum + v
		}
	}
	return sum, nil
}
func sumForEachInstance ( instances [ ] string , resp * Response ) ( float64 , error ) { if resp == nil { return 0 , fmt . Errorf ( " " ) } s := sets . String { } for _ , instance := range instances { s . Insert ( instance ) } sum := 0.0 if len ( resp . Data . Result ) < 1 { return 0 , fmt . Errorf ( " " ) } for _ , r := range resp . Data . Result { if s . Has ( r . Metric . Instance ) { v , err := strconv . ParseFloat ( r . Value [ 1 ] . ( string ) , 64 ) if err != nil { return 0.0 , err } sum = sum + v } } return sum , nil }
sumForEachInstance sum the value in Response of each instance from Prometheus
sumForEachInstance sum the value in Response of each instance from Prometheus