You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/lib/cartodb_stats.rb

93 lines
2.5 KiB

class CartodbStats
class << self
def update_tables_counter(count)
begin
if count == 1
Statsd.increment('tables.total')
elsif count == -1
Statsd.decrement('tables.total')
end
rescue => e
end
end
def update_tables_counter_per_user(count, user)
begin
if count == 1
Statsd.increment("tables.users.#{user}")
elsif count == -1
Statsd.decrement("tables.users.#{user}")
end
rescue => e
end
end
def update_tables_counter_per_host(count)
require 'socket'
begin
if count == 1
Statsd.increment("tables.hosts.#{Socket.gethostname.gsub('.', '_')}")
elsif count == -1
Statsd.decrement("tables.hosts.#{Socket.gethostname.gsub('.', '_')}")
end
rescue => e
end
end
def update_tables_counter_per_plan(count, plan)
begin
if count == 1
Statsd.increment("tables.plans.#{plan.gsub(/[\[\]]/, '').upcase}")
elsif count == -1
Statsd.decrement("tables.plans.#{plan.gsub(/[\[\]]/, '').upcase}")
end
rescue => e
end
end
def increment_imports()
require 'socket'
begin
Statsd.increment("imports.success.total")
Statsd.increment("imports.success.servers.#{Socket.gethostname.gsub('.', '_')}")
rescue => e
end
end
def increment_failed_imports()
require 'socket'
begin
Statsd.increment("imports.failed.total")
Statsd.increment("imports.failed.hosts.#{Socket.gethostname.gsub('.', '_')}")
rescue => e
end
end
def increment_login_counter(email)
begin
u = User.select(:username).filter(:email => email).or(:username => email).first
username = u ? u.username : 'UNKNOWN'
Statsd.increment("logins.success.total")
Statsd.increment("logins.success.hosts.#{Socket.gethostname.gsub('.', '_')}")
Statsd.increment("logins.success.users.#{username}")
rescue => e
end
end
def increment_failed_login_counter(email)
begin
u = User.select(:username).filter(:email => email).or(:username => email).first
username = u ? u.username : 'UNKNOWN'
Statsd.increment("logins.failed.total")
Statsd.increment("logins.failed.hosts.#{Socket.gethostname.gsub('.', '_')}")
Statsd.increment("logins.failed.users.#{username}")
rescue => e
end
end
end
end