Skip to main content

A Python client interacting with Grafana Loki.

Project description

loki-client

A Python client interacting with Grafana Loki.

Quickstart

Install:

pip install loki-client

Usage:

# example.py
from loki_client import LokiClient
from loki_client import SUPPORTED_DIRECTION


loki_url = 'http://localhost:3100'
loki_client = LokiClient(url=loki_url, disable_ssl=True)

# 1 test ready()
loki_ready = loki_client.ready()
if not loki_ready:
    print('Loki is not ready.')
    exit(1)

# 2 test query_range_with_context()
query = r'{host="ubuntu"}|~"error"'
result = loki_client.query_range_with_context(query=query, context_before=5, context_after=3)
if result[0]:
    print(result)

# 3 test post()
label_dic = {'host': 'windows', 'env': 'test'}
logs_lst = ['This is line 1', 'This is line 2', 'This is line 3', 'This is line 4']
result = loki_client.post(label_dic, logs_lst)
if not result[0]:
    print(result[1])

# 4 test labels()
result = loki_client.labels()
print(result)

# 5 test query_range()
query = r'{host="ubuntu"}|~"error"'
result = loki_client.query_range(query, direction=SUPPORTED_DIRECTION[1], limit=10)
print(result)

if result[0]:
    print(result[1]['status'])
    print(result[1]['data']['resultType'])

# 6 test query()
result = loki_client.query(query, direction=SUPPORTED_DIRECTION[1], limit=10)
print(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loki-client-0.0.2.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

loki_client-0.0.2-py3-none-any.whl (2.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page