github.com/containerd/Containerd@v1.4.13/metrics/cgroups/v2/memory.go (about) 1 // +build linux 2 3 /* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 */ 18 19 package v2 20 21 import ( 22 v2 "github.com/containerd/containerd/metrics/types/v2" 23 metrics "github.com/docker/go-metrics" 24 "github.com/prometheus/client_golang/prometheus" 25 ) 26 27 var memoryMetrics = []*metric{ 28 { 29 name: "memory_usage", 30 help: "Current memory usage (cgroup v2)", 31 unit: metrics.Bytes, 32 vt: prometheus.GaugeValue, 33 getValues: func(stats *v2.Metrics) []value { 34 if stats.Memory == nil { 35 return nil 36 } 37 return []value{ 38 { 39 v: float64(stats.Memory.Usage), 40 }, 41 } 42 }, 43 }, 44 { 45 name: "memory_usage_limit", 46 help: "Current memory usage limit (cgroup v2)", 47 unit: metrics.Bytes, 48 vt: prometheus.GaugeValue, 49 getValues: func(stats *v2.Metrics) []value { 50 if stats.Memory == nil { 51 return nil 52 } 53 return []value{ 54 { 55 v: float64(stats.Memory.UsageLimit), 56 }, 57 } 58 }, 59 }, 60 { 61 name: "memory_swap_usage", 62 help: "Current swap usage (cgroup v2)", 63 unit: metrics.Bytes, 64 vt: prometheus.GaugeValue, 65 getValues: func(stats *v2.Metrics) []value { 66 if stats.Memory == nil { 67 return nil 68 } 69 return []value{ 70 { 71 v: float64(stats.Memory.SwapUsage), 72 }, 73 } 74 }, 75 }, 76 { 77 name: "memory_swap_limit", 78 help: "Current swap usage limit (cgroup v2)", 79 unit: metrics.Bytes, 80 vt: prometheus.GaugeValue, 81 getValues: func(stats *v2.Metrics) []value { 82 if stats.Memory == nil { 83 return nil 84 } 85 return []value{ 86 { 87 v: float64(stats.Memory.SwapLimit), 88 }, 89 } 90 }, 91 }, 92 93 { 94 name: "memory_file_mapped", 95 help: "The file_mapped amount", 96 unit: metrics.Bytes, 97 vt: prometheus.GaugeValue, 98 getValues: func(stats *v2.Metrics) []value { 99 if stats.Memory == nil { 100 return nil 101 } 102 return []value{ 103 { 104 v: float64(stats.Memory.FileMapped), 105 }, 106 } 107 }, 108 }, 109 { 110 name: "memory_file_dirty", 111 help: "The file_dirty amount", 112 unit: metrics.Bytes, 113 vt: prometheus.GaugeValue, 114 getValues: func(stats *v2.Metrics) []value { 115 if stats.Memory == nil { 116 return nil 117 } 118 return []value{ 119 { 120 v: float64(stats.Memory.FileDirty), 121 }, 122 } 123 }, 124 }, 125 { 126 name: "memory_file_writeback", 127 help: "The file_writeback amount", 128 unit: metrics.Bytes, 129 vt: prometheus.GaugeValue, 130 getValues: func(stats *v2.Metrics) []value { 131 if stats.Memory == nil { 132 return nil 133 } 134 return []value{ 135 { 136 v: float64(stats.Memory.FileWriteback), 137 }, 138 } 139 }, 140 }, 141 { 142 name: "memory_pgactivate", 143 help: "The pgactivate amount", 144 unit: metrics.Bytes, 145 vt: prometheus.GaugeValue, 146 getValues: func(stats *v2.Metrics) []value { 147 if stats.Memory == nil { 148 return nil 149 } 150 return []value{ 151 { 152 v: float64(stats.Memory.Pgactivate), 153 }, 154 } 155 }, 156 }, 157 { 158 name: "memory_pgdeactivate", 159 help: "The pgdeactivate amount", 160 unit: metrics.Bytes, 161 vt: prometheus.GaugeValue, 162 getValues: func(stats *v2.Metrics) []value { 163 if stats.Memory == nil { 164 return nil 165 } 166 return []value{ 167 { 168 v: float64(stats.Memory.Pgdeactivate), 169 }, 170 } 171 }, 172 }, 173 { 174 name: "memory_pgfault", 175 help: "The pgfault amount", 176 unit: metrics.Bytes, 177 vt: prometheus.GaugeValue, 178 getValues: func(stats *v2.Metrics) []value { 179 if stats.Memory == nil { 180 return nil 181 } 182 return []value{ 183 { 184 v: float64(stats.Memory.Pgfault), 185 }, 186 } 187 }, 188 }, 189 { 190 name: "memory_pgmajfault", 191 help: "The pgmajfault amount", 192 unit: metrics.Bytes, 193 vt: prometheus.GaugeValue, 194 getValues: func(stats *v2.Metrics) []value { 195 if stats.Memory == nil { 196 return nil 197 } 198 return []value{ 199 { 200 v: float64(stats.Memory.Pgmajfault), 201 }, 202 } 203 }, 204 }, 205 { 206 name: "memory_pglazyfree", 207 help: "The pglazyfree amount", 208 unit: metrics.Bytes, 209 vt: prometheus.GaugeValue, 210 getValues: func(stats *v2.Metrics) []value { 211 if stats.Memory == nil { 212 return nil 213 } 214 return []value{ 215 { 216 v: float64(stats.Memory.Pglazyfree), 217 }, 218 } 219 }, 220 }, 221 { 222 name: "memory_pgrefill", 223 help: "The pgrefill amount", 224 unit: metrics.Bytes, 225 vt: prometheus.GaugeValue, 226 getValues: func(stats *v2.Metrics) []value { 227 if stats.Memory == nil { 228 return nil 229 } 230 return []value{ 231 { 232 v: float64(stats.Memory.Pgrefill), 233 }, 234 } 235 }, 236 }, 237 { 238 name: "memory_pglazyfreed", 239 help: "The pglazyfreed amount", 240 unit: metrics.Bytes, 241 vt: prometheus.GaugeValue, 242 getValues: func(stats *v2.Metrics) []value { 243 if stats.Memory == nil { 244 return nil 245 } 246 return []value{ 247 { 248 v: float64(stats.Memory.Pglazyfreed), 249 }, 250 } 251 }, 252 }, 253 { 254 name: "memory_pgscan", 255 help: "The pgscan amount", 256 unit: metrics.Bytes, 257 vt: prometheus.GaugeValue, 258 getValues: func(stats *v2.Metrics) []value { 259 if stats.Memory == nil { 260 return nil 261 } 262 return []value{ 263 { 264 v: float64(stats.Memory.Pgscan), 265 }, 266 } 267 }, 268 }, 269 { 270 name: "memory_pgsteal", 271 help: "The pgsteal amount", 272 unit: metrics.Bytes, 273 vt: prometheus.GaugeValue, 274 getValues: func(stats *v2.Metrics) []value { 275 if stats.Memory == nil { 276 return nil 277 } 278 return []value{ 279 { 280 v: float64(stats.Memory.Pgsteal), 281 }, 282 } 283 }, 284 }, 285 { 286 name: "memory_inactive_anon", 287 help: "The inactive_anon amount", 288 unit: metrics.Bytes, 289 vt: prometheus.GaugeValue, 290 getValues: func(stats *v2.Metrics) []value { 291 if stats.Memory == nil { 292 return nil 293 } 294 return []value{ 295 { 296 v: float64(stats.Memory.InactiveAnon), 297 }, 298 } 299 }, 300 }, 301 { 302 name: "memory_active_anon", 303 help: "The active_anon amount", 304 unit: metrics.Bytes, 305 vt: prometheus.GaugeValue, 306 getValues: func(stats *v2.Metrics) []value { 307 if stats.Memory == nil { 308 return nil 309 } 310 return []value{ 311 { 312 v: float64(stats.Memory.ActiveAnon), 313 }, 314 } 315 }, 316 }, 317 { 318 name: "memory_inactive_file", 319 help: "The inactive_file amount", 320 unit: metrics.Bytes, 321 vt: prometheus.GaugeValue, 322 getValues: func(stats *v2.Metrics) []value { 323 if stats.Memory == nil { 324 return nil 325 } 326 return []value{ 327 { 328 v: float64(stats.Memory.InactiveFile), 329 }, 330 } 331 }, 332 }, 333 { 334 name: "memory_active_file", 335 help: "The active_file amount", 336 unit: metrics.Bytes, 337 vt: prometheus.GaugeValue, 338 getValues: func(stats *v2.Metrics) []value { 339 if stats.Memory == nil { 340 return nil 341 } 342 return []value{ 343 { 344 v: float64(stats.Memory.ActiveFile), 345 }, 346 } 347 }, 348 }, 349 { 350 name: "memory_unevictable", 351 help: "The unevictable amount", 352 unit: metrics.Bytes, 353 vt: prometheus.GaugeValue, 354 getValues: func(stats *v2.Metrics) []value { 355 if stats.Memory == nil { 356 return nil 357 } 358 return []value{ 359 { 360 v: float64(stats.Memory.Unevictable), 361 }, 362 } 363 }, 364 }, 365 { 366 name: "memory_anon", 367 help: "The anon amount", 368 unit: metrics.Bytes, 369 vt: prometheus.GaugeValue, 370 getValues: func(stats *v2.Metrics) []value { 371 if stats.Memory == nil { 372 return nil 373 } 374 return []value{ 375 { 376 v: float64(stats.Memory.Anon), 377 }, 378 } 379 }, 380 }, 381 { 382 name: "memory_file", 383 help: "The file amount", 384 unit: metrics.Bytes, 385 vt: prometheus.GaugeValue, 386 getValues: func(stats *v2.Metrics) []value { 387 if stats.Memory == nil { 388 return nil 389 } 390 return []value{ 391 { 392 v: float64(stats.Memory.File), 393 }, 394 } 395 }, 396 }, 397 { 398 name: "memory_kernel_stack", 399 help: "The kernel_stack amount", 400 unit: metrics.Bytes, 401 vt: prometheus.GaugeValue, 402 getValues: func(stats *v2.Metrics) []value { 403 if stats.Memory == nil { 404 return nil 405 } 406 return []value{ 407 { 408 v: float64(stats.Memory.KernelStack), 409 }, 410 } 411 }, 412 }, 413 { 414 name: "memory_slab", 415 help: "The slab amount", 416 unit: metrics.Bytes, 417 vt: prometheus.GaugeValue, 418 getValues: func(stats *v2.Metrics) []value { 419 if stats.Memory == nil { 420 return nil 421 } 422 return []value{ 423 { 424 v: float64(stats.Memory.Slab), 425 }, 426 } 427 }, 428 }, 429 { 430 name: "memory_sock", 431 help: "The sock amount", 432 unit: metrics.Bytes, 433 vt: prometheus.GaugeValue, 434 getValues: func(stats *v2.Metrics) []value { 435 if stats.Memory == nil { 436 return nil 437 } 438 return []value{ 439 { 440 v: float64(stats.Memory.Sock), 441 }, 442 } 443 }, 444 }, 445 { 446 name: "memory_shmem", 447 help: "The shmem amount", 448 unit: metrics.Bytes, 449 vt: prometheus.GaugeValue, 450 getValues: func(stats *v2.Metrics) []value { 451 if stats.Memory == nil { 452 return nil 453 } 454 return []value{ 455 { 456 v: float64(stats.Memory.Shmem), 457 }, 458 } 459 }, 460 }, 461 { 462 name: "memory_anon_thp", 463 help: "The anon_thp amount", 464 unit: metrics.Bytes, 465 vt: prometheus.GaugeValue, 466 getValues: func(stats *v2.Metrics) []value { 467 if stats.Memory == nil { 468 return nil 469 } 470 return []value{ 471 { 472 v: float64(stats.Memory.AnonThp), 473 }, 474 } 475 }, 476 }, 477 { 478 name: "memory_slab_reclaimable", 479 help: "The slab_reclaimable amount", 480 unit: metrics.Bytes, 481 vt: prometheus.GaugeValue, 482 getValues: func(stats *v2.Metrics) []value { 483 if stats.Memory == nil { 484 return nil 485 } 486 return []value{ 487 { 488 v: float64(stats.Memory.SlabReclaimable), 489 }, 490 } 491 }, 492 }, 493 { 494 name: "memory_slab_unreclaimable", 495 help: "The slab_unreclaimable amount", 496 unit: metrics.Bytes, 497 vt: prometheus.GaugeValue, 498 getValues: func(stats *v2.Metrics) []value { 499 if stats.Memory == nil { 500 return nil 501 } 502 return []value{ 503 { 504 v: float64(stats.Memory.SlabUnreclaimable), 505 }, 506 } 507 }, 508 }, 509 { 510 name: "memory_workingset_refault", 511 help: "The workingset_refault amount", 512 unit: metrics.Bytes, 513 vt: prometheus.GaugeValue, 514 getValues: func(stats *v2.Metrics) []value { 515 if stats.Memory == nil { 516 return nil 517 } 518 return []value{ 519 { 520 v: float64(stats.Memory.WorkingsetRefault), 521 }, 522 } 523 }, 524 }, 525 { 526 name: "memory_workingset_activate", 527 help: "The workingset_activate amount", 528 unit: metrics.Bytes, 529 vt: prometheus.GaugeValue, 530 getValues: func(stats *v2.Metrics) []value { 531 if stats.Memory == nil { 532 return nil 533 } 534 return []value{ 535 { 536 v: float64(stats.Memory.WorkingsetActivate), 537 }, 538 } 539 }, 540 }, 541 { 542 name: "memory_workingset_nodereclaim", 543 help: "The workingset_nodereclaim amount", 544 unit: metrics.Bytes, 545 vt: prometheus.GaugeValue, 546 getValues: func(stats *v2.Metrics) []value { 547 if stats.Memory == nil { 548 return nil 549 } 550 return []value{ 551 { 552 v: float64(stats.Memory.WorkingsetNodereclaim), 553 }, 554 } 555 }, 556 }, 557 { 558 name: "memory_thp_fault_alloc", 559 help: "The thp_fault_alloc amount", 560 unit: metrics.Bytes, 561 vt: prometheus.GaugeValue, 562 getValues: func(stats *v2.Metrics) []value { 563 if stats.Memory == nil { 564 return nil 565 } 566 return []value{ 567 { 568 v: float64(stats.Memory.ThpFaultAlloc), 569 }, 570 } 571 }, 572 }, 573 { 574 name: "memory_thp_collapse_alloc", 575 help: "The thp_collapse_alloc amount", 576 unit: metrics.Bytes, 577 vt: prometheus.GaugeValue, 578 getValues: func(stats *v2.Metrics) []value { 579 if stats.Memory == nil { 580 return nil 581 } 582 return []value{ 583 { 584 v: float64(stats.Memory.ThpCollapseAlloc), 585 }, 586 } 587 }, 588 }, 589 { 590 name: "memory_oom", 591 help: "The number of times a container has received an oom event", 592 unit: metrics.Total, 593 vt: prometheus.GaugeValue, 594 getValues: func(stats *v2.Metrics) []value { 595 if stats.MemoryEvents == nil { 596 return nil 597 } 598 return []value{ 599 { 600 v: float64(stats.MemoryEvents.Oom), 601 }, 602 } 603 }, 604 }, 605 }