Fix prometheus metrics units

Signed-off-by: bpopovschi <zyqsempai@mail.ru>
This commit is contained in:
bpopovschi 2019-12-16 18:27:50 +02:00
parent b98cc79184
commit 6bfb24824b
2 changed files with 523 additions and 26 deletions

View File

@ -26,9 +26,9 @@ import (
var cpuMetrics = []*metric{ var cpuMetrics = []*metric{
{ {
name: "cpu", name: "cpu_usage",
help: "Current cpu usage_usec (cgroup v2)", help: "Total cpu usage (cgroup v2)",
unit: metrics.Unit("usage_usec"), unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {
@ -42,9 +42,9 @@ var cpuMetrics = []*metric{
}, },
}, },
{ {
name: "cpu", name: "cpu_user_usage",
help: "Current cpu user_usec (cgroup v2)", help: "Current cpu usage in user space (cgroup v2)",
unit: metrics.Unit("user_usec"), unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {
@ -58,9 +58,9 @@ var cpuMetrics = []*metric{
}, },
}, },
{ {
name: "cpu", name: "cpu_kernel_usage",
help: "Current cpu system_usec (cgroup v2)", help: "Current cpu usage in kernel space (cgroup v2)",
unit: metrics.Unit("system_usec"), unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {
@ -74,9 +74,9 @@ var cpuMetrics = []*metric{
}, },
}, },
{ {
name: "cpu", name: "cpu_nr_periods",
help: "Current cpu nr_periods (only if controller is enabled)", help: "Current cpu number of periods (only if controller is enabled)",
unit: metrics.Unit("nr_periods"), unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {
@ -90,9 +90,9 @@ var cpuMetrics = []*metric{
}, },
}, },
{ {
name: "cpu", name: "cpu_nr_throttled",
help: "Current cpu nr_throttled (only if controller is enabled)", help: "Total number of times tasks have been throttled (only if controller is enabled)",
unit: metrics.Unit("nr_throttled"), unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {
@ -106,9 +106,9 @@ var cpuMetrics = []*metric{
}, },
}, },
{ {
name: "cpu", name: "cpu_throttled_usec",
help: "Current cpu throttled_usec (only if controller is enabled)", help: "Total time duration for which tasks have been throttled. (only if controller is enabled)",
unit: metrics.Unit("throttled_usec"), unit: metrics.Nanoseconds,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.CPU == nil { if stats.CPU == nil {

View File

@ -26,9 +26,9 @@ import (
var memoryMetrics = []*metric{ var memoryMetrics = []*metric{
{ {
name: "memory", name: "memory_usage",
help: "Current memory usage (cgroup v2)", help: "Current memory usage (cgroup v2)",
unit: metrics.Unit("usage"), unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil { if stats.Memory == nil {
@ -42,9 +42,9 @@ var memoryMetrics = []*metric{
}, },
}, },
{ {
name: "memory", name: "memory_limit",
help: "Current memory usage limit (cgroup v2)", help: "Current memory usage limit (cgroup v2)",
unit: metrics.Unit("limit"), unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil { if stats.Memory == nil {
@ -58,9 +58,9 @@ var memoryMetrics = []*metric{
}, },
}, },
{ {
name: "memory", name: "memory_swap_usage",
help: "Current swap usage (cgroup v2)", help: "Current swap usage (cgroup v2)",
unit: metrics.Unit("swap"), unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil { if stats.Memory == nil {
@ -74,9 +74,9 @@ var memoryMetrics = []*metric{
}, },
}, },
{ {
name: "memory", name: "memory_swap_Limit",
help: "Current swap usage limit (cgroup v2)", help: "Current swap usage limit (cgroup v2)",
unit: metrics.Unit("swap_limit"), unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value { getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil { if stats.Memory == nil {
@ -89,4 +89,501 @@ var memoryMetrics = []*metric{
} }
}, },
}, },
{
name: "memory_mapped_file",
help: "The mapped_file amount used",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.FileMapped),
},
}
},
},
{
name: "memory_dirty_file",
help: "The dirty file amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.FileDirty),
},
}
},
},
{
name: "memory_file_writeback",
help: "The file_writeback amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.FileWriteback),
},
}
},
},
{
name: "memory_pgactive",
help: "The pgactive amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgactivate),
},
}
},
},
{
name: "memory_pgdeactivate",
help: "The pgdeactivate amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgdeactivate),
},
}
},
},
{
name: "memory_pgfault",
help: "The pgfault amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgfault),
},
}
},
},
{
name: "memory_pgmajfault",
help: "The pgmajfault amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgmajfault),
},
}
},
},
{
name: "memory_pglazyfree",
help: "The pglazyfree amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pglazyfree),
},
}
},
},
{
name: "memory_pgrefill",
help: "The pgrefill amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgrefill),
},
}
},
},
{
name: "memory_pglazyfreed",
help: "The pglazyfreed amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pglazyfreed),
},
}
},
},
{
name: "memory_pgscan",
help: "The pgscan amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgscan),
},
}
},
},
{
name: "memory_pgsteal",
help: "The pgsteal amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Pgsteal),
},
}
},
},
{
name: "memory_inactive_anon",
help: "The inactive_anon amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.InactiveAnon),
},
}
},
},
{
name: "memory_active_anon",
help: "The active_anon amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.ActiveAnon),
},
}
},
},
{
name: "memory_inactive_file",
help: "The inactive_file amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.InactiveFile),
},
}
},
},
{
name: "memory_active_file",
help: "The active_file amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.ActiveFile),
},
}
},
},
{
name: "memory_unevictable",
help: "The unevictable amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Unevictable),
},
}
},
},
{
name: "memory_anon",
help: "The anon amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Anon),
},
}
},
},
{
name: "memory_file",
help: "The file amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.File),
},
}
},
},
{
name: "memory_kernel_stack",
help: "The kernel_stack amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.KernelStack),
},
}
},
},
{
name: "memory_slab",
help: "The slab amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Slab),
},
}
},
},
{
name: "memory_sock",
help: "The sock amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Sock),
},
}
},
},
{
name: "memory_shmem",
help: "The shmem amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.Shmem),
},
}
},
},
{
name: "memory_anon_thp",
help: "The anon_thp amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.AnonThp),
},
}
},
},
{
name: "memory_slab_reclaimable",
help: "The slab_reclaimable amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.SlabReclaimable),
},
}
},
},
{
name: "memory_slab_unreclaimable",
help: "The slab_unreclaimable amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.SlabUnreclaimable),
},
}
},
},
{
name: "memory_workingset_refault",
help: "The workingset_refault amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.WorkingsetRefault),
},
}
},
},
{
name: "memory_workingset_activate",
help: "The workingset_activate amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.WorkingsetActivate),
},
}
},
},
{
name: "memory_workingset_nodereclaim",
help: "The workingset_nodereclaim amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.WorkingsetNodereclaim),
},
}
},
},
{
name: "memory_thp_fault_alloc",
help: "The thp_fault_alloc amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.ThpFaultAlloc),
},
}
},
},
{
name: "memory_thp_collapse_alloc",
help: "The thp_collapse_alloc amount",
unit: metrics.Bytes,
vt: prometheus.GaugeValue,
getValues: func(stats *v2.Metrics) []value {
if stats.Memory == nil {
return nil
}
return []value{
{
v: float64(stats.Memory.ThpCollapseAlloc),
},
}
},
},
} }