github.com/demonoid81/containerd@v1.3.4/metrics/cgroups/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 cgroups 20 21 import ( 22 v1 "github.com/containerd/containerd/metrics/types/v1" 23 metrics "github.com/docker/go-metrics" 24 "github.com/prometheus/client_golang/prometheus" 25 ) 26 27 var memoryMetrics = []*metric{ 28 { 29 name: "memory_cache", 30 help: "The cache amount used", 31 unit: metrics.Bytes, 32 vt: prometheus.GaugeValue, 33 getValues: func(stats *v1.Metrics) []value { 34 if stats.Memory == nil { 35 return nil 36 } 37 return []value{ 38 { 39 v: float64(stats.Memory.Cache), 40 }, 41 } 42 }, 43 }, 44 { 45 name: "memory_rss", 46 help: "The rss amount used", 47 unit: metrics.Bytes, 48 vt: prometheus.GaugeValue, 49 getValues: func(stats *v1.Metrics) []value { 50 if stats.Memory == nil { 51 return nil 52 } 53 return []value{ 54 { 55 v: float64(stats.Memory.RSS), 56 }, 57 } 58 }, 59 }, 60 { 61 name: "memory_rss_huge", 62 help: "The rss_huge amount used", 63 unit: metrics.Bytes, 64 vt: prometheus.GaugeValue, 65 getValues: func(stats *v1.Metrics) []value { 66 if stats.Memory == nil { 67 return nil 68 } 69 return []value{ 70 { 71 v: float64(stats.Memory.RSSHuge), 72 }, 73 } 74 }, 75 }, 76 { 77 name: "memory_mapped_file", 78 help: "The mapped_file amount used", 79 unit: metrics.Bytes, 80 vt: prometheus.GaugeValue, 81 getValues: func(stats *v1.Metrics) []value { 82 if stats.Memory == nil { 83 return nil 84 } 85 return []value{ 86 { 87 v: float64(stats.Memory.MappedFile), 88 }, 89 } 90 }, 91 }, 92 { 93 name: "memory_dirty", 94 help: "The dirty amount", 95 unit: metrics.Bytes, 96 vt: prometheus.GaugeValue, 97 getValues: func(stats *v1.Metrics) []value { 98 if stats.Memory == nil { 99 return nil 100 } 101 return []value{ 102 { 103 v: float64(stats.Memory.Dirty), 104 }, 105 } 106 }, 107 }, 108 { 109 name: "memory_writeback", 110 help: "The writeback amount", 111 unit: metrics.Bytes, 112 vt: prometheus.GaugeValue, 113 getValues: func(stats *v1.Metrics) []value { 114 if stats.Memory == nil { 115 return nil 116 } 117 return []value{ 118 { 119 v: float64(stats.Memory.Writeback), 120 }, 121 } 122 }, 123 }, 124 { 125 name: "memory_pgpgin", 126 help: "The pgpgin amount", 127 unit: metrics.Bytes, 128 vt: prometheus.GaugeValue, 129 getValues: func(stats *v1.Metrics) []value { 130 if stats.Memory == nil { 131 return nil 132 } 133 return []value{ 134 { 135 v: float64(stats.Memory.PgPgIn), 136 }, 137 } 138 }, 139 }, 140 { 141 name: "memory_pgpgout", 142 help: "The pgpgout amount", 143 unit: metrics.Bytes, 144 vt: prometheus.GaugeValue, 145 getValues: func(stats *v1.Metrics) []value { 146 if stats.Memory == nil { 147 return nil 148 } 149 return []value{ 150 { 151 v: float64(stats.Memory.PgPgOut), 152 }, 153 } 154 }, 155 }, 156 { 157 name: "memory_pgfault", 158 help: "The pgfault amount", 159 unit: metrics.Bytes, 160 vt: prometheus.GaugeValue, 161 getValues: func(stats *v1.Metrics) []value { 162 if stats.Memory == nil { 163 return nil 164 } 165 return []value{ 166 { 167 v: float64(stats.Memory.PgFault), 168 }, 169 } 170 }, 171 }, 172 { 173 name: "memory_pgmajfault", 174 help: "The pgmajfault amount", 175 unit: metrics.Bytes, 176 vt: prometheus.GaugeValue, 177 getValues: func(stats *v1.Metrics) []value { 178 if stats.Memory == nil { 179 return nil 180 } 181 return []value{ 182 { 183 v: float64(stats.Memory.PgMajFault), 184 }, 185 } 186 }, 187 }, 188 { 189 name: "memory_inactive_anon", 190 help: "The inactive_anon amount", 191 unit: metrics.Bytes, 192 vt: prometheus.GaugeValue, 193 getValues: func(stats *v1.Metrics) []value { 194 if stats.Memory == nil { 195 return nil 196 } 197 return []value{ 198 { 199 v: float64(stats.Memory.InactiveAnon), 200 }, 201 } 202 }, 203 }, 204 { 205 name: "memory_active_anon", 206 help: "The active_anon amount", 207 unit: metrics.Bytes, 208 vt: prometheus.GaugeValue, 209 getValues: func(stats *v1.Metrics) []value { 210 if stats.Memory == nil { 211 return nil 212 } 213 return []value{ 214 { 215 v: float64(stats.Memory.ActiveAnon), 216 }, 217 } 218 }, 219 }, 220 { 221 name: "memory_inactive_file", 222 help: "The inactive_file amount", 223 unit: metrics.Bytes, 224 vt: prometheus.GaugeValue, 225 getValues: func(stats *v1.Metrics) []value { 226 if stats.Memory == nil { 227 return nil 228 } 229 return []value{ 230 { 231 v: float64(stats.Memory.InactiveFile), 232 }, 233 } 234 }, 235 }, 236 { 237 name: "memory_active_file", 238 help: "The active_file amount", 239 unit: metrics.Bytes, 240 vt: prometheus.GaugeValue, 241 getValues: func(stats *v1.Metrics) []value { 242 if stats.Memory == nil { 243 return nil 244 } 245 return []value{ 246 { 247 v: float64(stats.Memory.ActiveFile), 248 }, 249 } 250 }, 251 }, 252 { 253 name: "memory_unevictable", 254 help: "The unevictable amount", 255 unit: metrics.Bytes, 256 vt: prometheus.GaugeValue, 257 getValues: func(stats *v1.Metrics) []value { 258 if stats.Memory == nil { 259 return nil 260 } 261 return []value{ 262 { 263 v: float64(stats.Memory.Unevictable), 264 }, 265 } 266 }, 267 }, 268 { 269 name: "memory_hierarchical_memory_limit", 270 help: "The hierarchical_memory_limit amount", 271 unit: metrics.Bytes, 272 vt: prometheus.GaugeValue, 273 getValues: func(stats *v1.Metrics) []value { 274 if stats.Memory == nil { 275 return nil 276 } 277 return []value{ 278 { 279 v: float64(stats.Memory.HierarchicalMemoryLimit), 280 }, 281 } 282 }, 283 }, 284 { 285 name: "memory_hierarchical_memsw_limit", 286 help: "The hierarchical_memsw_limit amount", 287 unit: metrics.Bytes, 288 vt: prometheus.GaugeValue, 289 getValues: func(stats *v1.Metrics) []value { 290 if stats.Memory == nil { 291 return nil 292 } 293 return []value{ 294 { 295 v: float64(stats.Memory.HierarchicalSwapLimit), 296 }, 297 } 298 }, 299 }, 300 { 301 name: "memory_total_cache", 302 help: "The total_cache amount used", 303 unit: metrics.Bytes, 304 vt: prometheus.GaugeValue, 305 getValues: func(stats *v1.Metrics) []value { 306 if stats.Memory == nil { 307 return nil 308 } 309 return []value{ 310 { 311 v: float64(stats.Memory.TotalCache), 312 }, 313 } 314 }, 315 }, 316 { 317 name: "memory_total_rss", 318 help: "The total_rss amount used", 319 unit: metrics.Bytes, 320 vt: prometheus.GaugeValue, 321 getValues: func(stats *v1.Metrics) []value { 322 if stats.Memory == nil { 323 return nil 324 } 325 return []value{ 326 { 327 v: float64(stats.Memory.TotalRSS), 328 }, 329 } 330 }, 331 }, 332 { 333 name: "memory_total_rss_huge", 334 help: "The total_rss_huge amount used", 335 unit: metrics.Bytes, 336 vt: prometheus.GaugeValue, 337 getValues: func(stats *v1.Metrics) []value { 338 if stats.Memory == nil { 339 return nil 340 } 341 return []value{ 342 { 343 v: float64(stats.Memory.TotalRSSHuge), 344 }, 345 } 346 }, 347 }, 348 { 349 name: "memory_total_mapped_file", 350 help: "The total_mapped_file amount used", 351 unit: metrics.Bytes, 352 vt: prometheus.GaugeValue, 353 getValues: func(stats *v1.Metrics) []value { 354 if stats.Memory == nil { 355 return nil 356 } 357 return []value{ 358 { 359 v: float64(stats.Memory.TotalMappedFile), 360 }, 361 } 362 }, 363 }, 364 { 365 name: "memory_total_dirty", 366 help: "The total_dirty amount", 367 unit: metrics.Bytes, 368 vt: prometheus.GaugeValue, 369 getValues: func(stats *v1.Metrics) []value { 370 if stats.Memory == nil { 371 return nil 372 } 373 return []value{ 374 { 375 v: float64(stats.Memory.TotalDirty), 376 }, 377 } 378 }, 379 }, 380 { 381 name: "memory_total_writeback", 382 help: "The total_writeback amount", 383 unit: metrics.Bytes, 384 vt: prometheus.GaugeValue, 385 getValues: func(stats *v1.Metrics) []value { 386 if stats.Memory == nil { 387 return nil 388 } 389 return []value{ 390 { 391 v: float64(stats.Memory.TotalWriteback), 392 }, 393 } 394 }, 395 }, 396 { 397 name: "memory_total_pgpgin", 398 help: "The total_pgpgin amount", 399 unit: metrics.Bytes, 400 vt: prometheus.GaugeValue, 401 getValues: func(stats *v1.Metrics) []value { 402 if stats.Memory == nil { 403 return nil 404 } 405 return []value{ 406 { 407 v: float64(stats.Memory.TotalPgPgIn), 408 }, 409 } 410 }, 411 }, 412 { 413 name: "memory_total_pgpgout", 414 help: "The total_pgpgout amount", 415 unit: metrics.Bytes, 416 vt: prometheus.GaugeValue, 417 getValues: func(stats *v1.Metrics) []value { 418 if stats.Memory == nil { 419 return nil 420 } 421 return []value{ 422 { 423 v: float64(stats.Memory.TotalPgPgOut), 424 }, 425 } 426 }, 427 }, 428 { 429 name: "memory_total_pgfault", 430 help: "The total_pgfault amount", 431 unit: metrics.Bytes, 432 vt: prometheus.GaugeValue, 433 getValues: func(stats *v1.Metrics) []value { 434 if stats.Memory == nil { 435 return nil 436 } 437 return []value{ 438 { 439 v: float64(stats.Memory.TotalPgFault), 440 }, 441 } 442 }, 443 }, 444 { 445 name: "memory_total_pgmajfault", 446 help: "The total_pgmajfault amount", 447 unit: metrics.Bytes, 448 vt: prometheus.GaugeValue, 449 getValues: func(stats *v1.Metrics) []value { 450 if stats.Memory == nil { 451 return nil 452 } 453 return []value{ 454 { 455 v: float64(stats.Memory.TotalPgMajFault), 456 }, 457 } 458 }, 459 }, 460 { 461 name: "memory_total_inactive_anon", 462 help: "The total_inactive_anon amount", 463 unit: metrics.Bytes, 464 vt: prometheus.GaugeValue, 465 getValues: func(stats *v1.Metrics) []value { 466 if stats.Memory == nil { 467 return nil 468 } 469 return []value{ 470 { 471 v: float64(stats.Memory.TotalInactiveAnon), 472 }, 473 } 474 }, 475 }, 476 { 477 name: "memory_total_active_anon", 478 help: "The total_active_anon amount", 479 unit: metrics.Bytes, 480 vt: prometheus.GaugeValue, 481 getValues: func(stats *v1.Metrics) []value { 482 if stats.Memory == nil { 483 return nil 484 } 485 return []value{ 486 { 487 v: float64(stats.Memory.TotalActiveAnon), 488 }, 489 } 490 }, 491 }, 492 { 493 name: "memory_total_inactive_file", 494 help: "The total_inactive_file amount", 495 unit: metrics.Bytes, 496 vt: prometheus.GaugeValue, 497 getValues: func(stats *v1.Metrics) []value { 498 if stats.Memory == nil { 499 return nil 500 } 501 return []value{ 502 { 503 v: float64(stats.Memory.TotalInactiveFile), 504 }, 505 } 506 }, 507 }, 508 { 509 name: "memory_total_active_file", 510 help: "The total_active_file amount", 511 unit: metrics.Bytes, 512 vt: prometheus.GaugeValue, 513 getValues: func(stats *v1.Metrics) []value { 514 if stats.Memory == nil { 515 return nil 516 } 517 return []value{ 518 { 519 v: float64(stats.Memory.TotalActiveFile), 520 }, 521 } 522 }, 523 }, 524 { 525 name: "memory_total_unevictable", 526 help: "The total_unevictable amount", 527 unit: metrics.Bytes, 528 vt: prometheus.GaugeValue, 529 getValues: func(stats *v1.Metrics) []value { 530 if stats.Memory == nil { 531 return nil 532 } 533 return []value{ 534 { 535 v: float64(stats.Memory.TotalUnevictable), 536 }, 537 } 538 }, 539 }, 540 { 541 name: "memory_usage_failcnt", 542 help: "The usage failcnt", 543 unit: metrics.Total, 544 vt: prometheus.GaugeValue, 545 getValues: func(stats *v1.Metrics) []value { 546 if stats.Memory == nil { 547 return nil 548 } 549 return []value{ 550 { 551 v: float64(stats.Memory.Usage.Failcnt), 552 }, 553 } 554 }, 555 }, 556 { 557 name: "memory_usage_limit", 558 help: "The memory limit", 559 unit: metrics.Bytes, 560 vt: prometheus.GaugeValue, 561 getValues: func(stats *v1.Metrics) []value { 562 if stats.Memory == nil { 563 return nil 564 } 565 return []value{ 566 { 567 v: float64(stats.Memory.Usage.Limit), 568 }, 569 } 570 }, 571 }, 572 { 573 name: "memory_usage_max", 574 help: "The memory maximum usage", 575 unit: metrics.Bytes, 576 vt: prometheus.GaugeValue, 577 getValues: func(stats *v1.Metrics) []value { 578 if stats.Memory == nil { 579 return nil 580 } 581 return []value{ 582 { 583 v: float64(stats.Memory.Usage.Max), 584 }, 585 } 586 }, 587 }, 588 { 589 name: "memory_usage_usage", 590 help: "The memory usage", 591 unit: metrics.Bytes, 592 vt: prometheus.GaugeValue, 593 getValues: func(stats *v1.Metrics) []value { 594 if stats.Memory == nil { 595 return nil 596 } 597 return []value{ 598 { 599 v: float64(stats.Memory.Usage.Usage), 600 }, 601 } 602 }, 603 }, 604 { 605 name: "memory_swap_failcnt", 606 help: "The swap failcnt", 607 unit: metrics.Total, 608 vt: prometheus.GaugeValue, 609 getValues: func(stats *v1.Metrics) []value { 610 if stats.Memory == nil { 611 return nil 612 } 613 return []value{ 614 { 615 v: float64(stats.Memory.Swap.Failcnt), 616 }, 617 } 618 }, 619 }, 620 { 621 name: "memory_swap_limit", 622 help: "The swap limit", 623 unit: metrics.Bytes, 624 vt: prometheus.GaugeValue, 625 getValues: func(stats *v1.Metrics) []value { 626 if stats.Memory == nil { 627 return nil 628 } 629 return []value{ 630 { 631 v: float64(stats.Memory.Swap.Limit), 632 }, 633 } 634 }, 635 }, 636 { 637 name: "memory_swap_max", 638 help: "The swap maximum usage", 639 unit: metrics.Bytes, 640 vt: prometheus.GaugeValue, 641 getValues: func(stats *v1.Metrics) []value { 642 if stats.Memory == nil { 643 return nil 644 } 645 return []value{ 646 { 647 v: float64(stats.Memory.Swap.Max), 648 }, 649 } 650 }, 651 }, 652 { 653 name: "memory_swap_usage", 654 help: "The swap usage", 655 unit: metrics.Bytes, 656 vt: prometheus.GaugeValue, 657 getValues: func(stats *v1.Metrics) []value { 658 if stats.Memory == nil { 659 return nil 660 } 661 return []value{ 662 { 663 v: float64(stats.Memory.Swap.Usage), 664 }, 665 } 666 }, 667 }, 668 { 669 name: "memory_kernel_failcnt", 670 help: "The kernel failcnt", 671 unit: metrics.Total, 672 vt: prometheus.GaugeValue, 673 getValues: func(stats *v1.Metrics) []value { 674 if stats.Memory == nil { 675 return nil 676 } 677 return []value{ 678 { 679 v: float64(stats.Memory.Kernel.Failcnt), 680 }, 681 } 682 }, 683 }, 684 { 685 name: "memory_kernel_limit", 686 help: "The kernel limit", 687 unit: metrics.Bytes, 688 vt: prometheus.GaugeValue, 689 getValues: func(stats *v1.Metrics) []value { 690 if stats.Memory == nil { 691 return nil 692 } 693 return []value{ 694 { 695 v: float64(stats.Memory.Kernel.Limit), 696 }, 697 } 698 }, 699 }, 700 { 701 name: "memory_kernel_max", 702 help: "The kernel maximum usage", 703 unit: metrics.Bytes, 704 vt: prometheus.GaugeValue, 705 getValues: func(stats *v1.Metrics) []value { 706 if stats.Memory == nil { 707 return nil 708 } 709 return []value{ 710 { 711 v: float64(stats.Memory.Kernel.Max), 712 }, 713 } 714 }, 715 }, 716 { 717 name: "memory_kernel_usage", 718 help: "The kernel usage", 719 unit: metrics.Bytes, 720 vt: prometheus.GaugeValue, 721 getValues: func(stats *v1.Metrics) []value { 722 if stats.Memory == nil { 723 return nil 724 } 725 return []value{ 726 { 727 v: float64(stats.Memory.Kernel.Usage), 728 }, 729 } 730 }, 731 }, 732 { 733 name: "memory_kerneltcp_failcnt", 734 help: "The kerneltcp failcnt", 735 unit: metrics.Total, 736 vt: prometheus.GaugeValue, 737 getValues: func(stats *v1.Metrics) []value { 738 if stats.Memory == nil { 739 return nil 740 } 741 return []value{ 742 { 743 v: float64(stats.Memory.KernelTCP.Failcnt), 744 }, 745 } 746 }, 747 }, 748 { 749 name: "memory_kerneltcp_limit", 750 help: "The kerneltcp limit", 751 unit: metrics.Bytes, 752 vt: prometheus.GaugeValue, 753 getValues: func(stats *v1.Metrics) []value { 754 if stats.Memory == nil { 755 return nil 756 } 757 return []value{ 758 { 759 v: float64(stats.Memory.KernelTCP.Limit), 760 }, 761 } 762 }, 763 }, 764 { 765 name: "memory_kerneltcp_max", 766 help: "The kerneltcp maximum usage", 767 unit: metrics.Bytes, 768 vt: prometheus.GaugeValue, 769 getValues: func(stats *v1.Metrics) []value { 770 if stats.Memory == nil { 771 return nil 772 } 773 return []value{ 774 { 775 v: float64(stats.Memory.KernelTCP.Max), 776 }, 777 } 778 }, 779 }, 780 { 781 name: "memory_kerneltcp_usage", 782 help: "The kerneltcp usage", 783 unit: metrics.Bytes, 784 vt: prometheus.GaugeValue, 785 getValues: func(stats *v1.Metrics) []value { 786 if stats.Memory == nil { 787 return nil 788 } 789 return []value{ 790 { 791 v: float64(stats.Memory.KernelTCP.Usage), 792 }, 793 } 794 }, 795 }, 796 }