Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZheNing Hu <adlternative@gmail.com>2023-06-29 12:24:09 +0300
committerZheNing Hu <adlternative@gmail.com>2023-07-10 15:28:58 +0300
commite0e0cc45caff5305763f7e5afd6150e8a6f51407 (patch)
tree7b5dc031d91db1a8541e6df4a21c00958903d461
parent3e780e2c3a93ea866dbf7db2ddf26bc78e91d0ee (diff)
cgroup: move all metrics initialization to meterics.goqmnguyen0711/adlternative-zh-cgroups-v2
As the metrics detected by Prometheus in cgroups V1 and V2 are basically the same but slightly different, the initialization of all V1/V2 metrics is put into metrics.go. This makes the code cleaner and easier to observe the differences between the detection meterics of V1 and V2. Signed-off-by: ZheNing Hu <adlternative@gmail.com>
-rw-r--r--internal/cgroups/metrics.go87
-rw-r--r--internal/cgroups/v1_linux.go51
-rw-r--r--internal/cgroups/v2_linux.go45
3 files changed, 100 insertions, 83 deletions
diff --git a/internal/cgroups/metrics.go b/internal/cgroups/metrics.go
new file mode 100644
index 000000000..a8ffa618f
--- /dev/null
+++ b/internal/cgroups/metrics.go
@@ -0,0 +1,87 @@
+package cgroups
+
+import "github.com/prometheus/client_golang/prometheus"
+
+type cgroupsMetrics struct {
+ memoryReclaimAttemptsTotal *prometheus.GaugeVec
+ cpuUsage *prometheus.GaugeVec
+ cpuCFSPeriods *prometheus.Desc
+ cpuCFSThrottledPeriods *prometheus.Desc
+ cpuCFSThrottledTime *prometheus.Desc
+ procs *prometheus.GaugeVec
+}
+
+func newV1CgroupsMetrics() *cgroupsMetrics {
+ return &cgroupsMetrics{
+ memoryReclaimAttemptsTotal: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_memory_reclaim_attempts_total",
+ Help: "Number of memory usage hits limits",
+ },
+ []string{"path"},
+ ),
+ cpuUsage: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_cpu_usage_total",
+ Help: "CPU Usage of Cgroup",
+ },
+ []string{"path", "type"},
+ ),
+ cpuCFSPeriods: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_periods_total",
+ "Number of elapsed enforcement period intervals",
+ []string{"path"}, nil,
+ ),
+ cpuCFSThrottledPeriods: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_throttled_periods_total",
+ "Number of throttled period intervals",
+ []string{"path"}, nil,
+ ),
+ cpuCFSThrottledTime: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_throttled_seconds_total",
+ "Total time duration the Cgroup has been throttled",
+ []string{"path"}, nil,
+ ),
+ procs: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_procs_total",
+ Help: "Total number of procs",
+ },
+ []string{"path", "subsystem"},
+ ),
+ }
+}
+
+func newV2CgroupsMetrics() *cgroupsMetrics {
+ return &cgroupsMetrics{
+ cpuUsage: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_cpu_usage_total",
+ Help: "CPU Usage of Cgroup",
+ },
+ []string{"path", "type"},
+ ),
+ cpuCFSPeriods: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_periods_total",
+ "Number of elapsed enforcement period intervals",
+ []string{"path"}, nil,
+ ),
+ cpuCFSThrottledPeriods: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_throttled_periods_total",
+ "Number of throttled period intervals",
+ []string{"path"}, nil,
+ ),
+ cpuCFSThrottledTime: prometheus.NewDesc(
+ "gitaly_cgroup_cpu_cfs_throttled_seconds_total",
+ "Total time duration the Cgroup has been throttled",
+ []string{"path"}, nil,
+ ),
+ procs: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_procs_total",
+ Help: "Total number of procs",
+ },
+ []string{"path", "subsystem"},
+ ),
+ }
+}
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index e9b81103a..22e9ab841 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -18,15 +18,11 @@ import (
)
type cgroupV1Handler struct {
- cfg cgroupscfg.Config
- hierarchy func() ([]cgroup1.Subsystem, error)
- memoryReclaimAttemptsTotal *prometheus.GaugeVec
- cpuUsage *prometheus.GaugeVec
- cpuCFSPeriods *prometheus.Desc
- cpuCFSThrottledPeriods *prometheus.Desc
- cpuCFSThrottledTime *prometheus.Desc
- procs *prometheus.GaugeVec
- pid int
+ cfg cgroupscfg.Config
+ hierarchy func() ([]cgroup1.Subsystem, error)
+
+ *cgroupsMetrics
+ pid int
}
func newV1Handler(cfg cgroupscfg.Config, pid int) *cgroupV1Handler {
@@ -36,42 +32,7 @@ func newV1Handler(cfg cgroupscfg.Config, pid int) *cgroupV1Handler {
hierarchy: func() ([]cgroup1.Subsystem, error) {
return defaultSubsystems(cfg.Mountpoint)
},
- memoryReclaimAttemptsTotal: prometheus.NewGaugeVec(
- prometheus.GaugeOpts{
- Name: "gitaly_cgroup_memory_reclaim_attempts_total",
- Help: "Number of memory usage hits limits",
- },
- []string{"path"},
- ),
- cpuUsage: prometheus.NewGaugeVec(
- prometheus.GaugeOpts{
- Name: "gitaly_cgroup_cpu_usage_total",
- Help: "CPU Usage of Cgroup",
- },
- []string{"path", "type"},
- ),
- cpuCFSPeriods: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_periods_total",
- "Number of elapsed enforcement period intervals",
- []string{"path"}, nil,
- ),
- cpuCFSThrottledPeriods: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_throttled_periods_total",
- "Number of throttled period intervals",
- []string{"path"}, nil,
- ),
- cpuCFSThrottledTime: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_throttled_seconds_total",
- "Total time duration the Cgroup has been throttled",
- []string{"path"}, nil,
- ),
- procs: prometheus.NewGaugeVec(
- prometheus.GaugeOpts{
- Name: "gitaly_cgroup_procs_total",
- Help: "Total number of procs",
- },
- []string{"path", "subsystem"},
- ),
+ cgroupsMetrics: newV1CgroupsMetrics(),
}
}
diff --git a/internal/cgroups/v2_linux.go b/internal/cgroups/v2_linux.go
index abcbfbdc6..a2f81f60b 100644
--- a/internal/cgroups/v2_linux.go
+++ b/internal/cgroups/v2_linux.go
@@ -20,48 +20,17 @@ import (
)
type cgroupV2Handler struct {
- cfg cgroupscfg.Config
- cpuUsage *prometheus.GaugeVec
- cpuCFSPeriods *prometheus.Desc
- cpuCFSThrottledPeriods *prometheus.Desc
- cpuCFSThrottledTime *prometheus.Desc
- procs *prometheus.GaugeVec
- pid int
+ cfg cgroupscfg.Config
+
+ *cgroupsMetrics
+ pid int
}
func newV2Handler(cfg cgroupscfg.Config, pid int) *cgroupV2Handler {
return &cgroupV2Handler{
- cfg: cfg,
- pid: pid,
- cpuUsage: prometheus.NewGaugeVec(
- prometheus.GaugeOpts{
- Name: "gitaly_cgroup_cpu_usage_total",
- Help: "CPU Usage of Cgroup",
- },
- []string{"path", "type"},
- ),
- cpuCFSPeriods: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_periods_total",
- "Number of elapsed enforcement period intervals",
- []string{"path"}, nil,
- ),
- cpuCFSThrottledPeriods: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_throttled_periods_total",
- "Number of throttled period intervals",
- []string{"path"}, nil,
- ),
- cpuCFSThrottledTime: prometheus.NewDesc(
- "gitaly_cgroup_cpu_cfs_throttled_seconds_total",
- "Total time duration the Cgroup has been throttled",
- []string{"path"}, nil,
- ),
- procs: prometheus.NewGaugeVec(
- prometheus.GaugeOpts{
- Name: "gitaly_cgroup_procs_total",
- Help: "Total number of procs",
- },
- []string{"path", "subsystem"},
- ),
+ cfg: cfg,
+ pid: pid,
+ cgroupsMetrics: newV2CgroupsMetrics(),
}
}