【问题标题】:How to record custom performance metrics with GCP Monitoring from python3 apps如何使用来自 python3 应用程序的 GCP 监控记录自定义性能指标
【发布时间】:2020-12-11 01:57:16
【问题描述】:

我正在开发可以添加到将指标发送到 GCP 监控的 python 方法的装饰器。该方法已得到确认,但如果我尝试发送超过 1 个观察,则推送指标的 API 调用会失败。模式是在流程完成后收集指标并刷新,以保持此测试的简单性。捕获内联指标的代码在这里:

    def append(self, value):
        now = time.time()
        seconds = int(now)
        nanos = int((now - seconds) * 10 ** 9)
        interval = monitoring_v3.TimeInterval(
            {"end_time": {"seconds": seconds, "nanos": nanos}}
        )
        point = monitoring_v3.Point({
            "interval": interval,
            "value": {"double_value": value}
            }
        )
        self.samples[self.name].append(point)

下面的代码在PerfMetric.samples dict 中获取一批数据点,这些数据点指向monitoring_v3.Point 类的数组,该类通过此处未显示的装饰器附加在方法append 中,以使用@987654325 调用名为create_time_series 的RPC @ 班级。我们指向一个数组数组,所以也许这不正确,或者我们的元数据在追加中不正确?

 @staticmethod
 def flush():
     client = monitoring_v3.MetricServiceClient()
     for x in PerfMetric.samples:
         print('{} has {} points'.format(x, len(PerfMetric.samples[x])))
         series = monitoring_v3.TimeSeries()
         series.metric.type = 'custom.googleapis.com/perf/{}'.format(x)
         series.resource.type = "global"
         series.points = PerfMetric.samples[x]
         client.create_time_series(request={
             "name": PerfMetric.project_name,
             "time_series": [series]}
         )

提前感谢您的任何建议!

【问题讨论】:

    标签: performance google-cloud-platform google-cloud-monitoring


    【解决方案1】:

    我认为这是来自 Cloud Monitoring API 的 TimeSeries 调用中关于其数据点的 points[] 对象的记录限制:

    创建时间序列时,该字段必须只包含一个点,并且该点的类型必须与关联指标的值类型相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多