Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform Google警报策略基于云存储桶对象计数触发问题_Google Cloud Platform_Stackdriver_Google Cloud Stackdriver_Google Cloud Monitoring - Fatal编程技术网

Google cloud platform Google警报策略基于云存储桶对象计数触发问题

Google cloud platform Google警报策略基于云存储桶对象计数触发问题,google-cloud-platform,stackdriver,google-cloud-stackdriver,google-cloud-monitoring,Google Cloud Platform,Stackdriver,Google Cloud Stackdriver,Google Cloud Monitoring,我一直在尝试设置警报策略(通过堆栈驱动程序),以便在云存储桶中有新对象时获取电子邮件通知 但这里的问题是,它有时会在一段时间后起作用,而大多数时候不会 当bucket中有新文件时(每天多次),我们如何使警报立即触发 代码如下: resource "google_monitoring_alert_policy" "alert_policy" { display_name = "File notification" combiner = "OR" notification_cha

我一直在尝试设置警报策略(通过堆栈驱动程序),以便在云存储桶中有新对象时获取电子邮件通知

但这里的问题是,它有时会在一段时间后起作用,而大多数时候不会

当bucket中有新文件时(每天多次),我们如何使警报立即触发

代码如下:

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "File notification"
  combiner     = "OR"
  notification_channels = ["${google_monitoring_notification_channel.email.name}"]

  conditions {
    display_name = "File Notification"

    condition_threshold {
      comparison        = "COMPARISON_LT"
      duration          = "60s" 
      filter            = "metric.type=\"storage.googleapis.com/storage/object_count\" resource.type=\"gcs_bucket\" resource.label.\"bucket_name\"=\"realbucketname\""
      threshold_value   = 1

      aggregations {
        alignment_period        = "60s"
        per_series_aligner      = "ALIGN_COUNT"
      }

      trigger {
        count = 1
      }
    }
  }
  documentation {
    content = "There is a new file"
  }
}
感谢您的投入


谢谢

对象计数指标每天测量一次,因此该条件可能每天仅触发一次。这很可能就是您的警报不一致的原因

如果可能的话,推荐的查看bucket中对象更改的解决方案是通过。 使用发布/订阅通知,您可以在bucket中发生许多不同的事件时收到通知

下面是gsutil命令的一个示例,您可以使用它在bucket中创建对象时收到通知。e指定我只希望在特定事件发生时发出通知,在这种情况下,是在文件上载到bucket时

gsutil notification create -t [TOPIC_NAME] -f json gs://[BUCKET_NAME] -e OBJECT_FINALIZE
然后,您将创建一个用于接收通知的

下面是一个关于通过应用程序引擎管理存储桶上的通知的示例


您还可以研究如何使用独立函数来响应事件(将文件添加到bucket)。要通过功能发送电子邮件,您可以使用第三方服务,如。您还可以使用SMTP和NodeEmailer发送电子邮件

谢谢。我通过删除脚本中的聚合来修复它

现在一切如期而至

    condition_threshold {   
      comparison        = "COMPARISON_GT"
      duration          = "60s" 
      filter            = "metric.type=\"storage.googleapis.com/storage/object_count\" resource.type=\"gcs_bucket\" resource.label.\"bucket_name\"=\"realbucketname\""
      threshold_value   = 1