SumMetrics returns the sum of the values of each given metric names.
(metricNames []string, opts ...MetricsOption)
| 628 | |
| 629 | // SumMetrics returns the sum of the values of each given metric names. |
| 630 | func (s *HTTPService) SumMetrics(metricNames []string, opts ...MetricsOption) ([]float64, error) { |
| 631 | options := buildMetricsOptions(opts) |
| 632 | sums := make([]float64, len(metricNames)) |
| 633 | |
| 634 | metrics, err := s.Metrics() |
| 635 | if err != nil { |
| 636 | return nil, err |
| 637 | } |
| 638 | |
| 639 | tp := expfmt.NewTextParser(model.LegacyValidation) |
| 640 | families, err := tp.TextToMetricFamilies(strings.NewReader(metrics)) |
| 641 | if err != nil { |
| 642 | return nil, err |
| 643 | } |
| 644 | |
| 645 | for i, m := range metricNames { |
| 646 | sums[i] = 0.0 |
| 647 | |
| 648 | // Get the metric family. |
| 649 | mf, ok := families[m] |
| 650 | if !ok { |
| 651 | if options.SkipMissingMetrics { |
| 652 | continue |
| 653 | } |
| 654 | |
| 655 | return nil, errors.Wrapf(errMissingMetric, "metric=%s service=%s", m, s.name) |
| 656 | } |
| 657 | |
| 658 | // Filter metrics. |
| 659 | metrics := filterMetrics(mf.GetMetric(), options) |
| 660 | if len(metrics) == 0 { |
| 661 | if options.SkipMissingMetrics { |
| 662 | continue |
| 663 | } |
| 664 | |
| 665 | return nil, errors.Wrapf(errMissingMetric, "metric=%s service=%s", m, s.name) |
| 666 | } |
| 667 | |
| 668 | sums[i] = SumValues(getValues(metrics, options)) |
| 669 | } |
| 670 | |
| 671 | return sums, nil |
| 672 | } |
| 673 | |
| 674 | // WaitRemovedMetric waits until a metric disappear from the list of metrics exported by the service. |
| 675 | func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption) error { |