DEV: remove NGINX performance report

This report is no longer supported or tested, it was moved to:

https://github.com/SamSaffron/discourse-nginx-performance-report

The new home for the performance report means this is no longer an official
Discourse plugin
This commit is contained in:
Sam Saffron 2019-11-18 15:30:42 +11:00
parent af091c49e9
commit e2ccb0c608
52 changed files with 0 additions and 821 deletions

View File

@ -1,58 +0,0 @@
# frozen_string_literal: true
module Jobs
class DailyPerformanceReport < ::Jobs::Scheduled
every 1.day
per_host
def execute(args)
if SiteSetting.daily_performance_report &&
RailsMultisite::ConnectionManagement.current_db == "default"
result = `ruby #{Rails.root}/plugins/discourse-nginx-performance-report/script/nginx_analyze.rb --limit 1440`
report_data =
if result.strip.empty?
<<~TEXT
Report is only available in latest image, please run:
```text
cd /var/discourse
./launcher rebuild app
```
TEXT
else
"```text\n#{result}\n```"
end
PostCreator.create(Discourse.system_user,
topic_id: performance_topic_id,
raw: report_data,
skip_validations: true)
end
end
def performance_topic_id
if SiteSetting.performance_report_topic_id > 0
topic = Topic.find_by(id: SiteSetting.performance_report_topic_id)
return topic.id if topic
end
staff_category = Category.find_by(id: SiteSetting.staff_category_id)
raise StandardError, "Staff category was not found" unless staff_category
post = PostCreator.create(Discourse.system_user,
raw: I18n.t('performance_report.initial_post_raw'),
category: staff_category.name,
title: I18n.t('performance_report.initial_topic_title'),
skip_validations: true)
unless post && post.topic_id
raise StandardError, "Could not create or retrieve performance report topic id"
end
SiteSetting.performance_report_topic_id = post.topic_id
end
end
end

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ar:
site_settings:
daily_performance_report: "تحليل سجلّات الخادم NGINX يوميًا ونشر موضوع مفصّل مع طاقم الموقع"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
be: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
bg:
site_settings:
daily_performance_report: "Ежедневно анализирай на NGINX логовете в публиковай в темата която е само за екипа с детайли."

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
bs_BA:
site_settings:
daily_performance_report: "Analiziraj NGINX logove dnevno i objavljuj u Staff Only temu sa detaljima"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ca:
site_settings:
daily_performance_report: "Analitza els registres (logs) de NGINX diàriament, i publica un tema sols per a l'equip responsable amb els detalls."

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
cs:
site_settings:
daily_performance_report: "Analyzovat denní logy NGINX a zaslat téma s podrobnostmi přístupné pouze členům redakce."

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
da:
site_settings:
daily_performance_report: "Analysér NGINX-logfiler dagligt, og send et 'kun hjælperteam'-emne med detaljer"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
de:
site_settings:
daily_performance_report: "Analysiere die NGINX-Logs täglich. Poste anschließend eine Zusammenfassung als Beitrag, welcher nur für Moderatoren oder Administratoren zugänglich ist."

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
el: {}

View File

@ -1,3 +0,0 @@
en:
site_settings:
daily_performance_report: "Analyze NGINX logs daily and post a Staff Only topic with details"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
es:
site_settings:
daily_performance_report: "Analizar los registros de NGINX diariamente y publicar un tema solo para el staff con detalles"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
et: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
fa_IR:
site_settings:
daily_performance_report: "تحلیل لاگ‌های NGINX و ارسال یک پست شامل جزئیات ویژه مدیران"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
fi:
site_settings:
daily_performance_report: "Analysoi NGINX lokit päivittäin ja julkaise vain henkilökunnalle näkyvä ketju yksityiskohdista"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
fr:
site_settings:
daily_performance_report: "Analyser les logs de NGINX quotidiennement et poster un sujet Responsables Uniquement avec les détails"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
gl: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
he:
site_settings:
daily_performance_report: "Analyze NGINX logs daily and post a Staff Only topic with details"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
hu:
site_settings:
daily_performance_report: "NGINX naplók napi elemzése és egy csak stábtagoknak téma létrehozása a részletekkel"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
hy:
site_settings:
daily_performance_report: "Վերլուծեք NGINX-ի գրառումներն ամեն օր և մանրամասները հրապարակեք Միայն ԱՆձնակազմի համար թեմայում"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
id: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
it:
site_settings:
daily_performance_report: "Analizza i log di NGINX giornalmente, e pubblica un argomento con i dettagli visibile solo allo Staff"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ja:
site_settings:
daily_performance_report: "日別のNGINXのログを解析し、Staff Onlyトピックへ詳細を投稿する"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ko:
site_settings:
daily_performance_report: "NGINX 일별 로그를 분석하고 상세정보를 스태프들에게 글타래 게시"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
lt:
site_settings:
daily_performance_report: "Analizuokite NGINX logs kasdien ir paskelbkite \"Staff Only\" temą su detalėmis"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
lv: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
nb_NO:
site_settings:
daily_performance_report: "Analyser NGINX logger hver dag og opprett et emne for Staben med detaljer "

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
nl:
site_settings:
daily_performance_report: "Analyseer elke dag NGINX logs en post een Alleen Voor Medewerkers topic met de details"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
pl_PL:
site_settings:
daily_performance_report: "Analizuj logi NGINX codziennie i umieszczaj szczegóły w temacie widocznym tylko dla członków zespołu"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
pt:
site_settings:
daily_performance_report: "Analise os logs diários NGINX e publique um tópico visível apenas para o pessoal com detalhes"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
pt_BR:
site_settings:
daily_performance_report: "Analizar logs do NGINX diariamente e postar um tópico somente para a Staff com os detalhes"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ro: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ru:
site_settings:
daily_performance_report: "Ежедневно анализировать логи сервера NGINX и отправлять сообщение с результатами анализа в тему, видимую только персоналу."

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sk:
site_settings:
daily_performance_report: "Denne analyzuj NGINX logy a z detailov vytváraj témy iba pre zamestnancov."

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sl: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sq:
site_settings:
daily_performance_report: "Analyze NGINX logs daily and post a Staff Only topic with details"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sr: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sv:
site_settings:
daily_performance_report: "Analysera NGINX-loggar dagligen och skriv ett inlägg för personalen med detaljerna"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
sw:
site_settings:
daily_performance_report: "Pitia batli za NGINX kila siku na chapisha mada za wasaidizi tu pamoja na maelezo"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
te: {}

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
th: {}

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
tr_TR:
site_settings:
daily_performance_report: "NGINX kayıtlarını analiz edip detaylı bir şekilde günlük Yetkili kategorisinde bir konu içerisinde paylaş."

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
uk:
site_settings:
daily_performance_report: "Щодня аналізуйте журнали NGINX та публікуйте тему лише для персоналу з деталями"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
ur:
site_settings:
daily_performance_report: "Analyze NGINX logs daily and post a Staff Only topic with details"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
vi:
site_settings:
daily_performance_report: "Phân tích nhật ký NGINX hàng ngày và gửi cho BQT thông tin chi tiết"

View File

@ -1,10 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
zh_CN:
site_settings:
daily_performance_report: "每日分析 NGINX 日志并且发布详情主题到管理人员才能看到的主题"

View File

@ -1,8 +0,0 @@
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
#
# To work with us on translations, join this project:
# https://www.transifex.com/projects/p/discourse-org/
zh_TW: {}

View File

@ -1,6 +0,0 @@
plugins:
# Reporting
daily_performance_report: false
performance_report_topic_id:
default: -1
hidden: true

View File

@ -1,158 +0,0 @@
# frozen_string_literal: true
class LogAnalyzer
class LineParser
# log_format log_discourse '[$time_local] "$http_host" $remote_addr "$request" "$http_user_agent" "$sent_http_x_discourse_route" $status $bytes_sent "$http_referer" $upstream_response_time $request_time "$sent_http_x_discourse_username"';
attr_accessor :time, :ip_address, :url, :route, :user_agent, :rails_duration, :total_duration,
:username, :status, :bytes_sent, :referer
PATTERN = /\[(.*)\](?: ".*")? (\S+) \"(.*)\" \"(.*)\" \"(.*)\" ([0-9]+) ([0-9]+) \"(.*)\" ([0-9.]+) ([0-9.]+) "(.*)"/
TIME_FORMAT = "%d/%b/%Y:%H:%M:%S %Z"
def self.parse(line)
result = new
_, result.time, result.ip_address, result.url, result.user_agent,
result.route, result.status, result.bytes_sent, result.referer,
result.rails_duration, result.total_duration, result.username = line.match(PATTERN).to_a
result.rails_duration = result.rails_duration.to_f
result.total_duration = result.total_duration.to_f
verb = result.url[0..3] if result.url
if verb && verb == "POST"
result.route += " (POST)"
end
if verb && verb == "PUT"
result.route += " (PUT)"
end
result.url = self.sanitize_url(result.url) if result.url
result
end
def is_mobile?
user_agent =~ /Mobile|Android|webOS/ && !(user_agent =~ /iPad|Nexus (7|10)/)
end
def parsed_time
DateTime.strptime(time, TIME_FORMAT) if time
end
private
def self.sanitize_url(url)
url.gsub(/api_key=([\w.\-]+)/, 'api_key=[FILTERED]')
end
end
attr_reader :total_requests, :message_bus_requests, :filenames,
:ip_to_rails_duration, :username_to_rails_duration,
:route_to_rails_duration, :url_to_rails_duration,
:status_404_to_count, :from_time, :to_time
def self.analyze(filenames, args)
new(filenames, args).analyze
end
class Aggeregator
attr_accessor :aggregate_type
def initialize
@data = {}
@aggregate_type = :duration
end
def add(id, duration, aggregate = nil)
ary = (@data[id] ||= [0, 0])
ary[0] += duration
ary[1] += 1
unless aggregate.nil?
ary[2] ||= Hash.new(0)
if @aggregate_type == :duration
ary[2][aggregate] += duration
elsif @aggregate_type == :count
ary[2][aggregate] += 1
end
end
end
def top(n, aggregator_formatter = nil)
@data.sort { |a, b| b[1][0] <=> a[1][0] }.first(n).map do |metric, ary|
metric = metric.to_s
metric = "[empty]" if metric.length == 0
result = [metric, ary[0], ary[1]]
# handle aggregate
if ary[2]
if aggregator_formatter
result.push aggregator_formatter.call(ary[2], ary[0], ary[1])
else
result.push ary[2].sort { |a, b| b[1] <=> a[1] }.first(5).map { |k, v|
v = "%.2f" % v if Float === v
"#{k}(#{v})"}.join(" ")
end
end
result
end
end
end
def initialize(filenames, args = {})
@filenames = filenames
@ip_to_rails_duration = Aggeregator.new
@username_to_rails_duration = Aggeregator.new
@route_to_rails_duration = Aggeregator.new
@route_to_rails_duration.aggregate_type = :count
@url_to_rails_duration = Aggeregator.new
@status_404_to_count = Aggeregator.new
@total_requests = 0
@message_bus_requests = 0
@limit = args[:limit]
end
def analyze
now = DateTime.now
@filenames.each do |filename|
File.open(filename).each_line do |line|
@total_requests += 1
parsed = LineParser.parse(line)
next unless parsed.time
next if @limit && ((now - parsed.parsed_time) * 24 * 60).to_i > @limit
@from_time ||= parsed.time
@to_time = parsed.time
if parsed.url =~ /(POST|GET) \/message-bus/
@message_bus_requests += 1
next
end
@ip_to_rails_duration.add(parsed.ip_address, parsed.rails_duration)
username = parsed.username == "-" ? "[Anonymous]" : parsed.username
@username_to_rails_duration.add(username, parsed.rails_duration, parsed.route)
@route_to_rails_duration.add(parsed.route, parsed.rails_duration, parsed.is_mobile? ? "mobile" : "desktop")
@url_to_rails_duration.add(parsed.url, parsed.rails_duration)
@status_404_to_count.add(parsed.url, 1) if parsed.status == "404"
end
end
self
end
end

View File

@ -1,14 +0,0 @@
# frozen_string_literal: true
# name: discourse-nginx-performance-report
# about: Analyzing Discourse Performance using NGINX logs
# version: 0.1
# url: https://github.com/discourse/discourse/tree/master/plugins/discourse-nginx-performance-report
enabled_site_setting :daily_performance_report
enabled_site_setting_filter "daily_performance_report"
hide_plugin if self.respond_to?(:hide_plugin)
after_initialize do
load File.expand_path("../app/jobs/scheduled/daily_performance_report.rb", __FILE__)
end

View File

@ -1,141 +0,0 @@
# frozen_string_literal: true
require 'date'
require_relative '../lib/log_analyzer'
args = ARGV.dup
if args[0] == "--limit"
args.shift
limit = args.shift.to_i
end
filenames = args if args[0]
filenames ||= ["/var/log/nginx/access.log", "/var/log/nginx/access.log.1"]
analyzer = LogAnalyzer.analyze(filenames, limit: limit)
SPACER = "-" * 100
# don't feel like pulling in active support
def map_with_index(ary, &block)
idx = 0
ary.map do |item|
v = block.call(item, idx)
idx += 1
v
end
end
def top(cols, aggregator, count, aggregator_formatter = nil)
sorted = aggregator.top(count, aggregator_formatter)
col_just = []
col_widths = map_with_index(cols) do |name, idx|
max_width = name.length
if cols[idx].respond_to? :align
col_just[idx] = cols[idx].align
skip_just_detection = true
else
col_just[idx] = :ljust
end
sorted.each do |row|
col_just[idx] = :rjust unless (String === row[idx] || row[idx].nil?) && !skip_just_detection
row[idx] = '%.2f' % row[idx] if Float === row[idx]
row[idx] = row[idx].to_s
max_width = row[idx].length if row[idx].length > max_width
end
[max_width, 80].min
end
puts(map_with_index(cols) do |name, idx|
name.ljust(col_widths[idx])
end.join(" "))
puts(map_with_index(cols) do |name, idx|
("-" * name.length).ljust(col_widths[idx])
end.join(" "))
sorted.each do |raw_row|
rows = []
idx = 0
raw_row.each do |col|
j = 0
col.to_s.scan(/(.{1,80}($|\s)|.{1,80})/).each do |r|
rows[j] ||= []
rows[j][idx] = r[0]
j += 1
end
idx += 1
end
if rows.length > 1
puts
end
rows.each do |row|
cols.length.times do |i|
print row[i].to_s.public_send(col_just[i], col_widths[i])
print " "
end
puts
end
if rows.length > 1
puts
end
end
end
class Column < String
attr_accessor :align
def initialize(val, align)
super(val)
@align = align
end
end
puts
puts "Analyzed: #{analyzer.filenames.join(",")} on #{`hostname`}"
if limit
puts "Limited to #{DateTime.now - (limit.to_f / (60 * 24.0))} - #{DateTime.now}"
end
puts SPACER
puts "#{analyzer.from_time} - #{analyzer.to_time}"
puts SPACER
puts "Total Requests: #{analyzer.total_requests} ( MessageBus: #{analyzer.message_bus_requests} )"
puts SPACER
puts "Top 30 IPs by Server Load"
puts
top(["IP Address", "Duration", "Reqs"], analyzer.ip_to_rails_duration, 30)
puts SPACER
puts
puts "Top 30 users by Server Load"
puts
top(["Username", "Duration", "Reqs", "Routes"], analyzer.username_to_rails_duration, 30)
puts SPACER
puts
puts "Top 100 routes by Server Load"
puts
top(["Route", "Duration", "Reqs", Column.new("Mobile", :rjust)], analyzer.route_to_rails_duration, 100, lambda {
|hash, name, total|
"#{hash["mobile"] || 0} (#{"%.2f" % (((hash["mobile"] || 0) / (total + 0.0)) * 100)})%"}
)
puts SPACER
puts
puts "Top 30 urls by Server Load"
puts
top(["Url", "Duration", "Reqs"], analyzer.url_to_rails_duration, 30)
puts "(all durations in seconds)"
puts SPACER
puts
puts "Top 30 not found urls (404s)"
puts
top(["Url", "Count"], analyzer.status_404_to_count, 30)

View File

@ -1,15 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
require_relative '../lib/log_analyzer'
describe LogAnalyzer::LineParser do
describe '.parse' do
let(:line) { '[22/Sep/2016:07:32:00 +0000] 172.0.0.1 "GET /about.json?api_username=system&api_key=1234567 HTTP/1.1" "Some usename" "about/index" 200 1641 "-" 0.014 0.014 "system"' }
it "should filter out the api_key" do
result = described_class.parse(line)
expect(result.url).to eq('GET /about.json?api_username=system&api_key=[FILTERED] HTTP/1.1')
end
end
end