metrics.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package containers
  2. import (
  3. "github.com/coroot/coroot-node-agent/ebpftracer/l7"
  4. "github.com/prometheus/client_golang/prometheus"
  5. )
  6. var metrics = struct {
  7. ContainerInfo *prometheus.Desc
  8. Restarts *prometheus.Desc
  9. CPULimit *prometheus.Desc
  10. CPUUsage *prometheus.Desc
  11. CPUDelay *prometheus.Desc
  12. ThrottledTime *prometheus.Desc
  13. MemoryLimit *prometheus.Desc
  14. MemoryRss *prometheus.Desc
  15. MemoryCache *prometheus.Desc
  16. OOMKills *prometheus.Desc
  17. DiskDelay *prometheus.Desc
  18. DiskSize *prometheus.Desc
  19. DiskUsed *prometheus.Desc
  20. DiskReserved *prometheus.Desc
  21. DiskReadOps *prometheus.Desc
  22. DiskReadBytes *prometheus.Desc
  23. DiskWriteOps *prometheus.Desc
  24. DiskWriteBytes *prometheus.Desc
  25. NetListenInfo *prometheus.Desc
  26. NetConnectsSuccessful *prometheus.Desc
  27. NetConnectsFailed *prometheus.Desc
  28. NetConnectionsActive *prometheus.Desc
  29. NetRetransmits *prometheus.Desc
  30. NetLatency *prometheus.Desc
  31. LogMessages *prometheus.Desc
  32. ApplicationType *prometheus.Desc
  33. JvmInfo *prometheus.Desc
  34. JvmHeapSize *prometheus.Desc
  35. JvmHeapUsed *prometheus.Desc
  36. JvmGCTime *prometheus.Desc
  37. JvmSafepointTime *prometheus.Desc
  38. JvmSafepointSyncTime *prometheus.Desc
  39. }{
  40. ContainerInfo: metric("container_info", "Meta information about the container", "image"),
  41. Restarts: metric("container_restarts_total", "Number of times the container was restarted"),
  42. CPULimit: metric("container_resources_cpu_limit_cores", "CPU limit of the container"),
  43. CPUUsage: metric("container_resources_cpu_usage_seconds_total", "Total CPU time consumed by the container"),
  44. CPUDelay: metric("container_resources_cpu_delay_seconds_total", "Total time duration processes of the container have been waiting for a CPU (while being runnable)"),
  45. ThrottledTime: metric("container_resources_cpu_throttled_seconds_total", "Total time duration the container has been throttled"),
  46. MemoryLimit: metric("container_resources_memory_limit_bytes", "Memory limit of the container"),
  47. MemoryRss: metric("container_resources_memory_rss_bytes", "Amount of physical memory used by the container (doesn't include page cache)"),
  48. MemoryCache: metric("container_resources_memory_cache_bytes", "Amount of page cache memory allocated by the container"),
  49. OOMKills: metric("container_oom_kills_total", "Total number of times the container was terminated by the OOM killer"),
  50. DiskDelay: metric("container_resources_disk_delay_seconds_total", "Total time duration processes of the container have been waiting fot I/Os to complete"),
  51. DiskSize: metric("container_resources_disk_size_bytes", "Total capacity of the volume", "mount_point", "device", "volume"),
  52. DiskUsed: metric("container_resources_disk_used_bytes", "Used capacity of the volume", "mount_point", "device", "volume"),
  53. DiskReserved: metric("container_resources_disk_reserved_bytes", "Reserved capacity of the volume", "mount_point", "device", "volume"),
  54. DiskReadOps: metric("container_resources_disk_reads_total", "Total number of reads completed successfully by the container", "mount_point", "device", "volume"),
  55. DiskReadBytes: metric("container_resources_disk_read_bytes_total", "Total number of bytes read from the disk by the container", "mount_point", "device", "volume"),
  56. DiskWriteOps: metric("container_resources_disk_writes_total", "Total number of writes completed successfully by the container", "mount_point", "device", "volume"),
  57. DiskWriteBytes: metric("container_resources_disk_written_bytes_total", "Total number of bytes written to the disk by the container", "mount_point", "device", "volume"),
  58. NetListenInfo: metric("container_net_tcp_listen_info", "Listen address of the container", "listen_addr", "proxy"),
  59. NetConnectsSuccessful: metric("container_net_tcp_successful_connects_total", "Total number of successful TCP connects", "destination", "actual_destination"),
  60. NetConnectsFailed: metric("container_net_tcp_failed_connects_total", "Total number of failed TCP connects", "destination"),
  61. NetConnectionsActive: metric("container_net_tcp_active_connections", "Number of active outbound connections used by the container", "destination", "actual_destination"),
  62. NetRetransmits: metric("container_net_tcp_retransmits_total", "Total number of retransmitted TCP segments", "destination", "actual_destination"),
  63. NetLatency: metric("container_net_latency_seconds", "Round-trip time between the container and a remote IP", "destination_ip"),
  64. LogMessages: metric("container_log_messages_total", "Number of messages grouped by the automatically extracted repeated pattern", "source", "level", "pattern_hash", "sample"),
  65. ApplicationType: metric("container_application_type", "Type of the application running in the container (e.g. memcached, postgres, mysql)", "application_type"),
  66. JvmInfo: metric("container_jvm_info", "Meta information about the JVM", "jvm", "java_version"),
  67. JvmHeapSize: metric("container_jvm_heap_size_bytes", "Total heap size in bytes", "jvm"),
  68. JvmHeapUsed: metric("container_jvm_heap_used_bytes", "Used heap size in bytes", "jvm"),
  69. JvmGCTime: metric("container_jvm_gc_time_seconds", "Time spent in the given JVM garbage collector in seconds", "jvm", "gc"),
  70. JvmSafepointTime: metric("container_jvm_safepoint_time_seconds", "Time the application has been stopped for safepoint operations in seconds", "jvm"),
  71. JvmSafepointSyncTime: metric("container_jvm_safepoint_sync_time_seconds", "Time spent getting to safepoints in seconds", "jvm"),
  72. }
  73. var (
  74. L7Requests = map[l7.Protocol]prometheus.CounterOpts{
  75. l7.ProtocolHTTP: {Name: "container_http_requests_total", Help: "Total number of outbound HTTP requests"},
  76. l7.ProtocolPostgres: {Name: "container_postgres_queries_total", Help: "Total number of outbound Postgres queries"},
  77. l7.ProtocolRedis: {Name: "container_redis_queries_total", Help: "Total number of outbound Redis queries"},
  78. l7.ProtocolMemcached: {Name: "container_memcached_queries_total", Help: "Total number of outbound Memcached queries"},
  79. l7.ProtocolMysql: {Name: "container_mysql_queries_total", Help: "Total number of outbound Mysql queries"},
  80. l7.ProtocolMongo: {Name: "container_mongo_queries_total", Help: "Total number of outbound Mongo queries"},
  81. l7.ProtocolKafka: {Name: "container_kafka_requests_total", Help: "Total number of outbound Kafka requests"},
  82. l7.ProtocolCassandra: {Name: "container_cassandra_queries_total", Help: "Total number of outbound Cassandra requests"},
  83. l7.ProtocolRabbitmq: {Name: "container_rabbitmq_messages_total", Help: "Total number of Rabbitmq messages produced or consumed by the container"},
  84. l7.ProtocolNats: {Name: "container_nats_messages_total", Help: "Total number of NATS messages produced or consumed by the container"},
  85. }
  86. L7Latency = map[l7.Protocol]prometheus.HistogramOpts{
  87. l7.ProtocolHTTP: {Name: "container_http_requests_duration_seconds_total", Help: "Histogram of the response time for each outbound HTTP request"},
  88. l7.ProtocolPostgres: {Name: "container_postgres_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Postgres query"},
  89. l7.ProtocolRedis: {Name: "container_redis_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Redis query"},
  90. l7.ProtocolMemcached: {Name: "container_memcached_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Memcached query"},
  91. l7.ProtocolMysql: {Name: "container_mysql_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Mysql query"},
  92. l7.ProtocolMongo: {Name: "container_mongo_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Mongo query"},
  93. l7.ProtocolKafka: {Name: "container_kafka_requests_duration_seconds_total", Help: "Histogram of the execution time for each outbound Kafka request"},
  94. l7.ProtocolCassandra: {Name: "container_cassandra_queries_duration_seconds_total", Help: "Histogram of the execution time for each outbound Cassandra request"},
  95. }
  96. )
  97. func metric(name, help string, labels ...string) *prometheus.Desc {
  98. return prometheus.NewDesc(name, help, labels, nil)
  99. }
  100. func newCounter(name, help string, constLabels prometheus.Labels) prometheus.Counter {
  101. return prometheus.NewCounter(prometheus.CounterOpts{Name: name, Help: help, ConstLabels: constLabels})
  102. }
  103. func newCounterVec(name, help string, constLabels prometheus.Labels, labelNames ...string) *prometheus.CounterVec {
  104. return prometheus.NewCounterVec(prometheus.CounterOpts{Name: name, Help: help, ConstLabels: constLabels}, labelNames)
  105. }
  106. func newGauge(name, help string, constLabels prometheus.Labels) prometheus.Gauge {
  107. return prometheus.NewGauge(prometheus.GaugeOpts{Name: name, Help: help, ConstLabels: constLabels})
  108. }
  109. func newGaugeVec(name, help string, constLabels prometheus.Labels, labelNames ...string) *prometheus.GaugeVec {
  110. return prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: name, Help: help, ConstLabels: constLabels}, labelNames)
  111. }