从单个主机的模板为所有主机创建 DataDog 仪表板

Create DataDog dashboard for all hosts from a template for a single host

不确定这里是否有专业的 DataDog 用户,但我希望如此。

我创建了一个模板 DataDog 仪表板模板,它通过 docker 容器捕获主机的内存使用情况。

"hostname"出现在5处左右:

{
  "viz": "timeseries",
  "status": "done",
  "requests": [
    {
      "q": "max:docker.mem.rss{host:are-P-swarmB-swarm-node-1} by {container_name}",
      "aggregator": "avg",
      "conditional_formats": [],
      "type": "area",
      "style": {
        "palette": "dog_classic"
      }
    },
    {
      "q": "max:system.mem.total{host:are-P-swarmB-swarm-node-1}",
      "conditional_formats": [],
      "type": "line",
      "style": {
        "palette": "warm",
        "type": "dashed",
        "width": "normal"
      }
    },
    {
      "q": "max:system.mem.total{host:are-P-swarmB-swarm-node-1} * 0.8",
      "conditional_formats": [],
      "type": "line",
      "style": {
        "palette": "orange",
        "type": "dashed",
        "width": "normal"
      }
    },
    {
      "q": "max:system.mem.total{host:are-P-swarmB-swarm-node-1} - max:system.mem.usable{host:are-P-swarmB-swarm-node-1}",
      "conditional_formats": [],
      "type": "line",
      "style": {
        "palette": "orange",
        "type": "dotted",
        "width": "thin"
      }
    }
  ],
  "autoscale": true,
  "yaxis": {
    "includeZero": false
  }
}

我现在正在尝试设置一个仪表板,为我的 20 多个主机中的每一个显示此模板,但克隆图表并在所有 5 个位置编辑主机名是一个痛苦的过程。每当我对模板进行更改时,我都必须痛苦地将更改粘贴到每个主机图表中,并在适用的地方更改主机名。

有没有一种方法可以设置此模板(可能用变量代替主机名)并让仪表板自动根据此模板为每个主机创建图表?如果做不到这一点,是否可以编写脚本?

谢谢。

好吧,您可以 使用 Datadog API 编写脚本来创建 20 个共享相同内容但主机不同的独特仪表板。这是 API 文档的一部分,可以帮助(示例!)for Timeboards, and this one for Screenboards

也就是说,我个人发现我自己的 Datadog 帐户中有 20 个仪表板有点混乱/笨拙。相反,如果是我,我会尝试 (A) 找到仪表板模板变量的巧妙用途(例如,集群标签、主机标签等),或 (B) 按每个主机标签分组并应用 the "top()" function 以某种方式,以便我能够只看到最有价值的主机。但这当然取决于你:)