api_server_metrics.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package metrics
  14. // APIServerMetrics is metrics for API server
  15. type APIServerMetrics Metrics
  16. // Equal returns true if all metrics are the same as the arguments.
  17. func (m *APIServerMetrics) Equal(o APIServerMetrics) bool {
  18. return (*Metrics)(m).Equal(Metrics(o))
  19. }
  20. func newAPIServerMetrics() APIServerMetrics {
  21. result := NewMetrics()
  22. return APIServerMetrics(result)
  23. }
  24. func parseAPIServerMetrics(data string) (APIServerMetrics, error) {
  25. result := newAPIServerMetrics()
  26. if err := parseMetrics(data, (*Metrics)(&result)); err != nil {
  27. return APIServerMetrics{}, err
  28. }
  29. return result, nil
  30. }
  31. func (g *Grabber) getMetricsFromAPIServer() (string, error) {
  32. rawOutput, err := g.client.CoreV1().RESTClient().Get().RequestURI("/metrics").Do().Raw()
  33. if err != nil {
  34. return "", err
  35. }
  36. return string(rawOutput), nil
  37. }