Skip to content

derniercri/warpex

Repository files navigation

Warpex

Build Status

Warpex is a Warp10 client for Elixir.

Usage

Add it to your applications and dependencies in mix.exs:

def application do
  [applications: [:warpex]]
end
  
def deps do
  [{:warpex, "~> 1.2"}]
end

Configure it in config.exs:

config :warpex,
  address: "http://localhost",  # defaults to System.get_env("WARP10_ADDRESS"),
  read_key:   "xxxxx",  # defaults to System.get_env("WARP10_READ_KEY")
  write_key:  "xxxxx",  # defaults to System.get_env("WARP10_WRITE_KEY")
  httpoison_opts: [timeout: 5000]  # defaults to []

And then call functions like:

{status, response} = Warpex.update(
    [%{
        "labels" => "label1=anything,label2=anotherthing", 
        "latlon" => "50.683299992233515:2.8832999244332314", 
        "elev" => "214748",
        "name" => "metric.1.memory_available", 
        "val" => 12, 
        "ts" => 1521969018754000
    }])
"'#{Warpex.get_token(:read)}'  // Put your token on the stack                                                                                                           
'token' STORE // Store it in a variable   
[ $token '~sensor.#{sensor.id}.*' {  } #{start} #{delta} ] FETCH  
[ SWAP bucketizer.mean 0 0 1 ] BUCKETIZE"     
|> Warpex.exec_warpscript()
{status, response} = Warpex.fetch("~metric.1.*{}", start, stop)

status is either :ok or :error.

response is the raw response from Warp10 as text