Loki
배포 Mode
- Monolithic
- 모든 컴포넌트를 하나의 인스턴스에 배포
- 하루에 100GB 정도의 읽기/쓰기가 있는 환경에서 사용 가능
- Simple scalable
- 읽기 컴포넌트들과 쓰기 컴포넌트들로 분리하여 배포
- 하루에 100GB ~ 10TB 정도의 읽기/쓰기가 있는 환경에서 사용 가능
- Microservices
- 모든 컴포넌트를 분리하여 배포, 가장 자유도가 높지만 유지보수도 어려움
컴포넌트
- Distributor: 클라이언트에서 들어오는 로그를 검증 후 Ingester로 전달
- Ingester: Distributor로부터 받은 로그를 임시 또는 장기 저장
- Query Frontend: 쿼리를 조정, 쿼리 대기열 관리 등을 수행
- Querier: Ingester 또는 장기 저장소에서 로그를 쿼리
설치
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update grafana \
&& helm search repo grafana/loki-distributed -l | head -n 10
helm show values grafana/loki-distributed \
--version 0.77.0 \
> loki-distributed-values.yaml
loki-distributed-values.yaml
fullnameOverride: "loki"
loki:
# -- Check https://grafana.com/docs/loki/latest/configuration/#schema_config
# for more info on how to configure schemas
schemaConfig:
configs:
- # 인덱스 생성 시작일, 스키마가 변경되면 변경이 시작되는 날짜
from: 2022-10-19
store: boltdb-shipper
# chunks가 저장되는 저장소로 기본값으로 store 값을 씁니다. aws, azure, gcp,
# bigtable, gcs, cassandra, swift or filesystem
object_store: s3
schema: v11
index:
prefix: loki_index_
period: 24h
# -- Check https://grafana.com/docs/loki/latest/configuration/#storage_config
# for more info on how to configure storages
storageConfig:
aws:
s3: s3://<region>/<bucket>
boltdb_shipper:
shared_store: s3
active_index_directory: /var/loki/index
cache_location: /var/loki/cache
cache_ttl: 168h
# -- Structured loki configuration, takes precedence over `loki.config`, `loki.schemaConfig`, `loki.storageConfig`
structuredConfig:
limits_config:
max_entries_limit_per_query: 50000
ingester:
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
memory: 256Mi
distributor:
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
memory: 256Mi
querier:
resources:
requests:
cpu: 100m
memory: 1Gi
limits:
memory: 1Gi
queryFrontend:
resources:
requests:
cpu: 100m
memory: 1Gi
limits:
memory: 1Gi
gateway:
podLabels: {}
resources:
requests:
cpu: 100m
memory: 1Gi
limits:
memory: 1Gi
warning
querier
, queryFrontend
, gateway
는 쿼리되는 로그의 양에 따라 OOMKilled가 발생할 수 있으므로 모니터링을 통해 적절한 값을 설정해야 합니다.
helm template loki grafana/loki-distributed \
--version 0.77.0 \
-n monitoring \
-f loki-distributed-values.yaml \
> loki-distributed.yaml
helm upgrade loki grafana/loki-distributed \
--install \
--version 0.77.0 \
-n monitoring \
--history-max 5 \
-f loki-distributed-values.yaml
helm uninstall -n monitoring loki
Fluent Bit
fluent-bit-values.yaml
env:
- name: LOKI_HOST
value: loki-gateway.monitoring.svc
- name: LOKI_PORT
value: "80"
config:
# indent를 4칸으로 맞춰야 합니다.
outputs: |
[OUTPUT]
name loki
match *
host ${LOKI_HOST}
port ${LOKI_PORT}
labels job=fluent-bit
label_keys $tag
Retry_Limit 5
Fluentd
fluentd-values.yaml
plugins:
- fluent-plugin-grafana-loki
env:
- name: LOKI_HOST
value: loki-gateway.monitoring.svc
- name: LOKI_PORT
value: "80"
fileConfigs:
output-loki.conf: |
<match **>
@type loki
url "http://#{ENV['LOKI_HOST']}:#{ENV['LOKI_PORT']}"
insecure_tls true
line_format json
extra_labels {"job":"fluent-bit"}
<label>
tag $.tag
</label>
<buffer>
flush_at_shutdown true
flush_interval 5s
flush_thread_count 4
retry_max_interval 30s
</buffer>
</match>
Grafana
- Configuration -> Data sources -> Add data source -> Loki
- HTTP
- URL:
http://loki-querier.monitoring.svc:3100
- URL:
- HTTP
- Explore -> Loki -> Add query
- Builder
- Label filters
{job="fluent-bit"}
- Label filters
- Code
- Log browser:
{job="fluent-bit"}
- Log query: https://grafana.com/docs/loki/latest/logql/log_queries/
- LogQL Analyzer: https://grafana.com/docs/loki/latest/logql/analyzer/
- Log browser:
- Builder