Skip to content

Instantly share code, notes, and snippets.

@jimsynz jimsynz/jitter.ex
Created Sep 14, 2015

Embed
What would you like to do?
defp store_jitter received_at, delivered_at do
received_usec = Time.to_usecs received_at
delivered_usec = Time.to_usecs delivered_at
jitter_usecs = delivered_usec - received_usec
delivered_sec = delivered_at |> Time.to_secs |> trunc
delivered_5m = delivered_at |> Time.to_secs |> trunc |> rem 300
delivered_1h = delivered_at |> Time.to_secs |> trunc |> rem 3600
{:ok, _} = R.query [
["MULTI"],
["ZADD", namespace("jitter"), delivered_usec, jitter_usecs],
["ZADD", namespace(hostname <> ":jitter"), delivered_usec, jitter_usecs],
["ZADD", namespace("jitter_1s"), jitter_usecs, delivered_sec]
["ZADD", namespace(hostname <> ":jitter_1s"), jitter_usecs, delivered_sec]
["ZADD", namespace("jitter_5m"), jitter_usecs, delivered_5m]
["ZADD", namespace(hostname <> ":jitter_5m"), jitter_usecs, delivered_5m]
["ZADD", namespace("jitter_1h"), jitter_usecs, delivered_1h]
["ZADD", namespace(hostname <> ":jitter_1h"), jitter_usecs, delivered_1h]
["EXEC"]
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.