You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

  1. // Copyright (c) 2015-2024 MinIO, Inc.
  2. //
  3. // # This file is part of MinIO Object Storage stack
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. package cmd
  18. import (
  19. "context"
  20. )
  21. const (
  22. memTotal = "total"
  23. memUsed = "used"
  24. memFree = "free"
  25. memBuffers = "buffers"
  26. memCache = "cache"
  27. memUsedPerc = "used_perc"
  28. memShared = "shared"
  29. memAvailable = "available"
  30. )
  31. var (
  32. memTotalMD = NewGaugeMD(memTotal, "Total memory on the node")
  33. memUsedMD = NewGaugeMD(memUsed, "Used memory on the node")
  34. memUsedPercMD = NewGaugeMD(memUsedPerc, "Used memory percentage on the node")
  35. memFreeMD = NewGaugeMD(memFree, "Free memory on the node")
  36. memBuffersMD = NewGaugeMD(memBuffers, "Buffers memory on the node")
  37. memCacheMD = NewGaugeMD(memCache, "Cache memory on the node")
  38. memSharedMD = NewGaugeMD(memShared, "Shared memory on the node")
  39. memAvailableMD = NewGaugeMD(memAvailable, "Available memory on the node")
  40. )
  41. // loadMemoryMetrics - `MetricsLoaderFn` for node memory metrics.
  42. func loadMemoryMetrics(ctx context.Context, m MetricValues, c *metricsCache) error {
  43. memMetrics, err := c.memoryMetrics.Get()
  44. if err != nil {
  45. metricsLogIf(ctx, err)
  46. return err
  47. }
  48. m.Set(memTotal, float64(memMetrics.Total))
  49. m.Set(memUsed, float64(memMetrics.Used))
  50. usedPerc := float64(memMetrics.Used) * 100 / float64(memMetrics.Total)
  51. m.Set(memUsedPerc, usedPerc)
  52. m.Set(memFree, float64(memMetrics.Free))
  53. m.Set(memBuffers, float64(memMetrics.Buffers))
  54. m.Set(memCache, float64(memMetrics.Cache))
  55. m.Set(memShared, float64(memMetrics.Shared))
  56. m.Set(memAvailable, float64(memMetrics.Available))
  57. return nil
  58. }