Это старая версия документа!
loki
Настройка
auth_enabled: false server: http_listen_port: 3100 common: instance_addr: 127.0.0.1 path_prefix: /loki storage: filesystem: chunks_directory: /loki/chunks rules_directory: /loki/rules replication_factor: 1 ring: kvstore: store: inmemory schema_config: configs: - from: 2020-10-24 store: tsdb object_store: filesystem schema: v13 index: prefix: index_ period: 24h ruler: alertmanager_url: http://localhost:9093 limits_config: retention_period: 720h reject_old_samples: true reject_old_samples_max_age: 720h allow_structured_metadata: true max_query_length: 721h ingester: lifecycler: ring: kvstore: store: inmemory replication_factor: 1 final_sleep: 0s chunk_idle_period: 1h max_chunk_age: 1h chunk_target_size: 1048576 chunk_retain_period: 30s table_manager: retention_deletes_enabled: true retention_period: 720h
Индексы
- TSDB — это высокопроизводительные базы данных, которые позволяют запрашивать стримы и чанки по их лейблам. Однако они неизменяемы (immutable) и должны быть собраны до того, как к ним можно будет обращаться.
Loki фильтры
Взять любые значения и применить к ним фильтр json:
{stream=~".+", job=~".*", instance=~".*", cluster=""} | json
эквивалент:
{stream=~".+"} | json
В распарсенном json поискать значения парочки ключей:
{stream=~".+"} | json | http_host=`site.ru` | status > 299
Вот так я ищу ошибку в monolog:
{stream=~".+"} | json | message=`error message`
Найти точно по левой части и что-угодно справа:
request_uri=~"^/foo(.*)"
Найти по части совпадения строки:
{stream=~".+"}|~ "(.*)Find and save image problems(.*)"
Тоже самое, но сначала распарсить json:
{stream=~".+"} | json | message=~`(.*)Uncaught PHP Exception Doctrine(.*)`
OR условие:
... | json | scheme=`https` | status=~"301|302" [$__auto])))
Отрицание:
http_referer !~`(http|https)://yapro.ru(.*)`
Сформировать строку из разных значений:
| line_format "➡️ {{.request_method}} {{.request_uri}} with HTTP status: {{.status}} "
sum(count_over_time({app="servicefoundry-server"}[24h]))
{namespace="truefoundry", app!="grafana"} |= "[UNIQUE-STATIC-LOG] ID=abc123 XYZ"
{app="servicefoundry-server"} |= ":3000"
{namespace="truefoundry"} |= "non-existent log line"
{namespace="truefoundry"} |= "non-existent log line"
{container_name="nextcloud-cron-1"} | json | line_format `{{.log_raw}}`
{container_name="nextcloud-cron-1"} | json | line_format `{{.level}}`