rails-log-viewer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/UTF-8 +0 -0
- data/bin/fetch-log +35 -0
- data/bin/read-log +71 -0
- data/json +0 -0
- data/lib/log/parser.rb +41 -0
- data/lib/log/parser/version.rb +5 -0
- data/log-parser.gemspec +26 -0
- data/rails logs b/data/rails → logs +0 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f71d55ec4d0b129b9518234958e3f60529331578
|
4
|
+
data.tar.gz: 75d1e75904723e63cbe5d64a45f7f0eff4d0906c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f42bf40d716406ffbdfd67bd85f64a5bf2da524b61bd722e5951404df5308dc1336b27358d38b777e2fab78c14ed782a8bcd3b36c44c3be153eacb504d77bff
|
7
|
+
data.tar.gz: e179836cde88125f870083d5fd74137218863cabe450fe05ef881f85280c2045a8dc48396bb04e9462347e8a6651f367bc8bbc2fd57926aab7f7c6929a688754
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 leo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Log::Parser
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'log-parser'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install log-parser
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/UTF-8
ADDED
File without changes
|
data/bin/fetch-log
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'log/parser'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
dir = File.join(Dir.home, '.log-parser')
|
6
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
7
|
+
config = File.join(dir, '.config')
|
8
|
+
def configure
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
if ARGV.empty? and File.exists? config
|
13
|
+
options = JSON.parse(IO.read(config))
|
14
|
+
Log::Parser.fetch_log options['server'], options['remote_path'], options['user_name'], options['password']
|
15
|
+
exit(0)
|
16
|
+
elsif ARGV.empty?
|
17
|
+
puts 'What is the address of the remote server ?'
|
18
|
+
options = {}
|
19
|
+
options[:server] = gets.chomp
|
20
|
+
puts 'What the path of the log on the remote host ?'
|
21
|
+
options[:remote_path] = gets.chomp
|
22
|
+
puts 'What is the user name ?'
|
23
|
+
options[:user_name] = gets.chomp
|
24
|
+
puts 'What is the password ? (ignore it if you have public key)'
|
25
|
+
options[:password] = gets.chomp unless gets.chomp == ''
|
26
|
+
puts 'Is that correct(y/n) :'+"\nserver address: #{options[:server]}\n log path: #{options[:remote_path]}\n username: #{options[:user_name]}\npassword: ********"
|
27
|
+
if gets.chomp == 'y'
|
28
|
+
IO.write(config, options.to_json)
|
29
|
+
else
|
30
|
+
puts 'config aborted.'
|
31
|
+
end
|
32
|
+
exit(0)
|
33
|
+
else
|
34
|
+
Log::Parser.fetch_log ARGV[0], ARGV[1], ARGV[2], ARGV[3]
|
35
|
+
end
|
data/bin/read-log
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'log/parser'
|
3
|
+
Log::Parser.create_log_file
|
4
|
+
dir = File.join(Dir.home, '.log-parser')
|
5
|
+
config = File.join(dir, '.read-config')
|
6
|
+
case ARGV[0]
|
7
|
+
when 'quit'
|
8
|
+
pid = IO.read(File.join(dir, 'logstash.pid'))
|
9
|
+
Process.kill(9, pid.to_i)
|
10
|
+
puts 'logstash killed.'
|
11
|
+
exit(0)
|
12
|
+
when 'reset'
|
13
|
+
FileUtils.rm File.join(dir, '.line'), force: true
|
14
|
+
puts 'Parsing log file from beginning'
|
15
|
+
exit(0)
|
16
|
+
when 'config'
|
17
|
+
IO.write(config, ARGV[1])
|
18
|
+
puts 'config file written.'
|
19
|
+
exit(0)
|
20
|
+
end
|
21
|
+
|
22
|
+
quickstart = File.join(dir, 'quickstart.conf')
|
23
|
+
quistart_content = <<-EOD
|
24
|
+
input {
|
25
|
+
file {
|
26
|
+
type => "rails logs"
|
27
|
+
path => "#{File.join(dir, 'logstash.log')}"
|
28
|
+
codec => json {
|
29
|
+
charset => "UTF-8"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
filter {
|
35
|
+
if [fields][ip] {
|
36
|
+
geoip {
|
37
|
+
source => "[fields][ip]"
|
38
|
+
target => "geoip"
|
39
|
+
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
|
40
|
+
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
|
41
|
+
}
|
42
|
+
mutate {
|
43
|
+
convert => [ "[geoip][coordinates]", "float" ]
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
output {
|
49
|
+
# Print each event to stdout.
|
50
|
+
stdout {
|
51
|
+
codec => rubydebug
|
52
|
+
}
|
53
|
+
|
54
|
+
elasticsearch {
|
55
|
+
embedded => true
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
EOD
|
60
|
+
|
61
|
+
IO.write(quickstart, quistart_content)
|
62
|
+
if ARGV.empty?
|
63
|
+
logstash = IO.read(config)
|
64
|
+
else
|
65
|
+
logstash = ARGV[0]
|
66
|
+
end
|
67
|
+
puts 'Copy and execute this line:'
|
68
|
+
puts "JAVA_OPTS=-Des.path.data=\"#{dir}\" #{logstash} agent -f #{quickstart} -- web & echo $! > #{File.join(dir, 'logstash.pid')}"
|
69
|
+
puts 'and run fetch-log'
|
70
|
+
puts 'run read-log quit to quit logstash'
|
71
|
+
puts 'run read-log reset to parse the log file from beginning'
|
data/json
ADDED
File without changes
|
data/lib/log/parser.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "log/parser/version"
|
2
|
+
require 'net/scp'
|
3
|
+
|
4
|
+
module Log
|
5
|
+
module Parser
|
6
|
+
def self.create_log_file
|
7
|
+
dir = File.join(Dir.home, '.log-parser')
|
8
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
9
|
+
File.open(File.join(dir, 'logstash.log'), 'a+').close unless File.exists? File.join(dir, 'logstash.log')
|
10
|
+
end
|
11
|
+
def self.fetch_log(server, remote_path, user_name, password)
|
12
|
+
dir = File.join(Dir.home, '.log-parser')
|
13
|
+
log = File.join(dir, 'tmp.log')
|
14
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
15
|
+
puts 'fetching log...'
|
16
|
+
Net::SCP::download!(server, user_name, remote_path, log)
|
17
|
+
puts 'reading log...'
|
18
|
+
file_line_path = File.join(dir, '.line')
|
19
|
+
if File.exists? file_line_path
|
20
|
+
line_nb = IO.read(file_line_path).to_i
|
21
|
+
else
|
22
|
+
line_nb = nil
|
23
|
+
end
|
24
|
+
file = File.open(log, 'r')
|
25
|
+
count = 0
|
26
|
+
log_file = File.open(File.join(dir, 'logstash.log'), 'a+')
|
27
|
+
while !file.eof?
|
28
|
+
count+=1
|
29
|
+
line = file.readline
|
30
|
+
if line_nb.nil? or line_nb < count
|
31
|
+
log_file.write(line)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
log_file.close
|
35
|
+
file_line = File.new(file_line_path, 'w+')
|
36
|
+
file_line.write(count.to_s+'\n')
|
37
|
+
file_line.close
|
38
|
+
file.close
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/log-parser.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'log/parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails-log-viewer"
|
8
|
+
spec.version = Log::Parser::VERSION
|
9
|
+
spec.authors = ["leo"]
|
10
|
+
spec.email = ["facenord.sud@gmail.com"]
|
11
|
+
spec.description = %q{fetch logstasher file log from remote server and add it to a local log files. Start logstash, elastic search and kibana but need executable in path}
|
12
|
+
spec.summary = %q{see description}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables << 'fetch-log'
|
18
|
+
spec.executables << 'read-log'
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_dependency 'net-scp'
|
25
|
+
spec.add_dependency 'json'
|
26
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-log-viewer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- leo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-scp
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: fetch logstasher file log from remote server and add it to a local log
|
70
|
+
files. Start logstash, elastic search and kibana but need executable in path
|
71
|
+
email:
|
72
|
+
- facenord.sud@gmail.com
|
73
|
+
executables:
|
74
|
+
- fetch-log
|
75
|
+
- read-log
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- UTF-8
|
85
|
+
- bin/fetch-log
|
86
|
+
- bin/read-log
|
87
|
+
- json
|
88
|
+
- lib/log/parser.rb
|
89
|
+
- lib/log/parser/version.rb
|
90
|
+
- log-parser.gemspec
|
91
|
+
- rails logs
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: see description
|
116
|
+
test_files: []
|