/status: add more information to /status page.
Add the following: * Container name, machine name, worker id. * Container uptime, puma uptime, worker uptime. * Number of requests processed by current worker. * ExifTool version. Also change /status page to show information in tables instead of lists.
This commit is contained in:
6
app/logical/danbooru/helpers.rb
Normal file
6
app/logical/danbooru/helpers.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Danbooru
|
||||
module Helpers
|
||||
module_function
|
||||
extend ActionView::Helpers::DateHelper
|
||||
end
|
||||
end
|
||||
@@ -18,20 +18,30 @@ class ServerStatus
|
||||
{
|
||||
ip: request.remote_ip,
|
||||
headers: http_headers,
|
||||
status: {
|
||||
hostname: hostname,
|
||||
uptime: uptime,
|
||||
loadavg: loadavg,
|
||||
instance: {
|
||||
container_name: container_name,
|
||||
instance_name: instance_name,
|
||||
worker_name: worker_name,
|
||||
container_uptime: container_uptime,
|
||||
instance_uptime: instance_uptime,
|
||||
worker_uptime: worker_uptime,
|
||||
requests_processed: requests_processed,
|
||||
danbooru_version: danbooru_version,
|
||||
ruby_version: RUBY_VERSION,
|
||||
distro_version: distro_version,
|
||||
kernel_version: kernel_version,
|
||||
libvips_version: libvips_version,
|
||||
ffmpeg_version: ffmpeg_version,
|
||||
mkvmerge_version: mkvmerge_version,
|
||||
exiftool_version: exiftool_version,
|
||||
redis_version: redis_version,
|
||||
postgres_version: postgres_version,
|
||||
},
|
||||
server: {
|
||||
node_name: node_name,
|
||||
node_uptime: node_uptime,
|
||||
loadavg: loadavg,
|
||||
kernel_version: kernel_version,
|
||||
},
|
||||
postgres: {
|
||||
connection_stats: postgres_connection_stats,
|
||||
},
|
||||
@@ -54,9 +64,53 @@ class ServerStatus
|
||||
Socket.gethostname
|
||||
end
|
||||
|
||||
def uptime
|
||||
seconds = File.read("/proc/uptime").split[0].to_f
|
||||
"#{seconds.seconds.in_days.round} days"
|
||||
def instance_name
|
||||
if container_name.present?
|
||||
"#{container_name}/#{node_name}"
|
||||
else
|
||||
node_name
|
||||
end
|
||||
end
|
||||
|
||||
def container_name
|
||||
ENV["K8S_POD_NAME"]
|
||||
end
|
||||
|
||||
def node_name
|
||||
ENV["K8S_NODE_NAME"] || hostname
|
||||
end
|
||||
|
||||
def worker_name
|
||||
Thread.current.object_id
|
||||
end
|
||||
|
||||
def node_uptime
|
||||
uptime = File.read("/proc/uptime").split[0].to_f.seconds
|
||||
Danbooru::Helpers.distance_of_time_in_words(uptime)
|
||||
end
|
||||
|
||||
def container_uptime
|
||||
started_at = File.stat("/proc/1").mtime
|
||||
uptime = Time.zone.now - started_at
|
||||
Danbooru::Helpers.distance_of_time_in_words(uptime)
|
||||
end
|
||||
|
||||
def instance_uptime
|
||||
started_at = File.stat("/proc/#{Process.ppid}").mtime
|
||||
uptime = Time.zone.now - started_at
|
||||
Danbooru::Helpers.distance_of_time_in_words(uptime)
|
||||
end
|
||||
|
||||
def worker_uptime
|
||||
started_at = File.stat("/proc/#{Process.pid}").mtime
|
||||
uptime = Time.zone.now - started_at
|
||||
Danbooru::Helpers.distance_of_time_in_words(uptime)
|
||||
end
|
||||
|
||||
def requests_processed
|
||||
if Puma::Server.current.present?
|
||||
Puma::Server.current.requests_count
|
||||
end
|
||||
end
|
||||
|
||||
def loadavg
|
||||
@@ -87,6 +141,10 @@ class ServerStatus
|
||||
def mkvmerge_version
|
||||
`mkvmerge --version`.chomp
|
||||
end
|
||||
|
||||
def exiftool_version
|
||||
`exiftool -ver`.chomp
|
||||
end
|
||||
end
|
||||
|
||||
concerning :RedisMethods do
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<%# hash %>
|
||||
<dl>
|
||||
<table class="striped aligned-vertical">
|
||||
<% hash.each do |key, value| %>
|
||||
<dt><%= key.to_s.humanize %></dt>
|
||||
<dd><%= value %></dd>
|
||||
<tr>
|
||||
<th><%= key.to_s.humanize %></th>
|
||||
<td><%= value %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</dl>
|
||||
</table>
|
||||
|
||||
@@ -2,17 +2,27 @@
|
||||
<div id="a-show" class="fixed-width-container">
|
||||
<h1>Status</h1>
|
||||
|
||||
<% if @status.danbooru_version.present? && Danbooru.config.source_code_url.present? %>
|
||||
<p>Running <%= external_link_to "#{Danbooru.config.source_code_url}/commits/#{@status.danbooru_version}", @status.danbooru_version.first(7) %>.</p>
|
||||
<% end %>
|
||||
|
||||
<h2>Server</h2>
|
||||
<h2>Instance</h1>
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
Server: <%= @status.hostname %>
|
||||
Running
|
||||
<% if @status.danbooru_version.present? && Danbooru.config.source_code_url.present? %>
|
||||
<%= external_link_to "#{Danbooru.config.source_code_url}/commits/#{@status.danbooru_version}", @status.danbooru_version.first(7) %>
|
||||
<% end %>
|
||||
on <%= @status.instance_name %>
|
||||
for <%= @status.instance_uptime %>
|
||||
</summary>
|
||||
<%= render "list", hash: @status.serializable_hash[:status] %>
|
||||
<%= render "list", hash: @status.serializable_hash[:instance] %>
|
||||
</details>
|
||||
|
||||
<h2>Server</h1>
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
Server: <%= @status.node_name %>
|
||||
</summary>
|
||||
<%= render "list", hash: @status.serializable_hash[:server] %>
|
||||
</details>
|
||||
|
||||
<h2>Postgres</h2>
|
||||
|
||||
Reference in New Issue
Block a user