部署 Prometheus 到 Cloud Foundry

huangapple go评论90阅读模式
英文:

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 &#39;evaluation_interval&#39;.
rule_files:
  # - &quot;first_rules.yml&quot;
  # - &quot;second_rules.yml&quot;

# A scrape configuration containing exactly one endpoint to scrape:
# Here it&#39;s Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.
  - job_name: &#39;prometheus&#39;

    # metrics_path defaults to &#39;/metrics&#39;
    # scheme defaults to &#39;http&#39;.

    static_configs:
      - targets: [&#39;localhost:8080&#39;] ###### 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 := &quot;:9090&quot;
if s := os.Getenv(&quot;PORT&quot;); s != &quot;&quot; {
    port = &quot;:&quot;+s
}

and then changing the following part (also in the init() function)

cfg.fs.StringVar(
	&amp;cfg.web.ListenAddress, &quot;web.listen-address&quot;, &quot;:9090&quot;,
	&quot;Address to listen on for the web interface, API, and telemetry.&quot;,
)

to

cfg.fs.StringVar(
	&amp;cfg.web.ListenAddress, &quot;web.listen-address&quot;, port,
	&quot;Address to listen on for the web interface, API, and telemetry.&quot;,
)

After that you can simply deploy the application with cf push and everything should work as a charm

huangapple
  • 本文由 发表于 2017年2月22日 04:13:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/42377057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定