简体   繁体   English

使用 Grafana Loki 通过抓取进行过滤

[英]Filtering through scraping with Grafana Loki

i am trying to get logs from a single namespace through promtail and scrape_configs, but i am not getting results.我试图通过 promtail 和 scrape_configs 从单个命名空间获取日志,但我没有得到结果。 I am installing in k8s with我正在使用 k8s 安装

helm install loki grafana/loki-stack -n loki-test -f ~/loki-stack-values.yml helm install loki grafana/loki-stack -n loki-test -f ~/loki-stack-values.yml

and the contents of my values file are:我的值文件的内容是:

loki:
 enabled: true

promtail:
 enabled: true
 pipelineStages:
 - cri: {}
 - json:
  expressions:
   is_even: is_even
   level: level
   version: version
 scrape_configs:
 - job_name: kubernetes-pods
  kubernetes_sd_configs:
  - role: pod
  relabel_configs:
  - source_labels: [__meta_kubernetes_namespace]
   action: keep
   regex: mongodb-test
 # [...]

 - job_name: kubernetes-pods-app
  kubernetes_sd_configs:
  - role: pod
  relabel_configs:
  - source_labels: [__meta_kubernetes_namespace]
   action: keep
   regex: mongodb-test

grafana:
 enabled: true
 sidecar:
 datasources:
  enabled: true
 image:
 tag: 8.3.5

My expectation was that i will only get logs from the mongodb-test namespace, but i can view from any namespace present.我的期望是我只会从 mongodb-test 命名空间获取日志,但我可以从任何存在的命名空间查看。 Also tried with drop, but it did not do anything.也尝试了 drop ,但它没有做任何事情。

What should i do here?我应该在这里做什么? Thank you so much太感谢了

Using match statement to drop other namespaces under pipeline stages worked for me.使用 match 语句删除管道阶段下的其他命名空间对我有用。 In your case,在你的情况下,

config:
  snippets:
    pipelineStages:
      - cri: {}
      - match:
          selector: '{namespace!~"mongodb-test"}'
          action: drop
    common:
      - action: replace
        source_labels:
          - __meta_kubernetes_namespace
        target_label: namespace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM