演示如何删除正常运行时间检查配置。
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
C#
public static object DeleteUptimeCheckConfig(string configName)
{
var client = UptimeCheckServiceClient.Create();
client.DeleteUptimeCheckConfig(configName);
Console.WriteLine($"Deleted {configName}");
return 0;
}
Go
// delete is an example of deleting an uptime check. resourceName should be
// of the form `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.
func delete(w io.Writer, resourceName string) error {
ctx := context.Background()
client, err := monitoring.NewUptimeCheckClient(ctx)
if err != nil {
return fmt.Errorf("NewUptimeCheckClient: %v", err)
}
defer client.Close()
req := &monitoringpb.DeleteUptimeCheckConfigRequest{
Name: resourceName,
}
if err := client.DeleteUptimeCheckConfig(ctx, req); err != nil {
return fmt.Errorf("DeleteUptimeCheckConfig: %v", err)
}
fmt.Fprintf(w, "Successfully deleted %q", resourceName)
return nil
}
Java
private static void deleteUptimeCheckConfig(String checkName) throws IOException {
try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
client.deleteUptimeCheckConfig(checkName);
} catch (Exception e) {
usage("Exception deleting uptime check: " + e.toString());
throw e;
}
}
Node.js
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');
// Creates a client
const client = new monitoring.UptimeCheckServiceClient();
/**
* TODO(developer): Uncomment and edit the following lines of code.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const uptimeCheckConfigId = 'YOUR_UPTIME_CHECK_CONFIG_ID';
const request = {
// i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check
name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId),
};
console.log(`Deleting ${request.name}`);
// Delete an uptime check config
await client.deleteUptimeCheckConfig(request);
console.log(`${request.name} deleted.`);
PHP
use Google\Cloud\Monitoring\V3\UptimeCheckServiceClient;
/**
* Example:
* ```
* delete_uptime_check($projectId, $configName);
* ```
*
* @param string $projectId Your project ID
* @param string $configName
*/
function delete_uptime_check($projectId, $configName)
{
$uptimeCheckClient = new UptimeCheckServiceClient([
'projectId' => $projectId,
]);
$uptimeCheckClient->deleteUptimeCheckConfig($configName);
printf('Deleted an uptime check: ' . $configName . PHP_EOL);
}
Python
# `config_name` is the `name` field of an UptimeCheckConfig.
# See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs#UptimeCheckConfig.
def delete_uptime_check_config(config_name):
client = monitoring_v3.UptimeCheckServiceClient()
client.delete_uptime_check_config(request={"name": config_name})
print("Deleted ", config_name)
Ruby
def delete_uptime_check_config config_name
require "google/cloud/monitoring"
client = Google::Cloud::Monitoring.uptime_check_service
client.delete_uptime_check_config name: config_name
puts "Deleted #{config_name}"
end
后续步骤
如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器。