---
# System prepended metadata

title: 'Install grafana-agent-flow in '

---

### Install grafana-agent-flow in Kubernetes cluster
CLUSTER_NAME=
GRAFANA_METRICS_URL=
GRAFANA_LOKI_URL=
GRAFANA_METRICS_USERNAME=
GRAFANA_LOKI_USERNAME=
GRAFANA_API_KEY=

```
helm repo add grafana https://grafana.github.io/helm-charts &&
  helm repo update &&
  helm upgrade --install grafana-k8s-monitoring grafana/k8s-monitoring \
    --namespace "grafana" --create-namespace --values - <<EOF
cluster:
  name: $(echo $CLUSTER_NAME)
externalServices:
  prometheus:
    host: $(echo $GRAFANA_METRICS_URL)
    basicAuth:
      username: "$(echo $GRAFANA_METRICS_USERNAME)"
      password: $(echo $GRAFANA_API_KEY)
  loki:
    host: $(echo $GRAFANA_LOKI_URL)
    basicAuth:
      username: "$(echo $GRAFANA_LOKI_USERNAME)"
      password: $(echo $GRAFANA_API_KEY)
    prometheus:
      external:
        url: $(echo $GRAFANA_METRICS_URL)/api/prom
grafana-agent:
  crds:
    create: false
prometheus-operator-crds:
  enabled: false
prometheus-node-exporter:
  enabled: false
metrics:
  agent:
    enabled: false
  node-exporter:
    enabled: false
  cost:
    enabled: false
opencost:
  enabled: false
logs:
  cluster_events:
    enabled: false
  pod_logs:
    extraRelabelingRules: |-
     rule {
       source_labels = ["namespace"]
       regex         = "kube-(.*)|grafana|gke-(.*)|gmp-(.*)|default"
       action        = "drop"
     }
     rule {
       source_labels = ["pod"]
       regex         = "safe-web-core(.*)|web-(.*)|pingpub(.*)|safe-config-service(.*)|blockscout-frontend(.*)|nginx-blockscout(.*)"
       action        = "drop"
     }      
    extraStageBlocks: |-
     stage.match {
       selector = "{namespace !~ \".*ping-pub.*|.*blockscout-frontend.*|.*aislm.*|.*safe-(config|web).*\", pod !~ \"web.*\"}"

       stage.regex{
         expression = "(?s)(?P<loglevel>(INF|ERR|DEBUG|WARN|CRIT|FATAL|TRACE|EMERG|ALERT|NOTICE)|\\\[(err.*|warn.*|inf.*|crit.*|fat.*|debug|trace|emerg.*|alert|notice)]).*$"
       }
       stage.replace {
         expression = "(.*INF.*|.*inf.*)" 
         source     = "loglevel"
         replace    = "INFO"
       }
       stage.replace {
         expression = "(.*ERR.*|.*err.*)" 
         source     = "loglevel"
         replace    = "ERROR"
       }
       stage.replace {
         expression = "(.*DEBUG.*|.*debug.*)" 
         source     = "loglevel"
         replace    = "DEBUG"
       }
       stage.replace {
         expression = "(.*WARN.*|.*warn.*)" 
         source     = "loglevel"
         replace    = "WARNING"
       }
       stage.replace {
         expression = "(.*CRIT.*|.*crit.*)" 
         source     = "loglevel"
         replace    = "CRITICAL"
       }
       stage.replace {
         expression = "(.*FATAL.*|.*fatal.*)" 
         source     = "loglevel"
         replace    = "FATAL"
       }
       stage.replace {
         expression = "(.*TRACE.*|.*trace.*)" 
         source     = "loglevel"
         replace    = "TRACE"
       }
       stage.replace {
         expression = "(.*EMERG.*|.*emerg.*)" 
         source     = "loglevel"
         replace    = "EMERGENCY"
       }
       stage.replace {
         expression = "(.*NOTICE.*|.*notice.*)" 
         source     = "loglevel"
         replace    = "NOTICE"
       }
       stage.replace {
         expression = "(.*ALERT.*|.*alert.*)" 
         source     = "loglevel"
         replace    = "ALERT"
       }
       stage.labels {
         values = {
           loglevel = "loglevel",
        }
       }
       stage.drop {
         source      = "loglevel"
         expression  = "(DEBUG|TRACE|WARN|INFO|NOTICE)"
       }
     }
EOF
```