首页 文章

用于Nodejs事件循环延迟的StackDriver自定义度量标准

提问于
浏览
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 来写入重叠时间 Span 的数据,因为另一个假实例已经写好了 . 现在,监视器客户端抛出错误

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实例中编写(运行 y 实例的 x AppEngine服务) .

我正在考虑 type ,它被编入 nodejs/eventloop/latency/{serviceName}/{serviceVersion}/{instanceId} 索引,但它看起来有点极端,很快就会让我走向StackDriver帐户的配额 .

任何建议都非常感谢!

1 回答

相关问题