Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ sudo: false
language: elixir
elixir:
- 1.3.1
- 1.4.0-rc.1
- 1.6.4
otp_release:
- 18.2
- 19.1
after_script:
- MIX_ENV=test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If [available in Hex](https://hex.pm/docs/publish), the package can be installed

```elixir
def deps do
[{:graphitex, "~> 0.1.0"}]
[{:graphitex, "~> 0.3.0"}]
end
```

Expand Down
2 changes: 1 addition & 1 deletion lib/graphitex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Graphitex do
defdelegate metric_batch(msgs), to: Graphitex.Client

def now do
:os.system_time(:seconds)
:os.system_time(:seconds) / 1
end

end
31 changes: 26 additions & 5 deletions lib/graphitex/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ defmodule Graphitex.Client do
@doc """
Add a node and the service it provides to the directory.
"""
@spec metric(number, [String.t], Float.t) :: nil
def metric(value, namespace, ts) when is_list(namespace) and is_float(ts) do
metric({value, Enum.join(namespace, "."), ts})
end

@spec metric(number, [String.t], number) :: nil
def metric(value, namespace, ts) when is_list(namespace) and is_number(ts) do
metric({value, Enum.join(namespace, "."), Float.round(ts / 1, 1)})
end

@spec metric(number, binary|String.t, Float.t) :: nil
def metric(value, namespace, ts) when is_float(ts) do
metric({value, namespace, Float.round(ts, 1)})
end

@spec metric(number, [String.t]) :: nil
def metric(value, namespace) when is_list(namespace) do
metric({value, Enum.join(namespace, ".")})
end

@spec metric(number, binary) :: nil
def metric(value, namespace) when is_binary(namespace) do
metric({value, namespace})
end
@spec metric(number, binary|String.t, Float.t) :: nil
def metric(value, namespace, ts) when is_float(ts) do
metric({value, namespace, Float.round(ts, 1)})
end

@spec metric({number, binary|String.t, Float.t}) :: nil
def metric(measurement) do
GenServer.cast(@name, {:metric, pack_msg(measurement)})
Expand Down Expand Up @@ -67,14 +80,22 @@ defmodule Graphitex.Client do

def connect(state) do
port = Application.get_env(:graphitex, :port, 2003)
host = Application.get_env(:graphitex, :host)
host = host()
opts = [:binary, active: false]
Logger.info fn -> "Connecting to carbon at #{host}:#{port}" end
{:ok, socket} = :gen_tcp.connect(host, port, opts)
Logger.info "Connected"
%{state | socket: socket}
end

defp host() do
host = Application.get_env(:graphitex, :host)
case is_binary(host) do
true -> String.to_charlist(host)
false -> host
end
end

def terminate({:error, :closed}, state) do
state
end
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ defmodule Graphitex.Mixfile do
# Type "mix help deps" for more examples and options
defp deps do
[
{:ex_doc, ">= 0.0.0", only: :dev},
{:credo, only: ~w(test dev)a},
{:mix_test_watch, "~> 0.2.5", only: ~w(dev test)a},
{:ex_doc, "~> 0.18.3", only: :dev},
{:credo, "~> 0.8.10", only: ~w(test dev)a},
{:mix_test_watch, "~> 0.5.0", only: ~w(dev test)a},
]
end
end
14 changes: 8 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"connection": {:git, "https://github.com/fishcakez/connection.git", "5b794fda9ec2cd41eae2887011381cfdb2cfb93e", []},
"credo": {:hex, :credo, "0.7.3", "9827ab04002186af1aec014a811839a06f72aaae6cd5eed3919b248c8767dbf3", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
"dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.2.6", "9fcc2b1b89d1594c4a8300959c19d50da2f0ff13642c8f681692a6e507f92cab", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}}
"mix_test_watch": {:hex, :mix_test_watch, "0.5.0", "2c322d119a4795c3431380fca2bca5afa4dc07324bd3c0b9f6b2efbdd99f5ed3", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
}
12 changes: 10 additions & 2 deletions test/graphitex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ defmodule GraphitexTest do
assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu])
end

test "collect metric atom tags and a Graphitex.now()" do
assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu], Graphitex.now())
end

test "collect metric atom tags and an :os.system_time(:seconds)" do
assert :ok == Graphitex.metric(4, [:aws, :node1, :avg_cpu], :os.system_time(:seconds))
end

test "batch send" do
batch = [
{4, "client.transactions.east"},
Expand All @@ -21,8 +29,8 @@ defmodule GraphitexTest do

test "stream batch" do
1..10
|> Enum.map(fn n ->
:ok = Graphitex.metric(n, "aws.node1.load")
|> Enum.each(fn (x) ->
:ok = Graphitex.metric(x, "aws.node1.load")
end)
end
end