custom_metrics.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 custommetrics contains support for instrumenting cAdvisor to gather custom metrics from pods.
  14. package custommetrics
  15. import (
  16. "path"
  17. "k8s.io/kubernetes/pkg/api"
  18. )
  19. const (
  20. CustomMetricsDefinitionContainerFile = "definition.json"
  21. CustomMetricsDefinitionDir = "/etc/custom-metrics"
  22. )
  23. // Alpha implementation.
  24. // Returns a path to a cAdvisor-specific custom metrics configuration.
  25. func GetCAdvisorCustomMetricsDefinitionPath(container *api.Container) (*string, error) {
  26. // Assuemes that the container has Custom Metrics enabled if it has "/etc/custom-metrics" directory
  27. // mounted as a volume. Custom Metrics definition is expected to be in "definition.json".
  28. if container.VolumeMounts != nil {
  29. for _, volumeMount := range container.VolumeMounts {
  30. if path.Clean(volumeMount.MountPath) == path.Clean(CustomMetricsDefinitionDir) {
  31. // TODO: add definition file validation.
  32. definitionPath := path.Clean(path.Join(volumeMount.MountPath, CustomMetricsDefinitionContainerFile))
  33. return &definitionPath, nil
  34. }
  35. }
  36. }
  37. // No Custom Metrics definition available.
  38. return nil, nil
  39. }