Last active
September 8, 2016 18:23
-
-
Save scottdavis/90c602c7254d9437aca01a5bc0412024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Monitor do | |
def health_check do | |
ExStatsD.histogram(get_concache_mem_size(:css_cache), "css.cache.memory", ["css_cache_memory"]) | |
ExStatsD.histogram(get_concache_mem_size(:sass_cache), "sass.cache.memory", ["sass_cache_memory"]) | |
ExStatsD.histogram(ConCache.size(:css_cache), "css.cache.size", ["css_cache_size"]) | |
ExStatsD.histogram(ConCache.size(:sass_cache), "sass.cache.size", ["sass_cache_size"]) | |
ExStatsD.histogram(:erlang.memory(:ets), "erlang.ets.memory", ["ets_size"]) | |
ExStatsD.histogram(:erlang.memory |> Keyword.get(:total), "erlang.memory.memory", ["ets_size"]) | |
end | |
defp get_concache_mem_size(name) do | |
name |> ConCache.ets |> :ets.info |> Keyword.get(:memory) |> (fn(x) -> x * :erlang.system_info(:wordsize) end).() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config :quantum, cron: [ | |
# Every minute | |
"* * * * *": {SassEngine.Monitor, :health_check} | |
] | |
config :ex_statsd, | |
host: "localhost", | |
port: 8125, | |
namespace: "MyApp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RequestStatusPlug do | |
@behaviour Plug | |
import Plug.Conn, only: [register_before_send: 2] | |
def init(opts), do: opts | |
def call(conn, _config) do | |
req_start_time = :os.timestamp | |
register_before_send conn, fn conn -> | |
# increment count | |
ExStatsD.increment("response.count") | |
# log response time in microseconds | |
req_end_time = :os.timestamp | |
duration = :timer.now_diff(req_end_time, req_start_time) | |
ExStatsD.timer(duration, "response.time") | |
conn | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment