740059a4b4
also add storage of gathered stats
20 lines
405 B
Elixir
20 lines
405 B
Elixir
defmodule Elstat.Adapter.Ping do
|
|
@behaviour Elstat.Adapter
|
|
|
|
def adapter_spec do
|
|
%{
|
|
db_columns: [:timestamp, :status]
|
|
}
|
|
end
|
|
|
|
def check(args) do
|
|
{cmd_output, _} = System.cmd("ping", ["-c", "1", args.address])
|
|
alive? = not Regex.match?(~r/100(\.0)?% packet loss/, cmd_output)
|
|
{:ok, {:bool, alive?}}
|
|
end
|
|
|
|
def transform_val({:bool, alive?}) do
|
|
[alive?]
|
|
end
|
|
|
|
end
|