mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-30 02:36:22 +00:00
Merge branch 'blazer' into panel.sutty.nl
This commit is contained in:
commit
6749dab23a
3 changed files with 33 additions and 49 deletions
|
@ -30,17 +30,16 @@ module RecursiveRollup
|
|||
# intervalo más amplio.
|
||||
#
|
||||
# @param :name [String]
|
||||
# @param :beginning [Time]
|
||||
# @param :operation [Symbol]
|
||||
# @param :dimensions [Hash]
|
||||
# @return [nil]
|
||||
def reduce_rollup(name, beginning, operation, **dimensions)
|
||||
def reduce_rollup(name:, dimensions:, operation: :sum)
|
||||
Stat::INTERVALS.reduce do |previous, current|
|
||||
recursive_rollup(name: name,
|
||||
interval_previous: previous,
|
||||
interval: current,
|
||||
dimensions: dimensions,
|
||||
beginning: beginning,
|
||||
beginning: beginning_of_interval,
|
||||
operation: operation)
|
||||
|
||||
# Devolver el intervalo actual
|
||||
|
|
|
@ -22,9 +22,11 @@ class StatCollectionJob < PeriodicJob
|
|||
rollup.average(:seconds)
|
||||
end
|
||||
|
||||
reduce_rollup('builds', beginning, :sum, site_id: site_id)
|
||||
reduce_rollup('space_used', beginning, :average, site_id: site_id)
|
||||
reduce_rollup('build_time', beginning, :average, site_id: site_id)
|
||||
dimensions = { site_id: site_id }
|
||||
|
||||
reduce_rollup(name: 'builds', operation: :sum, dimensions: dimensions)
|
||||
reduce_rollup(name: 'space_used', operation: :average, dimensions: dimensions)
|
||||
reduce_rollup(name: 'build_time', operation: :average, dimensions: dimensions)
|
||||
|
||||
stat.touch
|
||||
run_again! unless once
|
||||
|
|
|
@ -22,7 +22,7 @@ class UriCollectionJob < PeriodicJob
|
|||
@site = Site.find site_id
|
||||
|
||||
# Obtener el principio del intervalo anterior
|
||||
beginning = beginning_of_interval
|
||||
beginning_of_interval
|
||||
# Recordar la última vez que se corrió la tarea
|
||||
stat = site.stats.create! name: STAT_NAME
|
||||
# Columnas a agrupar
|
||||
|
@ -33,10 +33,6 @@ class UriCollectionJob < PeriodicJob
|
|||
# rápido buscar en los rollups indexados que en la tabla en bruto.
|
||||
#
|
||||
# Los referers solo se agrupan por host.
|
||||
site.hostnames.each do |host|
|
||||
break if stop?
|
||||
|
||||
host_dimensions = { host: host }
|
||||
columns.each_key do |column|
|
||||
columns[column] = AccessLog.where(**host_dimensions).distinct(column).pluck(column)
|
||||
end
|
||||
|
@ -45,39 +41,25 @@ class UriCollectionJob < PeriodicJob
|
|||
# que indican las páginas y recursos descargables, el resto son
|
||||
# imágenes, CSS, JS y tipografías que no nos aportan números
|
||||
# significativos.
|
||||
name = 'host|uri'
|
||||
dimensions = { host: host, uri: uris }
|
||||
uri_dimensions = { host: site.hostnames, uri: uris }
|
||||
host_dimensions = { host: site.hostnames }
|
||||
|
||||
rollup(name, beginning, **dimensions)
|
||||
reduce_rollup(name, beginning, :sum, **dimensions)
|
||||
# Cantidad de visitas por host
|
||||
rollup(name: 'host', dimensions: host_dimensions, filter: uri_dimensions)
|
||||
reduce_rollup(name: 'host', operation: :sum, dimensions: uri_dimensions)
|
||||
|
||||
# Cantidad de visitas por página/recurso
|
||||
rollup(name: 'host|uri', dimensions: uri_dimensions)
|
||||
reduce_rollup(name: 'host|uri', operation: :sum, dimensions: uri_dimensions)
|
||||
|
||||
# Cantidad de visitas host y parámetro
|
||||
columns.each_pair do |column, values|
|
||||
# Obtener orígenes de visitas por host
|
||||
values.each do |value|
|
||||
column_name = "host|uri|#{column}"
|
||||
column_dimensions = { host: host, uri: uris }
|
||||
column_dimensions[column] = value
|
||||
column_name = "host|#{column}"
|
||||
column_dimensions = { host: site.hostnames }
|
||||
column_dimensions[column] = values
|
||||
|
||||
rollup(column_name, beginning, **column_dimensions)
|
||||
reduce_rollup(column_name, beginning, :sum, **column_dimensions)
|
||||
end
|
||||
end
|
||||
|
||||
# Reducir todas las visitas a cantidad de visitas por host
|
||||
rollup('host', beginning, **host_dimensions)
|
||||
|
||||
# Acumular por mes y año
|
||||
reduce_rollup('host', beginning, :sum, **host_dimensions)
|
||||
|
||||
columns.each_pair do |column, values|
|
||||
values.each do |value|
|
||||
column_dimensions = { host: host }
|
||||
column_dimensions[column] = value
|
||||
|
||||
rollup("host|#{column}", beginning, **column_dimensions)
|
||||
reduce_rollup("host|#{column}", beginning, :sum, **column_dimensions)
|
||||
end
|
||||
end
|
||||
rollup(name: column_name, dimensions: column_dimensions, filter: uri_dimensions)
|
||||
reduce_rollup(name: column_name, dimensions: column_dimensions)
|
||||
end
|
||||
|
||||
stat.touch
|
||||
|
@ -92,9 +74,10 @@ class UriCollectionJob < PeriodicJob
|
|||
# @param :name [String]
|
||||
# @param :beginning [Time]
|
||||
# @param :dimensions [Hash]
|
||||
# @param :filter [Hash]
|
||||
# @return [nil]
|
||||
def rollup(name, beginning, **dimensions)
|
||||
AccessLog.where(**dimensions)
|
||||
def rollup(name:, beginning:, dimensions:, filter: nil)
|
||||
AccessLog.where(**(filter || dimensions))
|
||||
.where('created_at >= ?', beginning)
|
||||
.completed_requests
|
||||
.non_robots
|
||||
|
|
Loading…
Reference in a new issue