我正在尝试为 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 帐户的配额。
任何建议都非常感谢!