无法在 Loki 中获取日志记录
Posted
技术标签:
【中文标题】无法在 Loki 中获取日志记录【英文标题】:Cannot get log records in Loki 【发布时间】:2021-03-22 02:54:10 【问题描述】:我根据this doc创建了ECS集群
我使用的是 CloudFormation 模板:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
# ...
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Sub "$Application-$Env"
ExecutionRoleArn:
Fn::ImportValue:
!Sub "$Env-TaskExecutionRole"
Cpu: 256
Memory: 256
ContainerDefinitions:
- Name: nextjs
Image: nextjs
DependsOn:
- containerName: log_router
condition: START
Essential: true
LogConfiguration:
LogDriver: awsfirelens
Options:
Name: loki
Url: "http://loki.xxx.com/loki/api/v1/push"
Labels: "job=\"firelens\""
RemoveKeys: "container_id,ecs_task_arn"
LabelKeys: "container_name,ecs_task_definition,source,ecs_cluster"
LineFormat: key_value
Links:
- log_router
- Name: nginx
Image: nginx
DependsOn:
- containerName: nextjs
condition: START
Essential: true
PortMappings:
- ContainerPort: 80
LogConfiguration:
LogDriver: awsfirelens
Options:
Name: loki
Url: "http://loki.xxx.com/loki/api/v1/push"
Labels: "job=\"firelens\""
RemoveKeys: "container_id,ecs_task_arn"
LabelKeys: "container_name,ecs_task_definition,source,ecs_cluster"
LineFormat: key_value
Links:
- nextjs
- log_router
- Name: log_router
Image: grafana/fluent-bit-plugin-loki:latest
Essential: true
FirelensConfiguration:
Type: fluentbit
Options:
enable-ecs-log-metadata: true
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: firelens-container
awslogs-region: us-east-1
awslogs-create-group: true
awslogs-stream-prefix: firelens
memoryReservation: 50
所有三个容器都已启动并运行,但我在 CloudWatch 中收到此错误消息:
无法加载输出插件“loki”
截图(抱歉,当我将它添加为图像时失败):https://imgur.com/qnE0Cjd
Grafana Loki 是空的
错在哪里?会不会和DependsOn
或Links
有关?
【问题讨论】:
【参考方案1】:为同样的问题而苦苦挣扎。事实证明,文档是错误的。该插件的名称是“grafana-loki”,而不仅仅是文档中所述的“loki”。也许这改变了一段时间,文档已经过时了。
"logConfiguration":
"logDriver": "awsfirelens",
"options":
"Name": "grafana-loki",
"Url": "https://[...]/loki/api/v1/push",
"Labels": "job=\"firelens\"",
"RemoveKeys": "container_id,ecs_task_arn",
"LabelKeys": "container_name,ecs_task_definition,source,ecs_cluster",
"LineFormat": "key_value"
,
【讨论】:
如果您密切关注文档,您会看到 logConfiguration 节被转换为 Fluentbit 配置,而该配置又使用“grafana-loki”作为名称,而不仅仅是“loki”:@ 987654321@以上是关于无法在 Loki 中获取日志记录的主要内容,如果未能解决你的问题,请参考以下文章