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

generar estadísticas de uso de infra

This commit is contained in:
f 2022-04-30 14:39:31 -03:00
parent 001443c1be
commit 6bf286077b
3 changed files with 33 additions and 43 deletions

View file

@ -46,6 +46,30 @@ module RecursiveRollup
end end
end end
# Reducir las estadísticas calculadas aplicando un rollup sobre el
# 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)
Stat::INTERVALS.reduce do |previous, current|
recursive_rollup(name: name,
interval_previous: previous,
interval: current,
dimensions: dimensions,
beginning: beginning,
operation: operation)
# Devolver el intervalo actual
current
end
nil
end
# @param :dimensions [Hash] # @param :dimensions [Hash]
# @return [Array] # @return [Array]
def dimensions_to_jsonb_query(dimensions) def dimensions_to_jsonb_query(dimensions)

View file

@ -9,10 +9,8 @@ class StatCollectionJob < PeriodicJob
def perform(site_id:, once: true) def perform(site_id:, once: true)
@site = Site.find site_id @site = Site.find site_id
# Registrar que se hicieron todas las recolecciones
stat = site.stats.create! name: STAT_NAME
beginning = beginning_of_interval beginning = beginning_of_interval
stat = site.stats.create! name: STAT_NAME
scope.rollup('builds', **options) scope.rollup('builds', **options)
@ -24,16 +22,9 @@ class StatCollectionJob < PeriodicJob
rollup.average(:seconds) rollup.average(:seconds)
end end
# XXX: Es correcto promediar promedios? reduce_rollup('builds', beginning, :sum, site_id: site_id)
Stat::INTERVALS.reduce do |previous, current| reduce_rollup('space_used', beginning, :average, site_id: site_id)
opts = { interval_previous: previous, interval: current, beginning: beginning, dimensions: { site_id: site.id } } reduce_rollup('build_time', beginning, :average, site_id: site_id)
recursive_rollup(name: 'builds', **opts)
recursive_rollup(name: 'space_used', operation: :average, **opts)
recursive_rollup(name: 'build_time', operation: :average, **opts)
current
end
stat.touch stat.touch
run_again! unless once run_again! unless once
@ -45,10 +36,7 @@ class StatCollectionJob < PeriodicJob
# #
# @return [ActiveRecord::Relation] # @return [ActiveRecord::Relation]
def scope def scope
@scope ||= site.build_stats @scope ||= site.build_stats.jekyll.where('created_at >= ?', beginning_of_interval)
.jekyll
.where('created_at >= ?', beginning_of_interval)
.group(:site_id)
end end
# Las opciones por defecto # Las opciones por defecto

View file

@ -52,7 +52,7 @@ class UriCollectionJob < PeriodicJob
dimensions = { host: host, uri: uri } dimensions = { host: host, uri: uri }
rollup(name, beginning, **dimensions) rollup(name, beginning, **dimensions)
reduce_rollup(name, beginning, **dimensions) reduce_rollup(name, beginning, :sum, **dimensions)
columns.each_pair do |column, values| columns.each_pair do |column, values|
# Obtener orígenes de visitas por host # Obtener orígenes de visitas por host
@ -62,7 +62,7 @@ class UriCollectionJob < PeriodicJob
column_dimensions[column] = value column_dimensions[column] = value
rollup(column_name, beginning, **column_dimensions) rollup(column_name, beginning, **column_dimensions)
reduce_rollup(column_name, beginning, **column_dimensions) reduce_rollup(column_name, beginning, :sum, **column_dimensions)
end end
end end
end end
@ -75,7 +75,7 @@ class UriCollectionJob < PeriodicJob
beginning: beginning) beginning: beginning)
# Acumular por mes y año # Acumular por mes y año
reduce_rollup('host', beginning, **host_dimensions) reduce_rollup('host', beginning, :sum, **host_dimensions)
columns.each_key do |column| columns.each_key do |column|
square_rollup(name: "host|uri|#{column}", square_rollup(name: "host|uri|#{column}",
@ -84,7 +84,7 @@ class UriCollectionJob < PeriodicJob
dimensions: host_dimensions, dimensions: host_dimensions,
beginning: beginning) beginning: beginning)
reduce_rollup("host|#{column}", beginning, **host_dimensions) reduce_rollup("host|#{column}", beginning, :sum, **host_dimensions)
end end
end end
@ -110,28 +110,6 @@ class UriCollectionJob < PeriodicJob
.rollup(name, interval: starting_interval, update: true) .rollup(name, interval: starting_interval, update: true)
end 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,
interval: current,
dimensions: dimensions,
beginning: beginning)
# Devolver el intervalo actual
current
end
nil
end
def stat_name def stat_name
STAT_NAME STAT_NAME
end end