【问题标题】:How to get memory usage per target如何获取每个目标的内存使用情况
【发布时间】:2021-09-18 10:55:43
【问题描述】:

我一直在与 Prometheus 和 Grafana 合作,我试图将它们整合在一起。我目前的问题是我的节点导出器当前正在重定向到我能够做到的端口 9100:

然而,这只是总结了整个计算机的状态,但我想做的是我想获得每个目标的 RAM 使用情况:

# Sample config for Prometheus.

global:
  scrape_interval:     1s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 1s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'example'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  
  - job_name: node
    # If prometheus-node-exporter is installed, grab stats about the local
    # machine by default.
    static_configs:
      - targets: [
                  'localhost:8000',
                  'localhost:8001',
                  'localhost:8002',
                  'localhost:8003',
                  'localhost:8004',
                  'localhost:8005',
                  'localhost:8006',
                  'localhost:8007',
                  'localhost:8008',
                  'localhost:8009',
                  'localhost:8010',
                  'localhost:8011',
                  'localhost:8012',
                  'localhost:8013',
                  'localhost:8014',
                  'localhost:8015',
                  'localhost:8016',
                  'localhost:8002',
                  'localhost:8017',
                  'localhost:8018',
                  'localhost:8019',
                  'localhost:8020',
                  'localhost:8021',
                  'localhost:8022',
                  'localhost:8023',
                  'localhost:8024',
                  'localhost:8025',
                  'localhost:8026',
                  'localhost:8027',
                  'localhost:8028',
                  'localhost:8029',
                  'localhost:8030',
                  'localhost:8030',
                  'localhost:8031',
                  'localhost:8032',
                  'localhost:8033',
                  'localhost:8034',
                  'localhost:8035',
                  'localhost:8036',
                  'localhost:8037',
                  'localhost:8038',
                  'localhost:8039',
                  'localhost:8040',
                  'localhost:9100'
                ]

现在我被困在我不知道如何或是否有可能获得不同端口正在使用的 RAM 使用量的地方?

我想做的输出是:

编辑:

如何为每个节点运行一个节点导出器并使用实例标签来区分不同的节点/计算机?

【问题讨论】:

  • 您的抓取配置引用了在单台计算机 (localhost) 上运行的多个节点导出器。您应该为要监控的每台计算机指定主机名/IP 地址,否则您将复制指标,因为您要多次抓取一台计算机。有一个实例标签,您可以使用它来过滤/分组您的可视化,从而为您提供正在监控的每个节点/计算机的指标。
  • 嗨@BrandonMcClure - 是的,但如果我可能会问,怎么可能做到这一点?如果它甚至可能做到呢??
  • 您是否询问是否可以在单个实例(节点/计算机)上运行多个 node_exporter 并从每个实例中获取一些指标子集,答案是否定的。您应该只为每个节点运行 1 个 node_exporter 并使用实例标签来区分不同的节点/计算机。我认为通过在单台计算机上运行多个 node_exporters 来编辑您的问题,这对您有帮助。
  • 嗨@BrandonMcClure 我现在已经在最底部更新了我的问题。在你解释之前,我不确定它是如何工作的。但我不确定如何为每个端口添加实例标签。基本上如果它有意义......我有例如我正在运行的 5 个 py 脚本,我们可以调用 main1.py main2.py mainN.py - 每个 py 文件在启动脚本时都有自己的端口(端口 8000、8001、8002 ...),我希望能够获取每个脚本的 RAM USAGE/CPU USAGE 而不是总数。

标签: prometheus grafana


【解决方案1】:

出于历史目的保留此部分: 默认情况下,您的度量系列在抓取时会被赋予标签。最小值为jobinstance。 例如,如果您的度量系列是 node_memory_MemAvailable_bytes 您可以从您的目标之一中选择系列作为 node_memory_MemAvailable_bytes{instance="localhost:9100"} 这适用于任何类型的指标。 旁注:如果您的服务器上运行了多个 node_exporter,您将不会看到不同的信息。

编辑:

声明的问题是@ProtractorNewbie 希望能够从单个服务器导出 CPU 使用率。理想情况下,他们想使用 node_exporter。

今天node_exporter 无法提供进程信息。

但是,可以将 collectd 与配置并启用的 cgroupswrite_prometheus 插件一起使用。

那么您需要拥有这些服务中的每一个running as systemd services

您要使用的数据如下所示:

collectd_cgroups_cpu_total{cgroups="myservice.service",type="user",instance="myinstancename"} 0 1632740881417

您可以从那里执行任何典型的普罗米修斯操作。

【讨论】:

  • 您好!例如,如果我在我的 python 中设置连接到端口 8000 prometheus。您的意思是,如果我将实例更改为 8000,那么它将仅显示特定于该端口的 CPU/RAM?
  • 如果答案是肯定的,那么它似乎没有工作,因为它没有为我返回任何数据:/
  • 我现在也更新了我的问题,见最底部:)
  • 我明白了,这更像是一个关于如何公开服务器上运行的每个进程的 cpu 使用率的问题。
  • @ProtractorNewbie 我已经更新了我的答案以更准确地反映事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 2018-06-07
  • 1970-01-01
  • 2012-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多