diff --git a/.ruby-version b/.ruby-version index ecd7ee5..30f69e8 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.5.8 +2.5.9 diff --git a/README.markdown b/README.markdown index 395a57a..b77128f 100644 --- a/README.markdown +++ b/README.markdown @@ -90,19 +90,6 @@ on heroku, like this: heroku config:add AMNESIA_CREDS=ben:schwarz -### Content Security Policy - -Amnesia uses Google Charts to display pie charts. In case you're employing -a CSP header you'll need to add the Google Chart servers as a valid image source, e.g.: - - Content-Security-Policy: img-src 'self' data: https: https://chart.apis.google.com; - -Within a Rack app you can use [Rack::Protection](http://www.sinatrarb.com/protection): - -```rb -use Rack::Protection::ContentSecurityPolicy, img-src: "'self' data: https: https://chart.apis.google.com" -``` - ## Potential issues * Hosts are listed as "Inactive" or "Not Responding" diff --git a/amnesia.gemspec b/amnesia.gemspec index 1a7c119..2c0d1a1 100644 --- a/amnesia.gemspec +++ b/amnesia.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "amnesia" - s.version = "1.0.2" + s.version = "1.1.0" s.platform = Gem::Platform::RUBY s.authors = ["Ben Schwarz"] s.email = ["ben.schwarz@gmail.com"] @@ -12,7 +12,6 @@ Gem::Specification.new do |s| s.add_dependency "sinatra" s.add_dependency "dalli" - s.add_dependency "googlecharts", "~> 1.6.8" s.add_dependency "haml" s.add_development_dependency "rspec", "~> 3.9" diff --git a/lib/amnesia.rb b/lib/amnesia.rb index 1384337..6cce0f8 100644 --- a/lib/amnesia.rb +++ b/lib/amnesia.rb @@ -1,5 +1,4 @@ require 'sinatra/base' -require 'googlecharts' require 'haml' require 'amnesia/authentication' require 'amnesia/helpers' diff --git a/lib/amnesia/helpers.rb b/lib/amnesia/helpers.rb index b4e5fee..e4a8bf6 100644 --- a/lib/amnesia/helpers.rb +++ b/lib/amnesia/helpers.rb @@ -10,7 +10,7 @@ module HelperMethods SIZE_UNITS = %w[ Bytes KB MB GB TB PB EB ] def graph_url(*data) - Gchart.pie(data: data, size: '115x115', bg: 'ffffff00', use_ssl: true) + url "/pie?d="+data.join(',') end # https://github.com/rails/rails/blob/fbe335cfe09bf0949edfdf0c4b251f4d081bd5d7/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb diff --git a/lib/amnesia/host.rb b/lib/amnesia/host.rb index 64b5028..fdeecb7 100644 --- a/lib/amnesia/host.rb +++ b/lib/amnesia/host.rb @@ -4,9 +4,10 @@ module Amnesia class Host FLOAT_STATS = %w[ rusage_user rusage_system ] STRING_STATS = %w[ version libevent ] + DEFAULT_PORT = 11_211 def self.normalize_address address - return "#{address}:#{Dalli::Server::DEFAULT_PORT}" unless address.include? ":" + return "#{address}:#{DEFAULT_PORT}" unless address.include? ":" address end diff --git a/lib/amnesia/public/css/application.css b/lib/amnesia/public/css/application.css index 715faf9..e5e130b 100644 --- a/lib/amnesia/public/css/application.css +++ b/lib/amnesia/public/css/application.css @@ -47,10 +47,9 @@ header { margin: 1em 0; } align-items: center; margin: 2em 0; } -.stats-graph img { margin-left: -10px; } .stats-text { flex: 1 1; - margin-left: 1em; + margin-left: 1.5em; } .graph-indicator { color: #ff9900; } diff --git a/lib/amnesia/routes.rb b/lib/amnesia/routes.rb index 93d8e99..e2c0701 100644 --- a/lib/amnesia/routes.rb +++ b/lib/amnesia/routes.rb @@ -6,6 +6,27 @@ def self.included app haml :index end + get '/pie' do + data = params[:d].to_s.split(",").map(&:to_i) + + r = 25 + c = (2*Math::PI*r).ceil + v = data.first.to_f / data.last * 100 * c / 100 + v = v.nan? ? 0 : v.ceil + + content_type "image/svg+xml" + <<~BODY + + + + + BODY + end + get '/:address' do @host = find_host params[:address] @host ? haml(:host) : halt(404) diff --git a/lib/amnesia/views/host.haml b/lib/amnesia/views/host.haml index cdd5285..06bcf03 100644 --- a/lib/amnesia/views/host.haml +++ b/lib/amnesia/views/host.haml @@ -6,7 +6,7 @@ %article.stats %section.stats-graph - %img{src: graph_url(@host.bytes, @host.limit_maxbytes) } + %img{src: graph_url(@host.bytes, @host.limit_maxbytes), width: 90} %section.stats-text %h3 %span.graph-indicator Used (#{number_to_human_size(@host.bytes)}) @@ -15,7 +15,7 @@ %article.stats %section.stats-graph - %img{src: graph_url(@host.get_hits, @host.get_misses) } + %img{src: graph_url(@host.get_hits, @host.get_misses), width: 90} %section.stats-text %h3 %span.graph-indicator Hit (#{@host.get_hits}) @@ -24,7 +24,7 @@ %section.stats %section.stats-graph - %img{src: graph_url(@host.cmd_get, @host.cmd_set) } + %img{src: graph_url(@host.cmd_get, @host.cmd_set), width: 90} %section.stats-text %h3 %span.graph-indicator Read (#{@host.cmd_get}) diff --git a/lib/amnesia/views/index.haml b/lib/amnesia/views/index.haml index 4c75d13..ad1638d 100644 --- a/lib/amnesia/views/index.haml +++ b/lib/amnesia/views/index.haml @@ -1,7 +1,7 @@ - if alive_hosts.any? %article.stats %section.stats-graph - %img{src: graph_url(bytes_sum, limit_maxbytes_sum)} + %img{src: graph_url(bytes_sum, limit_maxbytes_sum), width: 90} %section.stats-text %h3 %span.graph-indicator Used (#{number_to_human_size(bytes_sum)}) @@ -10,7 +10,7 @@ %article.stats %section.stats-graph - %img{src: graph_url(get_hits_sum, get_misses_sum)} + %img{src: graph_url(get_hits_sum, get_misses_sum), width: 90} %section.stats-text %h3 %span.graph-indicator Hit (#{get_hits_sum}) @@ -19,7 +19,7 @@ %article.stats %section.stats-graph - %img{src: graph_url(cmd_get_sum, cmd_set_sum)} + %img{src: graph_url(cmd_get_sum, cmd_set_sum), width: 90} %section.stats-text %h3 %span.graph-indicator Read (#{cmd_get_sum})