【发布时间】: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