prometheus / prometheus
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Prometheus Visit prometheus.io for the full documentation, examples and guides. Prometheus, a Cloud Native Computing Foundation project, is a systems and service monitoring system. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts when specified conditions are observed.
请访问 prometheus.io 获取完整的文档、示例和指南。Prometheus 是云原生计算基金会(CNCF)的一个项目,是一个系统和服务监控系统。它按设定的时间间隔从配置的目标收集指标,评估规则表达式,显示结果,并能在观察到指定条件时触发警报。
The features that distinguish Prometheus from other metrics and monitoring systems are: A multi-dimensional data model (time series defined by metric name and set of key/value dimensions) PromQL, a powerful and flexible query language to leverage this dimensionality No dependency on distributed storage; single server nodes are autonomous An HTTP pull model for time series collection Pushing time series is supported via an intermediary gateway for batch jobs Targets are discovered via service discovery or static configuration Multiple modes of graphing and dashboarding support Support for hierarchical and horizontal federation Architecture overview.
使 Prometheus 有别于其他指标和监控系统的特性包括:多维数据模型(由指标名称和一组键/值维度定义的时间序列);PromQL,一种强大且灵活的查询语言,用于利用这种维度;不依赖分布式存储;单服务器节点是自治的;用于时间序列收集的 HTTP 拉取模型;通过中间网关支持批量作业的时间序列推送;通过服务发现或静态配置发现目标;多种图形和仪表板模式支持;支持分层和水平联邦;架构概述。
Install There are various ways to install Prometheus. Precompiled binaries Precompiled binaries for released versions are available in the download section on prometheus.io. Using the latest production release binary is the recommended way to install Prometheus. See the Installing chapter in the documentation for all the details.
安装:有多种安装 Prometheus 的方法。预编译二进制文件:发布版本的预编译二进制文件可在 prometheus.io 的下载部分获取。使用最新的生产发布二进制文件是安装 Prometheus 的推荐方式。有关所有详细信息,请参阅文档中的“安装”章节。
Docker images Docker images are available on Quay.io or Docker Hub. You can launch a Prometheus container for trying it out with docker run —name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus Prometheus will now be reachable at http://localhost:9090/.
Docker 镜像:Docker 镜像可在 Quay.io 或 Docker Hub 上获取。你可以通过以下命令启动一个 Prometheus 容器进行试用:docker run —name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus。现在可以通过 http://localhost:9090/ 访问 Prometheus。
Building from source To build Prometheus from source code, you need: Go: Version specified in go.mod or greater. NodeJS: Version specified in .nvmrc or greater. npm: Version 10 or greater (check with npm —version and here). Start by cloning the repository: git clone https://github.com/prometheus/prometheus.git cd prometheus.
从源代码构建:要从源代码构建 Prometheus,你需要:Go:go.mod 中指定的版本或更高版本。NodeJS:.nvmrc 中指定的版本或更高版本。npm:10 或更高版本(通过 npm —version 和此处检查)。首先克隆存储库:git clone https://github.com/prometheus/prometheus.git cd prometheus。
You can use the go tool to build and install the prometheus and promtool binaries into your GOPATH: go install github.com/prometheus/prometheus/cmd/… prometheus —config.file=your_config.yml However, when using go install to build Prometheus, Prometheus will expect to be able to read its web assets from local filesystem directories under web/ui/static. In order for these assets to be found, you will have to run Prometheus from the root of the cloned repository.
你可以使用 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。
Note also that this directory does not include the React UI unless it has been built explicitly using make assets or make build. An example of the above configuration file can be found here. You can also build using make build, which will compile in the web assets so that Prometheus can be run from anywhere: make build ./prometheus —config.file=your_config.yml.
另请注意,除非使用 make assets 或 make build 显式构建,否则此目录不包含 React UI。上述配置文件的示例可以在此处找到。你也可以使用 make build 进行构建,它会将 Web 资源编译进去,以便可以在任何地方运行 Prometheus:make build ./prometheus —config.file=your_config.yml。
The Makefile provides several targets: build: build the prometheus and promtool binaries (includes building and compiling in web assets) test: run the tests test-short: run the short tests format: format the source code vet: check the source code for common errors assets: build the React UI.
Makefile 提供了几个目标:build:构建 prometheus 和 promtool 二进制文件(包括构建和编译 Web 资源);test:运行测试;test-short:运行简短测试;format:格式化源代码;vet:检查源代码中的常见错误;assets:构建 React UI。
Service discovery plugins Prometheus is bundled with many service discovery plugins. You can customize which service discoveries are included in your build using Go build tags. To exclude service discoveries when building with make build, add the desired tags to the .promu.yml file under build.tags.all.
服务发现插件:Prometheus 捆绑了许多服务发现插件。你可以使用 Go 构建标签自定义构建中包含哪些服务发现。要在使用 make build 构建时排除服务发现,请将所需的标签添加到 .promu.yml 文件中的 build.tags.all 下。
Then run make build as usual. Alternatively, when using go build directly: go build -tags “remove_all_sd,enable_kubernetes_sd” ./cmd/prometheus Available build tags: remove_all_sd - Exclude all optional service discoveries (keeps file_sd, static_sd, and http_sd) enable_
然后像往常一样运行 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_
If you add out-of-tree plugins, which we do not endorse at the moment, additional steps might be needed to adjust the go.mod and go.sum files. As always, be extra careful when loading third party code.
如果你添加了树外插件(我们目前不支持),可能需要额外的步骤来调整 go.mod 和 go.sum 文件。一如既往,在加载第三方代码时要格外小心。
Building the Docker image You can build a docker image locally with the following commands: make promu promu crossbuild -p linux/$(go env GOHOSTARCH) make common-docker-current-arch To build for a different architecture, replace $(go env GOHOSTARCH) with one of the architectures in DOCKER_ARCHS from Makefile.common, such as amd64, and run the corresponding make common-docker-
构建 Docker 镜像:你可以使用以下命令在本地构建 Docker 镜像:make promu;promu crossbuild -p linux/$(go env GOHOSTARCH);make common-docker-current-arch。要为不同的架构构建,请将 $(go env GOHOSTARCH) 替换为 Makefile.common 中 DOCKER_ARCHS 里的架构之一(例如 amd64),并运行相应的 make common-docker-
Using Prometheus as a Go Library Within the Prometheus project, repositories such as prometheus/common and prometheus/client_golang are designed as reusable libraries. The prometheus/prometheus repository builds a stand-alone program and is not designed for use as a library. We are aware that people do use parts as such, and we do not put any deliberate inconvenience in the way, but we want you to be aware that no care has been taken to make it work well as a library. For instance, you may encounter errors that only surface when used as a library.
将 Prometheus 用作 Go 库:在 Prometheus 项目中,诸如 prometheus/common 和 prometheus/client_golang 之类的存储库被设计为可重用的库。prometheus/prometheus 存储库构建的是一个独立程序,并非设计为库使用。我们知道人们确实将其部分内容用作库,我们不会故意制造不便,但我们希望你意识到,我们并未采取任何措施使其作为库良好运行。例如,你可能会遇到仅在作为库使用时才会出现的错误。
Remote Write We are publishing our Remote Write protobuf independently at buf.build. You can use that as a library: go get buf.build/gen/go/prometheus/prometheus/protocolbuffers/go@latest This is experimental.
远程写入:我们正在 buf.build 上独立发布我们的远程写入 protobuf。你可以将其用作库:go get buf.build/gen/go/prometheus/prometheus/protocolbuffers/go@latest。这是实验性的。
Prometheus code base In order to comply with go mod rules, Prometheus release number do not exactly match Go module releases. For the Prometheus v3.y.z releases, we are publishing equivalent v0.3y.z tags. The y in v0.3y.z is always padded to two digits, with a leading zero if needed. Therefore, a user that would want to use Prometheus v3.0.0 as a library could do: go get github.com/prometheus/prometheus@v0.300.0.
Prometheus 代码库:为了符合 go mod 规则,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。
For the Prometheus v2.y.z releases, we published the equivalent v0.y.z tags. Therefore, a user that would want to use Prometheus v2.35.0 as a library could do: go get github.com/prometheus/prometheus@v0.35.0 This solution makes it clear that we might break our i.
对于 Prometheus v2.y.z 版本,我们发布了等效的 v0.y.z 标签。因此,想要将 Prometheus v2.35.0 用作库的用户可以执行:go get github.com/prometheus/prometheus@v0.35.0。此解决方案明确表明我们可能会破坏我们的 i。