31 lines
693 B
Elixir
31 lines
693 B
Elixir
defmodule Elstat.Adapter.Elixire do
|
|
@behaviour Elstat.Adapter
|
|
|
|
use GenServer
|
|
require Logger
|
|
|
|
def start_link(service_opts) do
|
|
GenServer.start_link(__MODULE__, service_opts, [])
|
|
end
|
|
|
|
def init(service_opts) do
|
|
Logger.info("Elixire adapter started with #{inspect service_opts}")
|
|
{:ok, %{}}
|
|
end
|
|
|
|
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,
|
|
latency: {:millisecond, delta},
|
|
}}}
|
|
end
|
|
|
|
end
|