Révision a89da38d
adding scanlog plugin and images
- a couple of images: for ** ejabberd_scanlog ** netstat_bsd_ ** tcp_retries
- ejabberd_scanlog plugin
| plugins/ejabberd/ejabberd_scanlog | ||
|---|---|---|
| 1 |
#!/usr/bin/env ruby |
|
| 2 |
require 'yaml' |
|
| 3 |
|
|
| 4 |
# ejabberd_scanlog revision 1 (Feb 2012) |
|
| 5 |
# |
|
| 6 |
# Scans ejabberd 2.1.x log for known error signatures and counts them |
|
| 7 |
# |
|
| 8 |
# Required privileges: read ejabberd log (user ejabberd or, in some cases, root) |
|
| 9 |
# |
|
| 10 |
# OS: Unix |
|
| 11 |
# |
|
| 12 |
# Configuration: |
|
| 13 |
# env.log: ejabberd log file (defaults to /var...) |
|
| 14 |
# |
|
| 15 |
# Author: Artem Sheremet <dot.doom@gmail.com> |
|
| 16 |
# |
|
| 17 |
|
|
| 18 |
LOG_FILE = ENV['log'] || '/var/log/ejabberd/ejabberd.log' |
|
| 19 |
CACHE_FILE = '/tmp/ejabberd_scanlog_cache' # cache file position |
|
| 20 |
|
|
| 21 |
DEFAULT_CACHE = { :start => 0 }
|
|
| 22 |
|
|
| 23 |
debug_mode = ARGV.first == 'debug' |
|
| 24 |
|
|
| 25 |
begin |
|
| 26 |
log_info = YAML.load IO.read(CACHE_FILE) |
|
| 27 |
rescue |
|
| 28 |
log_info = DEFAULT_CACHE |
|
| 29 |
end |
|
| 30 |
|
|
| 31 |
if File.size(LOG_FILE) < log_info[:start] |
|
| 32 |
# logrotate? |
|
| 33 |
log_info = DEFAULT_CACHE |
|
| 34 |
end |
|
| 35 |
|
|
| 36 |
new_data = '' |
|
| 37 |
File.open(LOG_FILE, 'r') do |flog| |
|
| 38 |
flog.seek(log_info[:start]) |
|
| 39 |
new_data = flog.read |
|
| 40 |
end |
|
| 41 |
|
|
| 42 |
LABELS = {
|
|
| 43 |
:wait_for => 'EJAB-1482 Crash when waiting for item', |
|
| 44 |
:ejabberd_odbc_failure => 'EJAB-1483 ODBC sup failure (wrong PID?)', |
|
| 45 |
:ejabberd_odbc_failure_echo => 'EJAB-1483 ODBC sup wrong PID failure echo', |
|
| 46 |
:dns => 'DNS failure', |
|
| 47 |
:database => 'Database unavailable/too slow', |
|
| 48 |
:auth_error => 'The auth module returned an error', |
|
| 49 |
:timeout => 'State machine terminated: timeout', |
|
| 50 |
:mysql_shutdown => 'MySQL disconnected', |
|
| 51 |
:mysql_refused => 'Connecting to MySQL: failed', |
|
| 52 |
:hook_timeout => 'Timeout while running a hook', |
|
| 53 |
:sql_transactions_exceeded => 'SQL transaction restarts exceeded', |
|
| 54 |
:unexpected_info => 'Unexpected info', |
|
| 55 |
:other_sql_cmd_timeout => 'Other sql_cmd timeout', |
|
| 56 |
:UNKNOWN => 'Unknown error/warning' |
|
| 57 |
} |
|
| 58 |
def log_type(text) |
|
| 59 |
if text.include? 'ejabberd_odbc_sup' |
|
| 60 |
:ejabberd_odbc_failure |
|
| 61 |
elsif text.include? "mod_pubsub_odbc,'-unsubscribe" |
|
| 62 |
:ejabberd_odbc_failure_echo |
|
| 63 |
elsif text.include? 'You should check your DNS configuration' |
|
| 64 |
:dns |
|
| 65 |
elsif text.include? 'Database was not available or too slow' |
|
| 66 |
:database |
|
| 67 |
elsif text.include? 'wait_for_' |
|
| 68 |
:wait_for |
|
| 69 |
elsif text.include?('State machine') and
|
|
| 70 |
text.include?('terminating') and
|
|
| 71 |
text.include?('Reason for') and
|
|
| 72 |
text.include?('timeout')
|
|
| 73 |
:timeout |
|
| 74 |
elsif text.include?('The authentication module') and
|
|
| 75 |
text.include?('returned an error')
|
|
| 76 |
:auth_error |
|
| 77 |
elsif text.include?('mysql') and text.include?('Received unknown signal, exiting')
|
|
| 78 |
:mysql_shutdown |
|
| 79 |
elsif text.include?('mysql') and text.include?('Failed connecting to')
|
|
| 80 |
:mysql_refused |
|
| 81 |
elsif text.include?('ejabberd_hooks') and text.include?('timeout')
|
|
| 82 |
:hook_timeout |
|
| 83 |
elsif text.include?('SQL transaction restarts exceeded')
|
|
| 84 |
:sql_transactions_exceeded |
|
| 85 |
elsif text.include?('nexpected info')
|
|
| 86 |
:unexpected_info |
|
| 87 |
elsif text.include?('timeout') and text.include?('sql_cmd')
|
|
| 88 |
:other_sql_cmd_timeout |
|
| 89 |
else |
|
| 90 |
puts "Cannot parse text: #{text}" if debug_mode
|
|
| 91 |
:UNKNOWN |
|
| 92 |
end |
|
| 93 |
end |
|
| 94 |
|
|
| 95 |
new_data.split("\n=").each { |report|
|
|
| 96 |
next if report.empty? |
|
| 97 |
report =~ /\A(\w+) REPORT==== (.*) ===\n(.*)\z/m |
|
| 98 |
type, time, text = $1, $2, $3 |
|
| 99 |
next unless type and time and text |
|
| 100 |
|
|
| 101 |
log_info[type] = (log_info[type] || 0) + 1 |
|
| 102 |
if sub_type = log_type(text) |
|
| 103 |
log_info[sub_type] = (log_info[sub_type] || 0) + 1 |
|
| 104 |
end |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
log_info[:start] += new_data.size |
|
| 108 |
File.open(CACHE_FILE, 'w') { |f| f.write log_info.to_yaml }
|
|
| 109 |
|
|
| 110 |
if ARGV.first == 'config' |
|
| 111 |
puts <<CONFIG |
|
| 112 |
graph_title Ejabberd Log |
|
| 113 |
graph_vtitle Report count |
|
| 114 |
graph_category ejabberd |
|
| 115 |
graph_args -l 0 |
|
| 116 |
graph_order #{(LABELS.keys + log_info.keys.select { |k| k.is_a? String }.sort).join(' ')}
|
|
| 117 |
CONFIG |
|
| 118 |
end |
|
| 119 |
|
|
| 120 |
first = true |
|
| 121 |
LABELS.each_pair { |type,label|
|
|
| 122 |
if ARGV.first == 'config' |
|
| 123 |
puts "#{type}.label #{label}"
|
|
| 124 |
puts "#{type}.draw #{
|
|
| 125 |
if first |
|
| 126 |
first = false |
|
| 127 |
'AREA' |
|
| 128 |
else |
|
| 129 |
'STACK' |
|
| 130 |
end |
|
| 131 |
}" |
|
| 132 |
else |
|
| 133 |
puts "#{type}.value #{log_info[type] or 0}"
|
|
| 134 |
end |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
log_info.each_pair { |k,value|
|
|
| 138 |
unless k == :start |
|
| 139 |
if k.is_a? String |
|
| 140 |
if ARGV.first == 'config' |
|
| 141 |
puts "#{k}.label #{k}"
|
|
| 142 |
puts "#{k}.draw LINE2"
|
|
| 143 |
else |
|
| 144 |
puts "#{k}.value #{value}"
|
|
| 145 |
end |
|
| 146 |
end |
|
| 147 |
end |
|
| 148 |
} |
|
Formats disponibles : Unified diff