2018-06-11 07:24:16 +00:00
|
|
|
defmodule Elstat.Adapter.Elixire do
|
|
|
|
@behaviour Elstat.Adapter
|
|
|
|
|
2018-06-11 22:19:15 +00:00
|
|
|
def adapter_spec do
|
|
|
|
%{
|
2018-06-11 22:37:49 +00:00
|
|
|
db_columns: [:timestamp, :status, :latency]
|
2018-06-11 22:19:15 +00:00
|
|
|
}
|
2018-06-11 07:24:16 +00:00
|
|
|
end
|
2018-06-11 22:19:15 +00:00
|
|
|
|
2018-06-11 07:24:16 +00:00
|
|
|
def check(args) do
|
|
|
|
addr = args.base_url
|
|
|
|
|
|
|
|
req_start = :erlang.monotonic_time(:millisecond)
|
|
|
|
resp = HTTPoison.get!("#{addr}/api/hello")
|
|
|
|
req_end = :erlang.monotonic_time(:millisecond)
|
|
|
|
|
|
|
|
delta = req_end - req_start
|
|
|
|
|
|
|
|
{:ok, {:map, %{
|
|
|
|
status: resp.status_code == 200,
|
2018-06-11 20:42:40 +00:00
|
|
|
latency: delta,
|
2018-06-11 07:24:16 +00:00
|
|
|
}}}
|
|
|
|
end
|
2018-06-11 22:37:49 +00:00
|
|
|
|
|
|
|
def transform_val({:map, %{status: status, latency: latency}}) do
|
|
|
|
[status, latency]
|
|
|
|
end
|
2018-06-11 07:24:16 +00:00
|
|
|
|
|
|
|
end
|