sko*_*opp 9 monitoring grafana
我在使用 promtail 解析 json 日志时遇到问题,请问有人可以帮助我吗?我尝试了很多配置,但不解析时间戳或其他标签。
日志条目:
{timestamp=2019-10-25T15:25:41.041-03, level=WARN, thread=http-nio-0.0.0.0-8080-exec-2, mdc={handler=MediaController, ctxCli=127.0.0.1, ctxId=FdD3FVqBAb0}, logger=br.com.brainyit.cdn.vbox.
controller.MediaController, message=[http://localhost:8080/media/sdf],c[500],t[4],l[null], context=default}
Run Code Online (Sandbox Code Playgroud)
promtail-config.yml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://localhost:3100/loki/api/v1/push
scrape_configs:
- job_name: vbox-main
static_configs:
- targets:
- localhost
labels:
job: vbox
appender: main
__path__: /var/log/vbox/main.log
pipeline_stages:
- json:
expressions:
timestamp: timestamp
message: message
context: context
level: level
timestamp:
source: timestamp
format: RFC3339Nano
labels:
context:
level:
output:
source: message
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用 Java SpringBoot 应用程序设置 Promtail(它通过 Logstash logback 编码器生成 JSON 格式的日志文件)并且它有效。
应用程序生成的示例日志行:
{"timestamp":"2020-06-06T01:00:30.840+02:00","version":1,"message":"Started ApiApplication in 1.431 seconds (JVM running for 6.824)","logger_name":"com.github.pnowy.spring.api.ApiApplication","thread_name":"main","level":"INFO","level_value":20000}
Run Code Online (Sandbox Code Playgroud)
prometail 配置:
# Promtail Server Config
server:
http_listen_port: 9080
grpc_listen_port: 0
# Positions
positions:
filename: /tmp/positions.yaml
clients:
- url: http://localhost:3100/loki/api/v1/push
scrape_configs:
- job_name: springboot
pipeline_stages:
- json:
expressions:
level: level
message: message
timestamp: timestamp
logger_name: logger_name
stack_trace: stack_trace
thread_name: thread_name
- labels:
level:
- template:
source: new_key
template: 'logger={{ .logger_name }} threadName={{ .thread_name }} | {{ or .message .stack_trace }}'
- output:
source: new_key
static_configs:
- targets:
- localhost
labels:
job: applogs
__path__: /Users/przemek/tools/promtail/*.log
Run Code Online (Sandbox Code Playgroud)
请注意,输出(日志文本)首先new_key通过 Go 模板进行配置,然后设置为输出源。这logger={{ .logger_name }}有助于识别在 Loki 视图上解析的字段(但这取决于您希望如何为应用程序配置它)。
在这里您会找到有关整个过程的非常好的文档:https://grafana.com/docs/loki/latest/clients/promtail/pipelines/
该示例在 Loki 和 Promtail v1.5.0 版本上运行(更新 2020-04-25:我已将链接更新到当前版本 - 2.2,因为旧链接已停止工作)。
关于时间戳的部分在这里: https: //grafana.com/docs/loki/latest/clients/promtail/stages/timestamp/并附有示例 - 我已经对其进行了测试,也没有注意到任何问题。希望能有所帮助。
JSON配置部分:https://grafana.com/docs/loki/latest/clients/promtail/stages/json/
洛基的结果:
| 归档时间: |
|
| 查看次数: |
18832 次 |
| 最近记录: |