5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 13:21:41 +00:00

recolectar estadísticas de referers

This commit is contained in:
f 2022-04-26 16:59:02 -03:00
parent 5186892a87
commit be6224ddf1

View file

@ -24,7 +24,6 @@ class UriCollectionJob < PeriodicJob
# Recordar la última vez que se corrió la tarea
stat = site.stats.create! name: STAT_NAME
name = 'host|uri'
beginning = beginning_of_interval
site.hostnames.each do |host|
@ -33,10 +32,18 @@ class UriCollectionJob < PeriodicJob
uris.each do |uri|
break if stop?
rollup_uri(uri, host, name, beginning)
rollup('host|uri', beginning, host: host, 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
end
rollup_host(host, name, beginning)
rollup('host', beginning, host: 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)
end
end
stat.touch
@ -46,9 +53,14 @@ class UriCollectionJob < PeriodicJob
private
def rollup_uri(uri, host, name, beginning)
dimensions = { host: host, uri: uri }
# Generar un rollup a partir de unas dimensiones que también sirven de
# filtro.
#
# @param :name [String]
# @param :beginning [Time]
# @param :dimensions [Hash]
# @return [nil]
def rollup(name, beginning, **dimensions)
AccessLog.where(**dimensions)
.where('created_at >= ?', beginning)
.completed_requests
@ -70,28 +82,6 @@ class UriCollectionJob < PeriodicJob
end
end
def rollup_host(host, name, beginning)
dimensions = { host: host }
new_name = 'host'
recursive_rollup(name: name,
new_name: new_name,
interval_previous: starting_interval,
interval: starting_interval,
dimensions: dimensions,
beginning: beginning)
Stat::INTERVALS.reduce do |previous, current|
recursive_rollup(name: new_name,
interval_previous: previous,
interval: current,
dimensions: dimensions,
beginning: beginning)
current
end
end
def stat_name
STAT_NAME
end