mostrar gráficos de recursos utilizados

This commit is contained in:
f 2021-10-08 18:39:55 -03:00
parent 8e9401036c
commit 224ea1ebc5
4 changed files with 62 additions and 10 deletions

View file

@ -9,6 +9,7 @@ class StatsController < ApplicationController
before_action :authorize_stats
INTERVALS = %i[hour day week month year].freeze
RESOURCES = %i[builds space_used build_time].freeze
# XXX: Permitir a Chart.js inyectar su propio CSS
content_security_policy only: :index do |policy|
@ -34,10 +35,23 @@ class StatsController < ApplicationController
end
end
end
end
render json: stats
end
end
def resources
if stale? [last_stat, interval, resource]
options = {
interval: interval,
dimensions: {
deploy_id: @site.deploys.where(type: 'DeployLocal').pluck(:id).first
}
}
render json: Rollup.series(resource, **options)
end
end
private
@ -86,6 +100,13 @@ class StatsController < ApplicationController
end
end
def resource
@resource ||= begin
r = params[:resource].to_sym
RESOURCES.include?(r) ? r : :builds
end
end
# Obtiene la cantidad de nodos de Sutty, para poder calcular la
# cantidad de visitas.
#

View file

@ -13,5 +13,12 @@
= link_to t(".#{interval}"), site_stats_path(interval: interval), class: "btn #{'btn-primary active' if params[:interval].to_sym == interval}"
.mb-3
%h2= t('.host', count: @hostnames.size)
= line_chart site_stats_host_path(@chart_params), locale: 'es'
%h2= t('.host.title', count: @hostnames.size)
%p.lead= t('.host.description')
= line_chart site_stats_host_path(@chart_params), **@chart_options
- StatsController::RESOURCES.each do |resource|
.mb-3
%h2= t(".resources.#{resource}.title")
%p.lead= t(".resources.#{resource}.description")
= line_chart site_stats_resources_path(resource: resource, **@chart_params), **@chart_options

View file

@ -261,9 +261,21 @@ en:
month: 'Monthly'
year: 'Yearly'
host:
title:
zero: 'Site visits'
one: 'Site visits'
other: 'Visits by site name'
description: 'Counts visited pages on your site, grouped by domain names in use.'
resources:
builds:
title: 'Site publication'
description: 'Times you published your site.'
space_used:
title: 'Server disk usage'
description: 'Average storage space used by your site.'
build_time:
title: 'Publication time'
description: 'Average time your site takes to build.'
sites:
donations:
url: 'https://donaciones.sutty.nl/en/'

View file

@ -266,9 +266,21 @@ es:
month: 'Mensuales'
year: 'Anuales'
host:
title:
zero: 'Visitas del sitio'
one: 'Visitas del sitio'
other: 'Visitas por nombre del sitio'
description: 'Cuenta la cantidad de páginas visitadas en tu sitio, dividida por los nombres de dominio en uso.'
resources:
builds:
title: 'Publicaciones del sitio'
description: 'Cantidad de veces que publicaste tu sitio.'
space_used:
title: 'Espacio utilizado en el servidor'
description: 'Espacio en disco que ocupa en promedio tu sitio.'
build_time:
title: 'Tiempo de publicación'
description: 'Tiempo promedio que toma en publicarse tu sitio.'
sites:
donations:
url: 'https://donaciones.sutty.nl/'