metrics.go 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package containers
  2. import (
  3. "github.com/prometheus/client_golang/prometheus"
  4. "reflect"
  5. )
  6. var metrics = struct {
  7. Restarts *prometheus.Desc
  8. CPULimit *prometheus.Desc
  9. CPUUsage *prometheus.Desc
  10. CPUDelay *prometheus.Desc
  11. ThrottledTime *prometheus.Desc
  12. MemoryLimit *prometheus.Desc
  13. MemoryRss *prometheus.Desc
  14. MemoryCache *prometheus.Desc
  15. OOMKills *prometheus.Desc
  16. DiskDelay *prometheus.Desc
  17. DiskSize *prometheus.Desc
  18. DiskUsed *prometheus.Desc
  19. DiskReserved *prometheus.Desc
  20. DiskReadOps *prometheus.Desc
  21. DiskReadBytes *prometheus.Desc
  22. DiskWriteOps *prometheus.Desc
  23. DiskWriteBytes *prometheus.Desc
  24. NetListenInfo *prometheus.Desc
  25. NetConnectsSuccessful *prometheus.Desc
  26. NetConnectsFailed *prometheus.Desc
  27. NetConnectionsActive *prometheus.Desc
  28. NetRetransmits *prometheus.Desc
  29. NetLatency *prometheus.Desc
  30. LogMessages *prometheus.Desc
  31. ApplicationType *prometheus.Desc
  32. }{
  33. Restarts: metric("container_restarts_total", "Number of times the container was restarted"),
  34. CPULimit: metric("container_resources_cpu_limit_cores", "CPU limit of the container"),
  35. CPUUsage: metric("container_resources_cpu_usage_seconds_total", "Total CPU time consumed by the container"),
  36. CPUDelay: metric("container_resources_cpu_delay_seconds_total", "Total time duration processes of the container have been waiting for a CPU (while being runnable)"),
  37. ThrottledTime: metric("container_resources_cpu_throttled_seconds_total", "Total time duration the container has been throttled"),
  38. MemoryLimit: metric("container_resources_memory_limit_bytes", "Memory limit of the container"),
  39. MemoryRss: metric("container_resources_memory_rss_bytes", "Amount of physical memory used by the container (doesn't include page cache)"),
  40. MemoryCache: metric("container_resources_memory_cache_bytes", "Amount of page cache memory allocated by the container"),
  41. OOMKills: metric("container_oom_kills_total", "Total number of times the container was terminated by the OOM killer"),
  42. DiskDelay: metric("container_resources_disk_delay_seconds_total", "Total time duration processes of the container have been waiting fot I/Os to complete"),
  43. DiskSize: metric("container_resources_disk_size_bytes", "Total capacity of the volume", "mount_point", "device", "provisioner", "volume"),
  44. DiskUsed: metric("container_resources_disk_used_bytes", "Used capacity of the volume", "mount_point", "device", "provisioner", "volume"),
  45. DiskReserved: metric("container_resources_disk_reserved_bytes", "Reserved capacity of the volume", "mount_point", "device", "provisioner", "volume"),
  46. DiskReadOps: metric("container_resources_disk_reads_total", "Total number of reads completed successfully by the container", "mount_point", "device", "provisioner", "volume"),
  47. DiskReadBytes: metric("container_resources_disk_read_bytes_total", "Total number of bytes read from the disk by the container", "mount_point", "device", "provisioner", "volume"),
  48. DiskWriteOps: metric("container_resources_disk_writes_total", "Total number of writes completed successfully by the container", "mount_point", "device", "provisioner", "volume"),
  49. DiskWriteBytes: metric("container_resources_disk_written_bytes_total", "Total number of bytes written to the disk by the container", "mount_point", "device", "provisioner", "volume"),
  50. NetListenInfo: metric("container_net_tcp_listen_info", "Listen address of the container", "listen_addr", "proxy"),
  51. NetConnectsSuccessful: metric("container_net_tcp_successful_connects_total", "Total number of successful TCP connects", "destination", "actual_destination"),
  52. NetConnectsFailed: metric("container_net_tcp_failed_connects_total", "Total number of failed TCP connects", "destination"),
  53. NetConnectionsActive: metric("container_net_tcp_active_connections", "Number of active outbound connections used by the container", "destination", "actual_destination"),
  54. NetRetransmits: metric("container_net_tcp_retransmits_total", "Total number of retransmitted TCP segments", "destination", "actual_destination"),
  55. NetLatency: metric("container_net_latency_seconds", "Round-trip time between the container and a remote IP", "destination_ip"),
  56. LogMessages: metric("container_log_messages_total", "Number of messages grouped by the automatically extracted repeated pattern", "source", "level", "pattern_hash", "sample"),
  57. ApplicationType: metric("container_application_type", "Type of the application running in the container (e.g. memcached, postgres, mysql)", "application_type"),
  58. }
  59. func metric(name, help string, labels ...string) *prometheus.Desc {
  60. return prometheus.NewDesc(name, help, labels, nil)
  61. }
  62. var metricsList []*prometheus.Desc
  63. func init() {
  64. v := reflect.ValueOf(metrics)
  65. for i := 0; i < v.NumField(); i++ {
  66. metricsList = append(metricsList, v.Field(i).Interface().(*prometheus.Desc))
  67. }
  68. }