mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 17:26:21 +00:00
recolectar información acumulándola
This commit is contained in:
parent
752935afb4
commit
957c810aea
1 changed files with 38 additions and 10 deletions
|
@ -26,23 +26,43 @@ class UriCollectionJob < PeriodicJob
|
|||
stat = site.stats.create! name: STAT_NAME
|
||||
beginning = beginning_of_interval
|
||||
|
||||
# Recorremos todos los hostnames y uris posibles y luego agrupamos
|
||||
# recursivamente para no tener que recalcular, asumiendo que es más
|
||||
# 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?
|
||||
|
||||
dimensions = { host: host }
|
||||
|
||||
uris.each do |uri|
|
||||
break if stop?
|
||||
|
||||
rollup('host|uri', beginning, host: host, uri: uri)
|
||||
dimensions[:uri] = uri
|
||||
|
||||
AccessLog.where(host: host, uri: uri).distinct(:http_referer).pluck(:http_referer).each do |http_referer|
|
||||
rollup('host|uri|referer', beginning, host: host, uri: uri, http_referer: http_referer)
|
||||
end
|
||||
rollup('host|uri', beginning, **dimensions)
|
||||
reduce_rollup('host|uri', beginning, **dimensions)
|
||||
end
|
||||
|
||||
rollup('host', beginning, host: host)
|
||||
dimensions.delete(:uri)
|
||||
|
||||
# Reducir todas las visitas a cantidad de visitas por host
|
||||
recursive_rollup(name: 'host|uri',
|
||||
new_name: 'host',
|
||||
interval_previous: starting_interval,
|
||||
interval: starting_interval,
|
||||
dimensions: dimensions)
|
||||
|
||||
# Acumular por mes y año
|
||||
reduce_rollup('host', beginning, **dimensions)
|
||||
|
||||
# Obtener orígenes de visitas por host
|
||||
AccessLog.where(host: host).distinct(:http_referer).pluck(:http_referer).each do |http_referer|
|
||||
rollup('host|referer', beginning, host: host, http_referer: http_referer)
|
||||
dimensions[:http_referer] = http_referer
|
||||
|
||||
rollup('host|referer', beginning, **dimensions)
|
||||
reduce_rollup('host|referer', beginning, **dimensions)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,8 +73,7 @@ class UriCollectionJob < PeriodicJob
|
|||
|
||||
private
|
||||
|
||||
# Generar un rollup a partir de unas dimensiones que también sirven de
|
||||
# filtro.
|
||||
# Generar un rollup de access logs
|
||||
#
|
||||
# @param :name [String]
|
||||
# @param :beginning [Time]
|
||||
|
@ -67,9 +86,16 @@ class UriCollectionJob < PeriodicJob
|
|||
.non_robots
|
||||
.group(*dimensions.keys)
|
||||
.rollup(name, interval: starting_interval, update: true)
|
||||
end
|
||||
|
||||
# Reducir las estadísticas calculadas aplicando un rollup sobre el
|
||||
# intervalo más amplio.
|
||||
#
|
||||
# @param :name [String]
|
||||
# @param :beginning [Time]
|
||||
# @param :dimensions [Hash]
|
||||
# @return [nil]
|
||||
def reduce_rollup(name, beginning, **dimensions)
|
||||
Stat::INTERVALS.reduce do |previous, current|
|
||||
recursive_rollup(name: name,
|
||||
interval_previous: previous,
|
||||
|
@ -80,6 +106,8 @@ class UriCollectionJob < PeriodicJob
|
|||
# Devolver el intervalo actual
|
||||
current
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def stat_name
|
||||
|
|
Loading…
Reference in a new issue