Skip to content

Instantly share code, notes, and snippets.

@adamyeats-zz
Last active April 17, 2018 20:05
Show Gist options
  • Save adamyeats-zz/5107465 to your computer and use it in GitHub Desktop.
Save adamyeats-zz/5107465 to your computer and use it in GitHub Desktop.
Server health endpoint based on @dshaw's JSDay tip
# In his JSDay talk (online here: http://dshaw.github.com/2012-05-jsday/), @dshaw proposed having a
# 'health' endpoint for Node servers that gave you important system stats.
#
# Here's an example of what that would look like for Sinatra.
require "time"
require "sinatra"
require "json"
get "/health" do
uptime = Time.parse `last | tail -1`
stats = {
"pid" => $$.to_s,
"current_memory_usage" => `ps -o rss= -p #{Process.pid}`.to_i.to_s,
"up_since" => uptime.to_s, # gets uptime of WHOLE MACHINE, TODO: change to time we start execution
"time_of_request" => Time.now.to_s
}
body stats.to_json
status 200
end
# TODO: number of current connections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment