config.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2019 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 v1alpha1
  14. import (
  15. "time"
  16. summary "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
  17. "k8s.io/kubernetes/pkg/kubelet/server/stats"
  18. )
  19. // Version is the string representation of the version of this configuration
  20. const Version = "v1alpha1"
  21. // Config is the v1alpha1 resource metrics definition
  22. func Config() stats.ResourceMetricsConfig {
  23. return stats.ResourceMetricsConfig{
  24. NodeMetrics: []stats.NodeResourceMetric{
  25. {
  26. Name: "node_cpu_usage_seconds_total",
  27. Description: "Cumulative cpu time consumed by the node in core-seconds",
  28. ValueFn: func(s summary.NodeStats) (*float64, time.Time) {
  29. if s.CPU == nil {
  30. return nil, time.Time{}
  31. }
  32. v := float64(*s.CPU.UsageCoreNanoSeconds) / float64(time.Second)
  33. return &v, s.CPU.Time.Time
  34. },
  35. },
  36. {
  37. Name: "node_memory_working_set_bytes",
  38. Description: "Current working set of the node in bytes",
  39. ValueFn: func(s summary.NodeStats) (*float64, time.Time) {
  40. if s.Memory == nil {
  41. return nil, time.Time{}
  42. }
  43. v := float64(*s.Memory.WorkingSetBytes)
  44. return &v, s.Memory.Time.Time
  45. },
  46. },
  47. },
  48. ContainerMetrics: []stats.ContainerResourceMetric{
  49. {
  50. Name: "container_cpu_usage_seconds_total",
  51. Description: "Cumulative cpu time consumed by the container in core-seconds",
  52. ValueFn: func(s summary.ContainerStats) (*float64, time.Time) {
  53. if s.CPU == nil {
  54. return nil, time.Time{}
  55. }
  56. v := float64(*s.CPU.UsageCoreNanoSeconds) / float64(time.Second)
  57. return &v, s.CPU.Time.Time
  58. },
  59. },
  60. {
  61. Name: "container_memory_working_set_bytes",
  62. Description: "Current working set of the container in bytes",
  63. ValueFn: func(s summary.ContainerStats) (*float64, time.Time) {
  64. if s.Memory == nil {
  65. return nil, time.Time{}
  66. }
  67. v := float64(*s.Memory.WorkingSetBytes)
  68. return &v, s.Memory.Time.Time
  69. },
  70. },
  71. },
  72. }
  73. }