我正在尝试为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 回答
Stackdriver中自定义指标的时间序列数据必须按顺序写入时间,如https://cloud.google.com/monitoring/custom-metrics/creating-metrics#which-resource中所述 .
解决方法是通过为
instance_id
添加用户定义的标签,为每个写入度量标准的实例创建单独的时间系列 . 如果需要,您还可以为service_name
或service_version
添加单独的标签 . 但是,请注意标签值的基数 . 在单个度量标准上创建过多的时间序列会降低查询性能 .有关时间序列的更多详细信息:请参阅https://cloud.google.com/monitoring/api/v3/metrics-details#intro-time-series .