Page MenuHomePhorge

No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/prometheus/registry.ex b/lib/prometheus/registry.ex
index b7d91ae..4f1dadb 100644
--- a/lib/prometheus/registry.ex
+++ b/lib/prometheus/registry.ex
@@ -1,63 +1,74 @@
defmodule Prometheus.Registry do
@moduledoc """
A registry of Collectors.
The majority of users should use the `:default`, rather than their own.
Creating a registry other than the default is primarily useful for
unit tests, or pushing a subset of metrics to the
[Pushgateway](https://github.com/prometheus/pushgateway) from batch jobs.
"""
use Prometheus.Erlang, :prometheus_registry
+ @doc """
+ Tries to find registry with the `name`.
+ Assumes that registry name is always an atom.
+ If `Name` is an atom `ets:lookup/2` is used
+ If `Name` is an iolist performs safe search (to avoid interning
+ atoms) and returns atom or false. This operation is O(n).
+ """
+ defmacro exists(name) do
+ Erlang.call([name])
+ end
+
@doc """
Calls `callback` for each collector with two arguments: `registry` and `collector`.
"""
defmacro collect(callback, registry \\ :default) do
Erlang.call([registry, callback])
end
@doc """
Returns collectors registered in `registry`.
"""
defmacro collectors(registry \\ :default) do
Erlang.call([registry])
end
@doc """
Registers a collector.
"""
defmacro register_collector(registry \\ :default, collector) do
Erlang.call([registry, collector])
end
@doc """
Registers collectors list.
"""
defmacro register_collectors(registry \\ :default, collectors) do
Erlang.call([registry, collectors])
end
@doc """
Unregisters a collector.
"""
defmacro deregister_collector(registry \\ :default, collector) do
Erlang.call([registry, collector])
end
@doc """
Unregisters all collectors.
"""
defmacro clear(registry \\ :default) do
Erlang.call([registry])
end
@doc """
Checks whether `collector` is registered.
"""
defmacro collector_registered?(registry \\ :default, collector) do
Erlang.call(:collector_registeredp, [registry, collector])
end
end
diff --git a/mix.exs b/mix.exs
index cc71fa6..98f4010 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,57 +1,57 @@
defmodule PrometheusEx.Mixfile do
use Mix.Project
@version "1.1.1"
def project do
[app: :prometheus_ex,
version: @version,
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
description: description(),
package: package(),
name: "Prometheus.ex",
deps: deps(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: ["coveralls": :test, "coveralls.html": :test],
docs: [main: Prometheus,
source_ref: "v#{@version}",
source_url: "https://github.com/deadtrickster/prometheus.ex",
extras: ["pages/Mnesia Collector.md",
"pages/VM Memory Collector.md",
"pages/VM Statistics Collector.md",
"pages/VM System Info Collector.md",
"pages/Time.md"]]]
end
def application do
[applications: [:logger,
:prometheus]]
end
defp description do
"""
Elixir-friendly Prometheus monitoring system client.
"""
end
defp package do
[maintainers: ["Ilya Khaprov"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/deadtrickster/prometheus.ex",
"Prometheus.erl" => "https://hex.pm/packages/prometheus",
"Ecto Instrumenter" => "https://hex.pm/packages/prometheus_ecto",
"Phoenix Instrumenter" => "https://hex.pm/packages/prometheus_phoenix",
"Plugs Instrumenter/Exporter" => "https://hex.pm/packages/prometheus_plugs",
"Process info Collector" => "https://hex.pm/packages/prometheus_process_collector"}]
end
defp deps do
- [{:prometheus, "~> 3.1"},
+ [{:prometheus, "~> 3.2"},
{:credo, git: "https://github.com/rrrene/credo", only: [:dev, :test]},
{:excoveralls, "~> 0.5.6", only: :test},
{:ex_doc, "~> 0.11", only: :dev},
{:earmark, ">= 0.0.0", only: :dev}]
end
end
diff --git a/mix.lock b/mix.lock
index c213297..3ba17c3 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,14 +1,14 @@
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"credo": {:git, "https://github.com/rrrene/credo", "075dc2f81539ee7e901ac33e4bb1ff7b2142c12b", []},
"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.7", "5d26e4a7cdf08294217594a1b0643636accc2ad30e984d62f1d166f70629ff50", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.8.0", "749bec6d205c694ae1786d62cea6cc45a390437e24835fd16d12d74f07097727", [:mix, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
- "prometheus": {:hex, :prometheus, "3.1.0", "32a148a6c906d8d31113cad5cb07d4b61dec3f77c6f6fe2ce837d1ff62e9a049", [:rebar3], []},
+ "prometheus": {:hex, :prometheus, "3.2.2", "887a687855e171852be3e023aea9dbc1ea3ce0f327b95765896ebb2847fef7f9", [:mix, :rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []}}
diff --git a/test/registry_test.exs b/test/registry_test.exs
index 8e80ffe..0368334 100644
--- a/test/registry_test.exs
+++ b/test/registry_test.exs
@@ -1,58 +1,69 @@
defmodule Prometheus.RegistryTest do
use Prometheus.Case
alias Prometheus.Registry
alias Prometheus.RegistryTest
import ExUnit.CaptureIO
def deregister_cleanup(_), do: :ok
+ test "registry exists" do
+ Prometheus.Registry.register_collector(:test_registry, RegistryTest)
+
+ assert true == Registry.exists(:test_registry)
+
+ assert :test_registry == Registry.exists("test_registry")
+
+ assert false == Registry.exists(:qweqwe)
+ assert false == Registry.exists("qweqwe")
+ end
+
test "default Registry" do
# default registry
assert :ok == Prometheus.Registry.register_collector(RegistryTest)
assert [RegistryTest] == Registry.collectors()
assert true == Registry.collector_registered?(RegistryTest)
Registry.clear()
assert [] == Registry.collectors()
assert false == Registry.collector_registered?(RegistryTest)
assert :ok == Registry.register_collector(RegistryTest)
Registry.deregister_collector(RegistryTest)
assert [] == Registry.collectors()
assert false == Registry.collector_registered?(RegistryTest)
## custom registry
assert :ok == Registry.register_collector(:custom_collector, RegistryTest)
assert [RegistryTest] == Registry.collectors(:custom_collector)
assert true == Registry.collector_registered?(:custom_collector, RegistryTest)
Registry.clear(:custom_collector)
assert [] == Registry.collectors(:custom_collector)
assert false == Registry.collector_registered?(:custom_collector, RegistryTest)
assert :ok == Registry.register_collector(:custom_collector, RegistryTest)
Registry.deregister_collector(:custom_collector, RegistryTest)
assert [] == Registry.collectors(:custom_collector)
assert false == Registry.collector_registered?(:custom_collector, RegistryTest)
## register_collectors && collect; default registry
assert :ok == Registry.register_collectors([RegistryTest])
assert [RegistryTest] == Registry.collectors()
assert capture_io(fn ->
Registry.collect(fn (:default, collector) ->
:io.format("~p", [collector])
end) ==
"Elixir.RegistryTest"
end)
## register_collectors && collect; custom registry
assert :ok == Registry.register_collectors(:custom_collector, [RegistryTest])
assert [RegistryTest] == Registry.collectors(:custom_collector)
assert capture_io(fn ->
Registry.collect(fn (:custom_collector, collector) ->
:io.format("~p", [collector])
end, :custom_collector) ==
"Elixir.RegistryTest"
end)
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sun, Dec 1, 3:43 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41582
Default Alt Text
(9 KB)

Event Timeline