合成 SDK API
注:这是正在积极开发的实验包. 新的发布可能包括突破变化.
安装
npm install --save @google-cloud/synthetics-sdk-api
用云函数 V2
Google Cloud 监控合成需要一个 Cloud 函数 v2 目标,因此,本指南解释了如何设置一个使用该函数的简单函数 @google-cloud/synthetics-sdk-api 软件包.
$ npm init
$ npm install --save @google-cloud/synthetics-sdk-api
$ npm install --save @google-cloud/functions-framework
# This example uses node-fetch for http requests
$ npm install --save node-fetch
使用合成汉德勒中件
这个软件包为Google Cloud Monitoring Synthetics所引用的写作代码提供了一种便于使用可快速兼容的中间软件. 当向它提供用户书面功能时,会发送可能被Google服务所消耗的回复. 以下是一个例子 index.js 可用作云函数入口的文件.
// index.js
const assert = require("node:assert");
const functions = require('@google-cloud/functions-framework');
const fetch = require("node-fetch");
const GcmSynthetics = require('@google-cloud/synthetics-sdk-api');
functions.http('SyntheticFunction', GcmSynthetics.runSyntheticHandler(async () => {
const url = 'https://www.google.com/'; // URL to send the request to
return await assert.doesNotReject(fetch(url));
}));
无框架的使用
只要Google Cloud函数暴露出符合Synthetics SDK API软件包所定义的API光谱的http端点,Cloud函数就会成为Synthetic Monitor的目标. 因此,本套件包括了包含api spec的原型定义,以及由该原型所生成的打字类型.
如果您想要运行一个程序工作流程, 而其他 SyntheticSDK 并不适合该工作流程, 或者您想要为您的 Google Cloud 函数使用另一种语言, 但没有直接支持的话, 这是非常重要的 .
const functions = require('@google-cloud/functions-framework');
const { SyntheticResult, GenericResultV1 } = require('@google-cloud/synthetics-sdk-api');
有用链接
- 关于在平地节点的样本,见 一般合成-节点
- 关于使用打字符的样本,见 通用合成类型标记
- 对于活生生的,看 合成响应. proto
- 关于谷歌云监测合成器的文件,访问 云.google.com/监测/
- 关于云函数的文件,访问 https://cloud.google.com/ 函数