Federico Nafria
Federico Nafria

Reputation: 1600

How to use recording rules from Loki

I'm trying to use Loki new Recording Rules without alerting.

What is not clear to me is where would the result of the rule evaluation be available?

Can the ruler be scraped for the metrics values or they have to be pushed to something like Prometheus Pushgateway?

Upvotes: 3

Views: 2699

Answers (3)

paltaa
paltaa

Reputation: 3244

For kubernetes loki helm chart, need to config the rulerConfig block as follows:

  rulerConfig:
    wal:
      enabled: true
      dir: /var/loki/rules-wal
    storage:
      type: local
      local:
        directory: /var/loki/rulestorage
    # Here is where you mount the custom rules from a config map in volumeMounts
    rule_path: "/var/loki/rules-temp"
    ring:
      kvstore:
        store: inmemory
    alertmanager_url: http://vmalertmanager-vm-victoria-metrics-k8s-stack:9093
    enable_alertmanager_v2: true
    # This block configures remote_write, in my case im using victoria metrics which is compatible with Prometheus
    remote_write:
      enabled: true
      clients:
        vmsingle:
          name: vmsingle
          url: http://vmsingle-vm-victoria-metrics-k8s-stack:8429/api/v1/write

Upvotes: 1

Federico Nafria
Federico Nafria

Reputation: 1600

As Marcelo mentioned in his answer the metrics have to be pushed.

This is a configuration example to push to prometheus

ruler:
  storage:
    type: local
    local:
      directory: /etc/loki/rules
  ring:
    kvstore:
      store: memberlist
  remote_write:
    enabled: true
    client:
      url: http://<prometheus_domain>:9090/api/v1/write

Upvotes: 2

Accordingly, to the Loki documentation, metrics must be pushed to Prometheus, Cortex, or Thanos:

With recording rules, you can run these metric queries continually on an interval and have the resulting metrics written to a Prometheus-compatible remote-write endpoint. They produce Prometheus metrics from log entries.

At the time of writing, these are the compatible backends that support this:

  • Prometheus (>=v2.25.0)
  • Cortex
  • Thanos (Receiver)

Upvotes: 2

Related Questions