Last active
April 17, 2018 20:05
-
-
Save adamyeats-zz/5107465 to your computer and use it in GitHub Desktop.
Server health endpoint based on @dshaw's JSDay tip
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
# 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