问题描述
我正在尝试将我的应用程序(托管在Google云中)的正常运行时间历史记录保存到我自己的页面中.Google Cloud上是否有任何api这样的东西?我只需要获取日期以及上/下百分比或时间.
我已经在Google控制台上配置了正常运行时间检查.但是我需要将其集成到我的应用程序中.
是的,您可以这样做,但这并不明显,使用Cloud Monitoring以外的其他方式将正常运行时间数据导出到非GCP站点可能更容易:-)
如果您确实想使用Cloud Monitoring将此数据来源到GCP之外的页面,请选择Cloud Monitoring
我建议
资源类型为正常运行时间检查URL
( uptime_url
)
您可以使用的一项指标(!)是 Request Latency
( monitoring.googleapis.com/uptime_check/request_latency
)
如果填充Metrics Explorer,则应该看到与正常运行时间检查"页面上绘制的数据相同的数据.
点击查询编辑器
以将您的正常运行时间指标表示为云监控查询语言(MQL),并删除所有换行符.您可以使用:
获取uptime_url |指标'monitoring.googleapis.com/uptime_check/request_latency'|group_by 1m,[value_request_latency_mean:平均值(value.request_latency)] |每1m
因此,现在我们要查询Montioring公制时间序列
因此,例如请求正常运行时间检查的延迟,则可以使用Monitoring API的TimeSeries Query方法,并通过适当的查询来生成包括Point(值)数组的JSON数据.然后可以将这些值转换并显示到您的外部页面中.
I am trying to get my application(where hosted in google cloud) uptime history to a my own page. Is there any api so something on google cloud? I only need to get date and the up/down percentage or time.
I am already configure the uptime checks on google console. But I need to integrate this into my application.
Yes, you can but it's not obvious and it may be easier to use something other than Cloud Monitoring to export uptime data to a non-GCP site :-)
If you do want to use Cloud Monitoring to source this data into an off-GCP page, one of the Cloud Monitoring SDKs may be best. You can create a URL too (see below) but you'll need to authenticate this URL and that may make it too complex.
By way of an example, here's an Uptime check I created against my blog:
I recommend Google APIs Explorer as it's an excellent way to understand Google's services (via the REST APIs) and to test an approach.
First: List|Get Uptime Check(s)
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs/list
Plug in to the form on the right hand side parent
, the value of projects/${PROJECT}
If your Project ID is freddie-210224-66311747
then you'd type project/freddie-210224-66311747
.
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs/get
For this one, you need to provide name
, the value of projects/${PROJECT}/uptimeCheckConfigs/${UPTIME_CHECK}
If your Uptime check is called test
, then you'd type projects/freddie-210224-66311747/uptimeCheckConfigs/test
Click "Execute" (You don't need to have API Key
checked but it makes no difference).
What I learned is that Uptime checks are Metrics like all others. I confirmed this by watching the Chrome Dev Tools while I was watching Uptime checks.
Ensure that you use the correct metric name. You can use Monitoring's Metrics Explorer to confirm this:
The Resource Type is Uptime Check URL
(uptime_url
)
One (!) of the Metrics you may use is Request Latency
(monitoring.googleapis.com/uptime_check/request_latency
)
If you populate the Metrics Explorer, you should see the same data plotted as with the Uptime Check page.
Click Query Editor
to get your Uptime Metric represented as Cloud Monitoring Query Language (MQL), remove any line-feeds. You can use:
fetch uptime_url | metric 'monitoring.googleapis.com/uptime_check/request_latency' | group_by 1m, [value_request_latency_mean: mean(value.request_latency)] | every 1m
So, now we want to query Montioring Metric Time-series
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query
The value for name
is projects/${PROJECT}
For query
, paste in the MQL from above retain the quotes, i.e. "fetch uptime_url ..."
Hit EXECUTE
You should receive a snapshot of the time-series data underlying your Uptime URL. You can revise the MQL to reflect exactly the subset that you need. At 2021-02-24T20:55:38
the latency was 20.869
:
So, to get e.g. request latencies for your uptime checks, you can use the Monitoring API's TimeSeries Query method and, with a suitable Query, this will yield JSON data including an array of Point (values). These values could then be transformed and surfaced into your external page.
这篇关于将Google Cloud正常运行时间历史记录获取到第三方应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!