Module: Statusz
- Defined in:
- lib/statusz.rb,
lib/statusz/version.rb
Overview
Statusz is a tool for displaying deploy-time and runtime server information.
Defined Under Namespace
Classes: Server
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.render_from_json(filename = "./statusz.json", format = :html, extra_fields = {}) ⇒ Object
If you wrote out a json file at deploy time, you can use this at runtime to turn the json file into any of statusz's supported formats (html, json, text) and add additional runtime values.
-
.write_file(filename = "./statusz.html", options = {}) ⇒ Object
Write out a statusz file.
Class Method Details
.render_from_json(filename = "./statusz.json", format = :html, extra_fields = {}) ⇒ Object
If you wrote out a json file at deploy time, you can use this at runtime to turn the json file into any of statusz's supported formats (html, json, text) and add additional runtime values.
102 103 104 105 106 107 |
# File 'lib/statusz.rb', line 102 def self.render_from_json(filename = "./statusz.json", format = :html, extra_fields = {}) raise "Bad format: #{format}" unless [:html, :text, :json].include? format fields = load_json_info(filename) fields.merge! extra_fields render(fields, format) end |
.write_file(filename = "./statusz.html", options = {}) ⇒ Object
Write out a statusz file. This should be done at deployment time.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/statusz.rb', line 32 def self.write_file(filename = "./statusz.html", = {}) [:commit] ||= "HEAD" [:format] ||= :html raise "Bad format: #{[:format]}" unless [:html, :text, :json].include? [:format] [:fields] ||= FIELD_TO_SCRAPING_PROC.keys = [:fields] - FIELD_TO_SCRAPING_PROC.keys raise "Bad options: #{.inspect}" unless .empty? extra_fields = [:extra_fields] || {} unless extra_fields.is_a? Hash raise "Extra fields should be a hash, but #{extra_fields.inspect} (#{extra_fields.class}) was given." end results = {} [:fields].each do |field| results[field] = FIELD_TO_SCRAPING_PROC[field].call([:commit]) end extra_fields.each { |field, value| results[field.to_s] = value.to_s } File.open(filename, "w") { |file| file.puts(render(results, [:format])) } end |