说明
本文通过安装 docker loki plugin 直接采集docker容器日志,并推送至loki。官方文档
插件安装
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
[root@data1 ~]
ID NAME DESCRIPTION ENABLED
744b79d5d1a9 loki:latest Loki Logging Driver true
插件升级
docker plugin disable loki --force
docker plugin upgrade loki grafana/loki-docker-driver:latest --grant-all-permissions
docker plugin enable loki
systemctl restart docker
插件卸载
docker plugin disable loki --force
docker plugin rm loki
使用
单独为一个容器设置日志驱动
docker run --log-driver=loki \
--log-opt loki-url="http://IP:3100/loki/api/v1/push" \
--log-opt loki-retries=5 \
--log-opt loki-batch-size=400 \
--log-opt max-size=50m \
--log-opt max-file=3 \
grafana/grafana
为所有的容器设置默认参数
编辑/etc/docker/daemon.json
文件(如果没有就新建).
{
"debug" : true,
"log-driver": "loki",
"log-opts": {
"loki-url": "http://IP:3100/loki/api/v1/push",
"loki-batch-size": "400",
"loki-retries": 5,
"max-size": "50m",
"max-file": "10"
}
}
更多如docker-compose
的用法参考官网文档.
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9095
ingester:
chunk_idle_period: 3m
chunk_block_size: 262144
chunk_retain_period: 1m
max_transfer_retries: 0
lifecycler:
ring:
kvstore:
store: inmemory
replication_factor: 1
limits_config:
reject_old_samples: true
reject_old_samples_max_age: 168h
common:
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
instance_addr: 127.0.0.1
kvstore:
store: inmemory
storage_config:
boltdb_shipper:
active_index_directory: /tmp/loki/boltdb-shipper-active
cache_location: /tmp/loki/boltdb-shipper-cache
cache_ttl: 24h
shared_store: filesystem
filesystem:
directory: /tmp/loki/chunks
chunk_store_config:
max_look_back_period: 672h
table_manager:
retention_deletes_enabled: true
retention_period: 672h
compactor:
working_directory: /tmp/loki/boltdb-shipper-compactor
shared_store: filesystem
retention_enabled: true
retention_delete_delay: 2h
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 200
querier:
query_timeout: 2m
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
analytics:
reporting_enabled: false