prometheus/prometheus

GitHub: prometheus/prometheus

一款开源的系统监控与时间序列数据库,专为云原生环境下的指标收集、多维数据查询与告警而设计。

Stars: 63701 | Forks: 10348

Prometheus
Prometheus

访问 prometheus.io 获取完整的文档、 示例和指南。

[![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/3cbc52542b195914.svg)](https://github.com/prometheus/prometheus/actions/workflows/ci.yml) [![Docker Repository on Quay](https://quay.io/repository/prometheus/prometheus/status)][quay] [![Docker Pulls](https://img.shields.io/docker/pulls/prom/prometheus.svg?maxAge=604800)][hub] [![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/prometheus)](https://goreportcard.com/report/github.com/prometheus/prometheus) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/486/badge)](https://bestpractices.coreinfrastructure.org/projects/486) [![govluncheck](https://github.com/prometheus/prometheus/actions/workflows/govluncheck.yml/badge.svg?event=schedule)](https://github.com/prometheus/prometheus/actions/workflows/govluncheck.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/prometheus/prometheus/badge)](https://securityscorecards.dev/viewer/?uri=github.com/prometheus/prometheus) [![CLOMonitor](https://img.shields.io/endpoint?url=https://clomonitor.io/api/projects/cncf/prometheus/badge)](https://clomonitor.io/projects/cncf/prometheus) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/prometheus.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:prometheus)
Prometheus 是一个 [Cloud Native Computing Foundation](https://cncf.io/) 项目,它是一个系统和服务监控系统。它按设定的时间间隔从已配置的目标收集指标,评估规则表达式,展示结果,并能在观察到指定条件时触发警报。 Prometheus 区别于其他指标和监控系统的特性包括: * **多维**数据模型(由指标名称和键/值维度集合定义的时间序列) * PromQL,一种**强大且灵活的查询语言**,可充分利用这种维度特性 * 不依赖分布式存储;**单服务器节点是自治的** * 用于时间序列收集的 HTTP **拉取模型** * 通过中间网关支持批处理作业的**推送时间序列** * 通过**服务发现**或**静态配置**发现目标 * 多种模式的**图表和仪表盘支持** * 支持分层和水平的**联邦** ## 架构概览 ![Architecture overview](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/2277803528195927.svg) ## 安装 有多种安装 Prometheus 的方式。 ### 预编译二进制文件 已发布版本的预编译二进制文件可在 [prometheus.io](https://prometheus.io) 的 [*下载*部分](https://prometheus.io/download/) 获取。使用最新的生产环境发布版本二进制文件是安装 Prometheus 的推荐方式。 详情请参阅文档中的 [安装](https://prometheus.io/docs/introduction/install/)章节。 ### Docker 镜像 Docker 镜像可在 [Quay.io](https://quay.io/repository/prometheus/prometheus) 或 [Docker Hub](https://hub.docker.com/r/prom/prometheus/) 上获取。 你可以使用以下命令启动一个 Prometheus 容器来进行试用: ``` docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus ``` Prometheus 现在可以通过 访问。 ### 从源码构建 要从源代码构建 Prometheus,你需要: * Go:[go.mod](./go.mod) 中指定的版本或更高版本。 * NodeJS:[.nvmrc](./web/ui/.nvmrc) 中指定的版本或更高版本。 * npm:版本 10 或更高(使用 `npm --version` 检查,详见[这里](https://www.npmjs.com/))。 首先克隆仓库: ``` git clone https://github.com/prometheus/prometheus.git cd prometheus ``` 你可以使用 `go` 工具将 `prometheus` 和 `promtool` 二进制文件构建并安装到你的 `GOPATH` 中: ``` go install github.com/prometheus/prometheus/cmd/... prometheus --config.file=your_config.yml ``` *但是*,当使用 `go install` 构建 Prometheus 时,Prometheus 会期望能够从 `web/ui/static` 下的本地文件系统目录中读取其 Web 资源。为了能够找到这些资源,你必须从克隆仓库的根目录运行 Prometheus。还需要注意的是,除非已使用 `make assets` 或 `make build` 显式构建,否则该目录不包含 React UI。 有关上述配置文件的示例可以在[这里](https://github.com/prometheus/prometheus/blob/main/documentation/examples/prometheus.yml)找到。 你也可以使用 `make build` 进行构建,这会将 Web 资产编译进去,从而使 Prometheus 可以在任何地方运行: ``` make build ./prometheus --config.file=your_config.yml ``` Makefile 提供了多个目标: * *build*:构建 `prometheus` 和 `promtool` 二进制文件(包括构建和编译 Web 资产) * *test*:运行测试 * *test-short*:运行短测试 * *format*:格式化源代码 * *vet*:检查源代码中的常见错误 * *assets*:构建 React UI ### 服务发现插件 Prometheus 附带了许多服务发现插件。你可以使用 Go 构建标签自定义在构建中包含哪些服务发现。 要在使用 `make build` 构建时排除服务发现,请将所需的标签添加到 `.promu.yml` 文件中的 `build.tags.all` 下: ``` build: tags: all: - netgo - builtinassets - remove_all_sd # Exclude all optional SDs - enable_kubernetes_sd # Re-enable only kubernetes ``` 然后像往常一样运行 `make build`。或者,当直接使用 `go build` 时: ``` go build -tags "remove_all_sd,enable_kubernetes_sd" ./cmd/prometheus ``` 可用的构建标签: * `remove_all_sd` - 排除所有可选的服务发现(保留 file_sd、static_sd 和 http_sd) * `enable__sd` - 在使用 `remove_all_sd` 时重新启用特定的 SD 如果你添加了非官方(out-of-tree)插件(我们目前不推荐这样做),可能需要额外的步骤来调整 `go.mod` 和 `go.sum` 文件。与往常一样,加载第三方代码时要格外小心。 ### 构建 Docker 镜像 你可以使用以下命令在本地构建 docker 镜像: ``` make promu promu crossbuild -p linux/amd64 make npm_licenses make common-docker-amd64 ``` `make docker` 目标仅用于我们的 CI 系统,在本地运行时不会生成完全可用的镜像。 ## 将 Prometheus 作为 Go 库使用 在 Prometheus 项目中,诸如 [prometheus/common](https://github.com/prometheus/common) 和 [prometheus/client-golang](https://github.com/prometheus/client-golang) 这样的仓库被设计为可重用的库。 [prometheus/prometheus](https://github.com/prometheus/prometheus) 仓库构建了一个独立的程序,并非设计为库来使用。我们知道人们确实将其部分内容当作库来使用,我们也没有刻意设置障碍,但我们希望你明白,我们并未投入精力使其作为库能完美运行。例如,你可能会遇到仅在作为库使用时才会出现的错误。 ### 远程 Write 我们在 [buf.build](https://buf.build/prometheus/prometheus/assets) 独立发布了我们的 Remote Write protobuf。 你可以将其作为库使用: ``` go get buf.build/gen/go/prometheus/prometheus/protocolbuffers/go@latest ``` 这是实验性的。 ### Prometheus 代码库 为了符合 [go mod](https://go.dev/ref/mod#versions) 规则,Prometheus 的发布版本号与 Go 模块的发布版本号并不完全匹配。 对于 Prometheus v3.y.z 版本,我们发布了等效的 v0.3y.z 标签。v0.3y.z 中的 y 总是填充为两位数,如果需要会带有前导零。 因此,想要将 Prometheus v3.0.0 作为库使用的用户可以这样做: ``` go get github.com/prometheus/prometheus@v0.300.0 ``` 对于 Prometheus v2.y.z 版本,我们发布了等效的 v0.y.z 标签。 因此,想要将 Prometheus v2.35.0 作为库使用的用户可以这样做: ``` go get github.com/prometheus/prometheus@v0.35.0 ``` 这种解决方案清楚地表明,我们可能会在面向用户的小版本发布之间破坏我们的内部 Go API,正如[在主版本为零时允许进行破坏性更改](https://semver.org/#spec-item-4)中所规定的那样。 ## React UI 开发 有关基于 React 的 UI 的构建、运行和开发的更多信息,请参阅 React 应用的 [README.md](web/ui/README.md)。 ## 更多信息 * Godoc 文档可通过 [pkg.go.dev](https://pkg.go.dev/github.com/prometheus/prometheus) 获取。由于 Go Modules 的特殊性,v3.y.z 将显示为 v0.3y.z(v0.3y.z 中的 y 总是填充为两位数,如果需要会带有前导零),而 v2.y.z 将显示为 v0.y.z。 * 请参阅 [社区页面](https://prometheus.io/community),了解如何通过各种沟通渠道联系 Prometheus 开发人员和用户。 ## 贡献 请参阅 [CONTRIBUTING.md](https://github.com/prometheus/prometheus/blob/main/CONTRIBUTING.md) ## 许可证 Apache License 2.0,请参阅 [LICENSE](https://github.com/prometheus/prometheus/blob/main/LICENSE)。
标签:APM, CNCF, DNS解析, Docker, EVTX分析, Go语言, Grafana, Kubernetes监控, PromQL, SRE, TSDB, web渗透, 代理支持, 偏差过滤, 告警, 多引擎聚合, 安全防御评估, 开源项目, 指标收集, 数据库, 日志审计, 时序数据, 时间序列数据库, 服务监控, 监控系统, 程序破解, 站点可靠性, 请求拦截, 运维监控