Elixir:仅针对Prometheus指标启动http服务器 [英] Elixir: start http server only for prometheus metrics

查看:99
本文介绍了Elixir:仅针对Prometheus指标启动http服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

defmodule MyApp.Http do
  use Application

  require Logger

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    MyApp.PlugPipelineInstrumenter.setup()
    MyApp.MetricsExporter.setup()

    opts = [strategy: :one_for_one, name: MyApp.Http.Supervisor]
    Supervisor.start_link([], opts)
  end
end

defmodule MyApp.MetricsExporter do
  use Prometheus.PlugExporter
end

defmodule MyApp.PlugPipelineInstrumenter do
  use Prometheus.PlugPipelineInstrumenter
end

但是它什么也没做。当我添加时:

But it does nothing. When I add:

plug MyApp.MetricsExporter
plug MyApp.PlugPipelineInstrumenter

我得到编译错误:未定义的功能插件/ 1 。我使用长生不老药1.10.3。我在这里怎么办?

I get compilation error: undefined function plug/1. I use elixir 1.10.3. What do I do wrong here?

推荐答案

我制作了一个名为 prometheus_sidecar 会创建一个专门用于Prometheus的牧场服务器(这样您就可以在任何长生不老药应用程序中运行它)并连接 prometheus_plugs 为您提供。

I made a hex package called prometheus_sidecar that creates a ranch server dedicated to prometheus (so you could run it in any elixir application) and wires up prometheus_plugs for you.

它利用erlang的应用程序启动生命周期,因此除了添加它外,不需要任何配置。

It leverages erlang's application start lifecycle so there is no required configuration, besides adding it as a library to your application.

让我知道您是否认为它有用。

Let me know if you find it useful.

这篇关于Elixir:仅针对Prometheus指标启动http服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆