crystal-loki-client

Crystal client library for accessing Grafana Loki APIs.

Supported APIs

Query endpoints

Status/health endpoints

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      loki-client:
        github: spider-gazelle/crystal-loki-client
  2. Run shards install

Usage

require "loki-client"

You can configure the environment using the following variables or configure them via code.

Examples

client = Loki::Client.from_env

# Query endpoints
response = client.query(query: "{job=\"varlogs\"}")
response = client.query_range(query: "{job=\"varlogs\"}", start: 1.hour.ago, end_time: Time.local)
labels = client.list_labels
values = client.list_label_values("job")
series = client.series(matches: ["{app=\"loki\"}"])
stats = client.stats(query: "{job=\"foo\"}")
volume = client.volume(query: "{job=\"foo\"}", start: 1.hour.ago, end_time: Time.local)
patterns = client.patterns(query: "{app=\"loki\"}", start: 1.hour.ago, end_time: Time.local)
fields = client.detected_fields(query: "{app=\"myapp\"}", start: 1.hour.ago, end_time: Time.local)
formatted = client.format_query("{foo= \"bar\"}")
info = client.buildinfo

# Tail via WebSocket
ws = client.tail(query: "{job=\"varlogs\"}")
client.tail(query: "{job=\"varlogs\"}") { |msg| pp msg }

# Status/health endpoints
ready = client.ready?
prometheus_text = client.metrics
config = client.get_config
config_diffs = client.get_config(mode: "diffs")
services = client.services
level = client.log_level

Development

Contributing

  1. Fork it (https://github.com/spider-gazelle/crystal-loki-client/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors