参考
官网
入门教程
动态标签
日志改造
配置
安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| helm repo add grafana https://grafana.github.io/helm-charts
helm upgrade --install loki \ --namespace=loki-stack grafana/loki-stack --create-namespace \ --set grafana.enabled=true \ --set grafana.image.tag="9.3.2"
vi pvc-values.yaml loki: persistence: enabled: true size: 500Gi
helm upgrade --install loki --namespace=loki-stack grafana/loki-stack --create-namespace \ --set grafana.enabled=true \ --set grafana.image.tag="9.3.2" \ -f pvc-values.yaml
kubectl get secret --namespace loki-stack loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo blwUDUjqhl997xofek3dp06w8Xmc4ZhvwucQnMXw
kubectl port-forward --namespace loki-stack service/loki-grafana 3000:80 open http://localhost:3000 open http://10.193.36.41:30016
kubectl apply -f https://ghproxy.com/https://raw.githubusercontent.com/lyzhang1999/kubernetes-example/main/loki/deployment.yaml kubectl logs -l app=log-example
|
Query
Grafana 9.X支持图形化查询,TIDB自带的Grafana版本为7.5.11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| {app="log-example"} |= ``
{app="log-example"} | logfmt | status = `200`
{app="log-example"} | json | status = `200`
{app="log-example"} |= `status=` | logfmt | status != `200`
{app="log-example"} |= `status=` | logfmt | status >= 400 | status <= 500
{app="log-example"} |= `status=` | logfmt | duration > 3us
{app="log-example"} |= `status=` | logfmt | line_format `{{ .duration }} {{ .uri }}`
sum by (pod) (count_over_time({app="log-example"} |= `status=` | logfmt | duration > 4us [10s]))
sum by (status) ( count_over_time({app="log-example"} |= `status=` | logfmt | __error__=""[1m]) )
{app="dubhe-metadata"} | json | level = `INFO`
|
JSON日志改造
pom.xml
1 2 3 4 5
| <dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>7.0.1</version> </dependency>
|
logback-spring.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <providers> <pattern> <pattern> { "timestamp": "%date{\"yyyy-MM-dd HH:mm:ss.SSS\"}", "level": "%level", "pid": "${PID:-}", "thread": "%thread", "class": "%logger", "method": "%method", "line": "%line", "message": "%message" } </pattern> </pattern> </providers> </encoder> </appender>
|