英文:
Deploy Prometheus to Cloud Foundry
问题
我想在不使用Docker容器的情况下将Prometheus部署到Cloud Foundry。当我尝试使用标准的Cloud Foundry Go Buildpack部署时,出现以下错误:
无法加载包:包prometheus在/tmp/tmp.vv4iyDzMvE/.go/src/prometheus中没有可构建的Go源文件
这在某种程度上是有道理的,因为实际上在根目录中没有任何源文件,并且该项目是使用Prometheus实用工具进行编译的。
是否有任何方法可以将Prometheus部署到Cloud Foundry,例如使用另一个Buildpack或其他方法?
英文:
I want to deploy Prometheus to Cloud Foundry without using Docker container. When I try to deploy it with the standard Cloud Foundry Go Buildpack I get the following error:
can't load package: package prometheus: no buildable Go source files in /tmp/tmp.vv4iyDzMvE/.go/src/prometheus
Which somehow makes sense, because there are actually no sources in the root directory and the project is compiled with the Prometheus utility tool.
Is there any way to deploy Prometheus to Cloud Foundry, like using another Buildpack or something?
答案1
得分: 2
我有同样的问题,但是(就在今天)我想出了一个稍微不同的解决方案,对我来说似乎更容易。
我使用了 prometheus-2.2.1-linux-amd64 二进制构建。
我修改了 prometheus.yml 文件,将默认端口 8080 作为目标(最后一行):
# 我的全局配置
global:
scrape_interval: 15s # 将抓取间隔设置为每 15 秒一次。默认为每 1 分钟一次。
evaluation_interval: 15s # 每 15 秒评估规则一次。默认为每 1 分钟一次。
# 抓取超时设置为全局默认值(10s)。
# Alertmanager 配置
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# 加载规则并根据全局的 'evaluation_interval' 定期评估它们。
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# 包含一个端点的抓取配置:
# 这里是 Prometheus 本身。
scrape_configs:
# 作业名称将作为标签 `job=<job_name>` 添加到从此配置中抓取的任何时间序列。
- job_name: 'prometheus'
# metrics_path 默认为 '/metrics'
# scheme 默认为 'http'。
static_configs:
- targets: ['localhost:8080'] ###### 只更改了这一行
然后我添加了一个 manifest.yml 文件
---
applications:
- name: prometheus
instances: 1
buildpack: https://github.com/cloudfoundry/binary-buildpack.git
command: ./prometheus --config.file=prometheus.yml --web.listen-address=:8080 --web.enable-admin-api
memory: 1024M
random-route: true
这里使用了 binary-buildpack,并告诉 prometheus 在端口 8080 上启动服务器。
只需更改 2 个文件和执行以下命令:
cf push
现在,我在 Pivotal Web Services 上的空间中运行着 prometheus。
英文:
I had the same question, but (just today) came up with a slightly different solution, that seemed easier to me.
I used the prometheus-2.2.1-linux-amd64 binary build.
I modified the prometheus.yml to use the default port 8080 as a target (last line):
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:8080'] ###### Only changed this line
Then I added a manifest.yml
---
applications:
- name: prometheus
instances: 1
buildpack: https://github.com/cloudfoundry/binary-buildpack.git
command: ./prometheus --config.file=prometheus.yml --web.listen-address=:8080 --web.enable-admin-api
memory: 1024M
random-route: true
That is using the binary-buildpack, and tells prometheus to startup the server listening on port 8080.
2 files changes and this:
cf push
Now I have prometheus running in my space on Pivotal Web Services.
答案2
得分: 1
Prometheus是一个TSDB(时间序列数据库)。它的设计初衷是用于处理大量的数据。
在Cloud Foundry平台上,你受限于可用资源。那么,为什么要将Prometheus部署到Cloud Foundry上呢?
为什么不通过独立的bosh director
部署Prometheus,将其作为一个Bosh部署和独立部署,然后将其作为CUPS注入到Cloud Foundry中呢?
我只是好奇并试图理解使用场景。
英文:
Prometheus is a TSDB. And it is intended to consume gigabytes and gigabytes of data.
On a Cloud Foundry platform, you are limited by available resources.
So, why deploy Prometheus to Cloud Foundry?
Why not spin up a standalone bosh director
and deploy Prometheus through the director as a Bosh deployment, and a standalone. Then inject it as a CUPS into Cloud Foundry?
I am just curious and trying to understand the use case.
答案3
得分: 0
好的,以下是翻译的内容:
好的,在进行了一些调查后,我找到了使整个过程正常工作的方法,如下所示:
manifest.yml
---
applications:
- name: prometheus
instances: 1
buildpack: https://github.com/cloudfoundry/go-buildpack.git
command: prometheus
env:
GOPACKAGENAME: github.com/prometheus/prometheus
GO_INSTALL_PACKAGE_SPEC: github.com/prometheus/prometheus/cmd/prometheus
memory: 1000M
但是为了监听正确的端口,我找到的唯一解决方案是在 cmd/prometheus/config.go
文件的 init()
函数开头添加以下内容:
port := ":9090"
if s := os.Getenv("PORT"); s != "" {
port = ":" + s
}
然后将以下部分(也在 init()
函数中)进行更改:
cfg.fs.StringVar(
&cfg.web.ListenAddress, "web.listen-address", ":9090",
"Address to listen on for the web interface, API, and telemetry.",
)
更改为:
cfg.fs.StringVar(
&cfg.web.ListenAddress, "web.listen-address", port,
"Address to listen on for the web interface, API, and telemetry.",
)
之后,您只需使用 cf push
部署应用程序,一切应该正常工作。
英文:
Ok, after digging around a bit I got the whole thing working as follows
manifest.yml
---
applications:
- name: prometheus
instances: 1
buildpack: https://github.com/cloudfoundry/go-buildpack.git
command: prometheus
env:
GOPACKAGENAME: github.com/prometheus/prometheus
GO_INSTALL_PACKAGE_SPEC: github.com/prometheus/prometheus/cmd/prometheus
memory: 1000M
BUT in order to listen on the right port, the only solution I could find is adding the following to the cmd/prometheus/config.go
file to the beginning of the init()
function
port := ":9090"
if s := os.Getenv("PORT"); s != "" {
port = ":"+s
}
and then changing the following part (also in the init()
function)
cfg.fs.StringVar(
&cfg.web.ListenAddress, "web.listen-address", ":9090",
"Address to listen on for the web interface, API, and telemetry.",
)
to
cfg.fs.StringVar(
&cfg.web.ListenAddress, "web.listen-address", port,
"Address to listen on for the web interface, API, and telemetry.",
)
After that you can simply deploy the application with cf push
and everything should work as a charm
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论