【问题标题】:StackDriver Custom Metric for Nodejs event loop latencyNodejs 事件循环延迟的 StackDriver 自定义指标
【发布时间】:2018-07-13 23:39:18
【问题描述】:

我正在尝试为 Google StackDriver 构建一个自定义指标,我可以使用它来跟踪 nodejs 事件循环延迟。所有应用程序都在 Google AppEngine 中运行,因此我仅限于使用受监控的资源 global(至少据我了解)。

通过 nodejs @google/monitoring 客户端,我创建了一个指标描述符,如下所示:

{
  name: client.projectPath(projectId),
  metricDescriptor: {
    description: 'Nodejs event loop latency',
    displayName: 'Event Loop Latency',
    type: 'custom.googleapis.com/nodejs/eventloop/latency',
    metricKind: 'GAUGE',
    valueType: 'DOUBLE',
    unit: '{ms}',
    labels: [
      {
        key: 'instance_id',
        valueType: 'STRING',
        description: 'The ID of the instance reporting latency (containerId, vmId, etc.)',
      },
    ],
},

并将数据写入此自定义指标,例如:

metric: {
    type: 'custom.googleapis.com/nodejs/eventloop/latency',
    labels: {
      instance_id: instanceId,
    },
  },
  resource: {
    type: 'global',
    labels: {
      project_id: projectId,
    },
  },
  points: [{
    interval: {
      endTime: {
        seconds: item.at,
      },
    },
    value: {
      doubleValue: item.value,
    },
  }],
};

我在编写测试时认为一切都很好,直到我尝试更改我的instance_id 以写入另一个假实例已经写入的重叠时间跨度内的数据。现在监控客户端抛出错误

Error: One or more TimeSeries could not be written: Points must be written in order. One or more of the points specified was older than the most recent stored point.

这使我的自定义指标非常无用,只有一个 nodejs 进程可以写入此自定义指标。

现在我的问题是,我该如何规避这个问题?我希望能够从我所有正在运行的 nodejs 实例中写入(x AppEngine 服务和 y 实例正在运行)。

我在想一个在 nodejs/eventloop/latency/{serviceName}/{serviceVersion}/{instanceId} 上被索引的 type,但它似乎有点极端,很快就会让我达到 StackDriver 帐户的配额。

非常感谢任何建议!

【问题讨论】:

    标签: node.js google-app-engine stackdriver google-cloud-stackdriver


    【解决方案1】:

    Stackdriver 中自定义指标的时间序列数据必须按时间顺序写入,如 https://cloud.google.com/monitoring/custom-metrics/creating-metrics#which-resource 中所述。

    解决方法是通过为instance_id 添加用户定义的标签,为写入指标的每个实例创建单独的时间序列。如果需要,您还可以为 service_nameservice_version 添加单独的标签。但是,请注意标签值的基数。在单个指标上创建过多的时间序列会降低查询性能。

    有关什么是时间序列的更多详细信息:请参阅 https://cloud.google.com/monitoring/api/v3/metrics-details#intro-time-series

    【讨论】:

    • 感谢峰会 - 我希望自定义指标对我创建的每个标签都有一个时间序列,因为这可以解决我的问题。我想我将不得不创建唯一的 types 来跟踪所有正在运行的实例的指标。
    • 不,您不需要为每个实例创建唯一的指标type。我的建议是使用单一指标,以instance_id 作为标签。标签值的每个唯一组合都会创建一个时间序列。我已经在我的回答中澄清了这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 2018-02-20
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    相关资源
    最近更新 更多