grafana/loki

GitHub: grafana/loki

受Prometheus启发的水平可扩展日志聚合系统,通过仅索引标签元数据实现低成本高效率的日志存储与查询。

Stars: 27803 | Forks: 3948

Loki Logo

Check Go Report Card Slack [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/loki.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:loki) # Loki:就像 Prometheus,但是用于日志。 Loki 是一个受 [Prometheus](https://prometheus.io/) 启发的水平可扩展、高可用、多租户日志聚合系统。 它的设计非常具有成本效益且易于操作。 它不索引日志的内容,而是索引每个日志流的一组标签。 与其他日志聚合系统相比,Loki: - 不对日志进行全文索引。通过存储压缩的、非结构化的日志并且仅索引元数据,Loki 操作更简单,运行成本更低。 - 使用您已经在 Prometheus 中使用的相同标签来索引和分组日志流,使您能够使用已在 Prometheus 中使用的相同标签在指标和日志之间无缝切换。 - 特别适合存储 [Kubernetes](https://kubernetes.io/) Pod 日志。诸如 Pod 标签之类的元数据会被自动抓取和索引。 - 在 Grafana 中有原生支持(需要 Grafana v6.0)。 基于 Loki 的日志堆栈由 3 个组件组成: - [Alloy](https://github.com/grafana/alloy) 是代理,负责收集日志并将其发送给 Loki。 - [Loki](https://github.com/grafana/loki) 是主服务,负责存储日志和处理查询。 - [Grafana](https://github.com/grafana/grafana) 用于查询和显示日志。 **请注意,Alloy 已在堆栈中取代了 Promtail,因为 Promtail 已被视为功能完整,未来的日志收集开发将在 [Grafana Alloy](https://github.com/grafana/alloy) 中进行。** Loki 就像 Prometheus,但是用于日志:我们更倾向于基于多维标签的索引方法,并希望有一个无依赖、易于操作的单二进制系统。 Loki 与 Prometheus 的不同之处在于它专注于日志而不是指标,并通过推送而不是拉取来交付日志。 ## 入门指南 * [安装 Loki](https://grafana.com/docs/loki/latest/installation/) * [安装 Alloy](https://grafana.com/docs/loki/latest/send-data/alloy/) * [入门](https://grafana.com/docs/loki/latest/get-started/) ### ⚠️ Helm Chart 迁移 自 2026 年 3 月 16 日起,Grafana Loki Helm chart 将被分叉到新仓库 [grafana-community/helm-charts](https://github.com/grafana-community/helm-charts)。Loki 仓库中的 chart 将仅继续为 GEL 用户维护。详情请参见 [#20705](https://github.com/grafana/loki/issues/20705)。 ## 升级 * [升级 Loki](https://grafana.com/docs/loki/latest/upgrading/) ## 文档 * [最新版本](https://grafana.com/docs/loki/latest/) * [即将发布的版本](https://grafana.com/docs/loki/next/),位于主分支的顶端 常用部分: - [API 文档](https://grafana.com/docs/loki/latest/api/) 用于将日志导入 Loki。 - [标签](https://grafana.com/docs/loki/latest/getting-started/labels/) - [运维](https://grafana.com/docs/loki/latest/operations/) - [Promtail](https://grafana.com/docs/loki/latest/clients/promtail/) 是一个代理,用于跟踪日志文件并将其推送到 Loki。 - [Pipelines](https://grafana.com/docs/loki/latest/clients/promtail/pipelines/) 详细介绍了日志处理管道。 - [Docker Driver Client](https://grafana.com/docs/loki/latest/clients/docker-driver/) 是一个 Docker 插件,用于将日志从 Docker 容器直接发送到 Loki。 - [LogCLI](https://grafana.com/docs/loki/latest/query/logcli/) 提供了一个用于查询日志的命令行界面。 - [Loki Canary](https://grafana.com/docs/loki/latest/operations/loki-canary/) 监控您的 Loki 安装是否存在日志丢失。 - [故障排除](https://grafana.com/docs/loki/latest/operations/troubleshooting/) 提供了处理错误信息的帮助。 - [Grafana 中的 Loki](https://grafana.com/docs/loki/latest/operations/grafana/) 描述了如何在 Grafana 中设置 Loki 数据源。 ## 获取帮助 如果您对 Loki 有任何问题或反馈: - 在 Grafana Labs 社区论坛中搜索关于 Loki 的现有主题:[https://community.grafana.com](https://community.grafana.com/c/grafana-loki/) - 在 Loki Slack 频道上提问。要邀请自己加入 Grafana Slack,请访问 [https://slack.grafana.com/](https://slack.grafana.com/) 并加入 #loki 频道。 - 针对错误、问题和功能建议[提交 Issue](https://github.com/grafana/loki/issues/new)。 - 发送电子邮件至 [lokiproject@googlegroups.com](mailto:lokiproject@googlegroups.com),或使用 [网页界面](https://groups.google.com/forum/#!forum/lokiproject)。 - UI 问题应直接在 [Grafana](https://github.com/grafana/grafana/issues/new) 中提交。 我们随时欢迎您的反馈。 ## 延伸阅读 - Loki 最初的[设计文档](https://docs.google.com/document/d/11tjK_lvp1-SVsFZjgOTr1vV3-q6vBAsZYIQ5ZeYBkyM/view)是讨论其动机和设计决策的好资料。 - Callum Styan 在 2019 年 3 月 DevOpsDays Vancouver 上的演讲“[Grafana Loki: Log Aggregation for Incident Investigations][devopsdays19-talk]”。 - Grafana Labs 博客文章“[How We Designed Loki to Work Easily Both as Microservices and as Monoliths][architecture-blog]”。 - Tom Wilkie 在 2019 年初 CNCF Paris/FOSDEM 上的演讲“[Grafana Loki: like Prometheus, but for logs][fosdem19-talk]”([幻灯片][fosdem19-slides],[视频][fosdem19-video])。 - David Kaltschmidt 在 KubeCon 2018 上的演讲“[On the OSS Path to Full Observability with Grafana][kccna18-event]”([幻灯片][kccna18-slides],[视频][kccna18-video]),介绍了 Loki 如何融入云原生环境。 - Goutham Veeramachaneni 的博客文章“[Loki: Prometheus-inspired, open source logging for cloud natives](https://grafana.com/blog/2018/12/12/loki-prometheus-inspired-open-source-logging-for-cloud-natives/)”,介绍了 Loki 架构的细节。 - David Kaltschmidt 的博客文章“[Closer look at Grafana's user interface for Loki](https://grafana.com/blog/2019/01/02/closer-look-at-grafanas-user-interface-for-loki/)”,介绍了投入日志用户界面的想法。 ## 贡献 请参考 [CONTRIBUTING.md](CONTRIBUTING.md) ### 从源代码构建 可以使用以下命令在单主机、无依赖模式下运行 Loki。 您需要安装最新版本的 [Go](https://go.dev/),我们建议使用我们的 [Makefile](https://github.com/grafana/loki/blob/main/Makefile) 中指定的版本。 ``` # 检出源代码 $ git clone https://github.com/grafana/loki $ cd loki # 构建 binary $ go build ./cmd/loki # 运行 executable $ ./loki -config.file=./cmd/loki/loki-local-config.yaml ``` 或者,在 Unix 系统上,您可以使用 `make` 来构建二进制文件,这会向 `go build` 命令添加额外的参数。 ``` # 构建 binary $ make loki # 运行 executable $ ./cmd/loki/loki -config.file=./cmd/loki/loki-local-config.yaml ``` 要在本地运行多个 Loki 租户,请确保 auth_enabled 设置为 true,并提供包含任何租户特定覆盖的运行时配置。 ``` # 构建 binary $ make loki # 运行 executable ./loki -config.file=./cmd/loki/loki-local-multi-tenant-config.yaml -runtime-config.file=./cmd/loki/loki-overrides.yaml ``` 要在非 Linux 平台上构建 Promtail,请使用以下命令: ``` $ go build ./clients/cmd/promtail ``` 在 Linux 上,如果启用了 Journal 支持, Promtail 需要安装 systemd 头文件。 要启用 Journal 支持,应传递 go build tag 标志 `promtail_journal_enabled` 在 Ubuntu 上启用 Journal 支持,请使用以下命令运行: ``` $ sudo apt install -y libsystemd-dev $ go build --tags=promtail_journal_enabled ./clients/cmd/promtail ``` 在 CentOS 上启用 Journal 支持,请使用以下命令运行: ``` $ sudo yum install -y systemd-devel $ go build --tags=promtail_journal_enabled ./clients/cmd/promtail ``` 否则,要在不支持 Journal 的情况下构建 Promtail,请在禁用 CGO 的情况下运行 `go build`: ``` $ CGO_ENABLED=0 go build ./clients/cmd/promtail ``` ## 使用者 请参阅 [ADOPTERS.md](ADOPTERS.md) 了解目前正在使用 Loki 的一些组织。 如果您想将您的组织添加到列表中,请打开一个 PR 将其添加到列表中。 ## 许可证 Grafana Loki 根据 [AGPL-3.0-only](LICENSE) 发布。有关 Apache-2.0 例外情况,请参阅 [LICENSING.md](LICENSING.md)。
标签:API集成, DNS解析, Golang, Grafana Loki, LogQL, OISF, SRE, 偏差过滤, 元数据索引, 分布式系统, 可观测性, 后端开发, 响应大小分析, 多引擎聚合, 子域名突变, 安全编程, 对象存储, 开源项目, 日志存储, 日志审计, 日志查询, 日志管理, 日志聚合, 监控系统, 请求拦截, 运维工具