1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
defmodule ExPrometheusIo do
use Application
def start(_, _) do
ExPrometheusIo.Supervisor.start_link
end
def query(query, _opts \\ []) do
query_opts = [query]
spawn_query(:query, query_opts)
end
def range(query, start_ts, end_ts, step, _opts \\ []) do
query_opts = {query, start_ts, end_ts, step}
spawn_query(:range, query_opts)
end
def series(matches, _opts \\ []) when is_list(matches) do
spawn_query(:series, {matches})
end
defp spawn_query(query, query_opts, _opts \\ []) do
query_ref = make_ref()
query_opts = [query, query_opts, query_ref, self()]
{:ok, pid} = Task.Supervisor.start_child(
ExPrometheusIo.QuerySupervisor,
ExPrometheusIo.Query,
:process,
query_opts)
{pid, query_ref}
end
end
|