【问题标题】:Deploy Prometheus to Cloud Foundry将 Prometheus 部署到 Cloud Foundry
【发布时间】:2017-02-21 20:13:50
【问题描述】:

我想在不使用 Docker 容器的情况下将 Prometheus 部署到 Cloud Foundry。当我尝试使用标准 Cloud Foundry Go Buildpack 部署它时,我收到以下错误:

can't load package: package prometheus: no buildable Go source files in /tmp/tmp.vv4iyDzMvE/.go/src/prometheus

这在某种程度上是有道理的,因为根目录中实际上没有源代码,并且该项目是使用 Prometheus 实用工具编译的。

有什么方法可以将 Prometheus 部署到 Cloud Foundry,比如使用另一个 Buildpack 之类的吗?

【问题讨论】:

    标签: go cloud-foundry prometheus


    【解决方案1】:

    我有同样的问题,但(就在今天)想出了一个稍微不同的解决方案,这对我来说似乎更容易。

    我使用了 prometheus-2.2.1-linux-amd64 二进制构建。

    我修改了 prometheus.yml 以使用默认端口 8080 作为目标(最后一行):

        # 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
    

    然后我添加了一个 ma​​nifest.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
    

    这是使用二进制构建包,并告诉 prometheus 启动服务器侦听端口 8080。

    2 个文件更改,这是:

    cf push
    

    现在我在 Pivotal Web Services 上的空间中运行了 prometheus。

    【讨论】:

      【解决方案2】:

      Prometheus 是一个 TSDB。它旨在消耗千兆字节和千兆字节的数据。

      在 Cloud Foundry 平台上,您受到可用资源的限制。 那么,为什么要将 Prometheus 部署到 Cloud Foundry?

      为什么不启动独立的bosh director 并通过director 将Prometheus 部署为Bosh 部署和独立的。然后将其作为 CUPS 注入 Cloud Foundry?

      我只是好奇并试图理解用例。

      【讨论】:

      【解决方案3】:

      好的,经过一番挖掘后,我得到了整个工作如下

      ma​​nifest.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 简单地部署应用程序,一切都应该像一个魅力一样工作

      【讨论】:

        猜你喜欢
        • 2019-02-15
        • 2015-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多