简体   繁体   English

如何使用 GoLang 使用 Google PubSub opencensus 指标?

[英]How to consume Google PubSub opencensus metrics using GoLang?

I am new in Google PubSub.我是 Google PubSub 的新手。 I am using GoLang for the client library.我正在使用 GoLang 作为客户端库。

How to see the opencensus metrics that recorded by the google-cloud-go library?如何查看 google-cloud-go 库记录的 opencensus 指标?

I already success publish a message to Google PubSub.我已经成功向 Google PubSub 发布了一条消息。 And now I want to see this metrics, but I can not find these metrics in Google Stackdriver.现在我想查看这个指标,但我在 Google Stackdriver 中找不到这些指标。

PublishLatency = stats.Float64(statsPrefix+"publish_roundtrip_latency", "The latency in milliseconds per publish batch", stats.UnitMilliseconds)

https://github.com/googleapis/google-cloud-go/blob/25803d86c6f5d3a315388d369bf6ddecfadfbfb5/pubsub/trace.go#L59 https://github.com/googleapis/google-cloud-go/blob/25803d86c6f5d3a315388d369bf6ddecfadfbfb5/pubsub/trace.go#L59

This is curious;这很奇怪; I'm surprised to see these (machine-generated) APIs sprinkled with OpenCensus (Stats) integration.我很惊讶地看到这些(机器生成的)API 散布着 OpenCensus(Stats)集成。

I've not tried this but I'm familiar with OpenCensus.没有尝试过,但我熟悉 OpenCensus。

One of OpenCensus' benefits is that it loosely-couples the generation of eg metrics from the consumption. OpenCensus 的好处之一是它松散地耦合了消费指标的生成。 So, while the code defines the metrics (and views), I expect (?.) the API leaves it to you to choose which Exporter(s) you'd like to use and to configure these.因此,虽然代码定义了指标(和视图),但我希望 (?.) API 让您选择要使用的导出器并配置它们。

In your code, you'll need to import the Stackdriver (and any other exporters you wish to use) and then follow these instructions:在您的代码中,您需要导入 Stackdriver(以及您希望使用的任何其他导出器),然后按照以下说明进行操作:

https://opencensus.io/exporters/supported-exporters/go/stackdriver/#creating-the-exporter https://opencensus.io/exporters/supported-exporters/go/stackdriver/#creating-the-exporter

NOTE I encourage you to look at the OpenCensus Agent too as this further decouples your code;注意我鼓励您也查看 OpenCensus 代理,因为这会进一步解耦您的代码; you reference the generic Opencensus Agent in your code and configure the agent to route eg metrics to eg Stackdriver.您在代码中引用通用 Opencensus 代理并配置代理以将例如指标路由到例如 Stackdriver。

For Stackdriver, you will need to configure the exporter with a GCP Project ID and that project will need to have Stackdriver Monitor enabled (and configured).对于 Stackdriver,您需要使用 GCP 项目 ID 配置导出器,并且该项目需要启用(并配置)Stackdriver Monitor。 I've not used Stackdriver in some months but this used to require a manual step too.我已经有几个月没有使用 Stackdriver 了,但这过去也需要手动操作。 Easiest way to check is to visit:最简单的检查方法是访问:

https://console.cloud.google.com/monitoring/?project=[[YOUR-PROJECT]] https://console.cloud.google.com/monitoring/?project=[[YOUR-PROJECT]]

If I understand the intent (,) correctly.如果我正确理解了意图(,)。 I expect API calls will then record stats at the metrics in the views defined in the code that you referenced.我希望 API 调用将在您引用的代码中定义的视图中的指标上记录统计信息。

Once you're confident that metrics are being shipped to Stackdriver, the easiest way to confirm this is to query a metric using Stackdriver's metrics explorer:一旦您确信指标正在发送到 Stackdriver,确认这一点的最简单方法是使用 Stackdriver 的指标资源管理器查询指标:

https://console.cloud.google.com/monitoring/metrics-explorer?project=[[YOUR-PROJECT]] https://console.cloud.google.com/monitoring/metrics-explorer?project=[[YOUR-PROJECT]]

You may wish to test this approach using the Prometheus Exporter because it's simpler.您可能希望使用Prometheus Exporter来测试这种方法,因为它更简单。 After configuring the Prometheus Exporter, when you run your code, it will be create an HTTP server and you can curl the metrics that are being generated on:配置 Prometheus 导出器后,当您运行代码时,它将创建一个 HTTP 服务器,您可以 curl 生成正在生成的指标:

http://localhost:8888/metrics http://localhost:8888/metrics

NOTE Opencensus is being (??) deprecated in favor of a replacement solution called OpenTelemetry .注意Opencensus 正在被 (??) 弃用,取而代之的是一种名为OpenTelemetry的替代解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Golang 读取 Google Cloud Pubsub 消息并写入 BigQuery - Read Google Cloud Pubsub message and write to BigQuery using Golang Google pubsub 死字在 golang 中不起作用 - Google pubsub dead lettering not works in golang 自定义OpenCensus指标未显示在Stackdriver上 - Custom OpenCensus metrics not appearing on Stackdriver 如何使用 OpenCensus 检测 Prometheus Gauge? - How to instrument Prometheus Gauge using OpenCensus? 将Google PubSub与Golang配合使用。 轮询服务的最有效(成本)方式 - Using Google PubSub with Golang. The most efficient (cost) way to poll the service 如何使用client_golang在Prometheus中提取指标 - How to pull metrics in prometheus using client_golang 如何使用client_golang将指标推送到prometheus? - How to push metrics to prometheus using client_golang? 如何使用客户端 golang 在 cloudwatch 中拉/推指标 - how to pull/push metrics in cloudwatch using client golang 来自Opencensus图书馆的Golang供应商问题 - Vendoring problem from Opencensus Libraries for Golang “新样式”的google pubsub golang函数无法正常工作 - “new style” google pubsub golang functions not working right
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM