0

我正在尝试为 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 实例(运行实例的xAppEngine 服务y)中写入。

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

任何建议都非常感谢!

4

1 回答 1

0

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

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

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

于 2018-02-03T22:09:25.573 回答