【问题标题】:How make a filter "does not contain" in Google Stackdriver logs如何在 Google Stackdriver 日志中制作“不包含”过滤器
【发布时间】:2018-05-20 02:48:39
【问题描述】:

在 Google Stackdriver 高级过滤器中,我可以插入如下内容:

resource.type="container"
resource.labels.cluster_name="mycluster"
textPayload!="Metric stackdriver_sink_successfully_sent_entry_count was not found in the cache."
severity="INFO"
textPayload:(helloworld)

最后一条规则意味着字段 textPayload 应该包含字符串 helloworld。 但我无法找到添加 NOT 运算符的方法。

我会使用类似的东西:

textPayload:!(helloworld)

但不起作用

【问题讨论】:

    标签: logging string-comparison google-cloud-stackdriver


    【解决方案1】:

    只需在两行之间添加 AND NOT:

    resource.type="container"
    resource.labels.cluster_name="mycluster"
    textPayload!="Metric stackdriver_sink_successfully_sent_entry_count was not found in the cache."
    severity="INFO" AND NOT
    textPayload:(helloworld)
    

    【讨论】:

    • 我不确定有什么区别,但对我来说,我必须在 textPayload 前面加上 ~textPayload:" text I dont want" 这样的波浪号才能正常工作
    【解决方案2】:

    顺便说一句,有时会在末尾出现\n

    您也可以点击日志,点击子条目并点击隐藏。

    【讨论】:

      【解决方案3】:

      如果您想排除包含“独角兽”一词的条目,可以使用过滤器-text:unicorn

      来源:https://cloud.google.com/logging/docs/view/basic-filters

      【讨论】:

      • 仅供参考,这行得通。但是,如果您尝试使用相同的查询创建一个指标,然后在指标资源管理器中查看它,则会显示“所选指标无效”。错误。所以@suikoy 的答案可能对那些使用基于日志的指标的人更有效
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 2019-02-21
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多