l2met-syslog 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/l2met-syslog.gemspec +24 -0
- data/lib/l2met/syslog.rb +50 -0
- data/lib/l2met/syslog/version.rb +5 -0
- data/spec/lib/l2met/syslog_spec.rb +56 -0
- data/spec/spec_helper.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89b6a5bc8972020f892df655e3f0dff9fbf08329
|
4
|
+
data.tar.gz: ccd3d6e0c3c553a9ec48202929bfbc7b8ef951e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4519130525a915442d30049f646cdad2b00293e7754b7680eb3b2bd00d2b8937dfee5e366665ef3a7daad52fdfa4506d4e23b66522f9d9b37a1665e829087508
|
7
|
+
data.tar.gz: 3cd76767821a0e0a879892556e13619ef26bd3bb0c16dadfd29364f52afd5d4be67bed4f3018823624939a77e593212930f1625e0fcb8724e878154958663991
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sergey Varaksin
|
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,38 @@
|
|
1
|
+
# L2met::Syslog
|
2
|
+
|
3
|
+
This gem allows to write system info in log using l2met compatible format.
|
4
|
+
Runs in a thread.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'l2met-syslog'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install l2met-syslog
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
class MyLogger < L2met::Syslogger
|
23
|
+
def log_data
|
24
|
+
log(source: ENV['APP_NAME'], measure: 'cpu', val: 10)
|
25
|
+
log(source: ENV['APP_NAME'], measure: 'memory', val: 100)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# this will start logging data in a new thread
|
30
|
+
MyLogger.run
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'l2met/syslog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "l2met-syslog"
|
8
|
+
spec.version = L2met::Syslog::VERSION
|
9
|
+
spec.authors = ["Sergey Varaksin"]
|
10
|
+
spec.email = ["varaksin86@gmail.com"]
|
11
|
+
spec.description = %q{l2m compatible logger}
|
12
|
+
spec.summary = %q{allows to log system monitoring information asyncronously}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/l2met/syslog.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "l2met/syslog/version"
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module L2met
|
5
|
+
class Syslog
|
6
|
+
attr_accessor :logger
|
7
|
+
attr_accessor :interval
|
8
|
+
|
9
|
+
def self.run(options = {})
|
10
|
+
new(options).run
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@logger = options[:logger] || default_logger
|
15
|
+
@interval = options[:interval] || 60
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
@thread = Thread.new do
|
20
|
+
loop do
|
21
|
+
sleep @interval
|
22
|
+
log_data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
@thread.exit if @thread
|
29
|
+
end
|
30
|
+
|
31
|
+
def log_data
|
32
|
+
raise "This method must be implemented"
|
33
|
+
end
|
34
|
+
|
35
|
+
def log(params)
|
36
|
+
if @logger
|
37
|
+
message = params.map {|p| p.join('=') }.join(' ')
|
38
|
+
@logger.info(message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def default_logger
|
45
|
+
logger = ::Logger.new(STDOUT)
|
46
|
+
logger.formatter = proc {|severity, datetime, progname, msg| "#{msg}\n" }
|
47
|
+
logger
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe L2met::Syslog do
|
4
|
+
let(:options) { {interval: 0.01} }
|
5
|
+
|
6
|
+
subject { described_class.new(options) }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
context 'without params' do
|
10
|
+
let(:options) { {} }
|
11
|
+
|
12
|
+
it 'sets default logger' do
|
13
|
+
subject.logger.should be_an_instance_of ::Logger
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets default interval' do
|
17
|
+
subject.interval.should == 60
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#log_data' do
|
23
|
+
it 'must be implemented' do
|
24
|
+
expect {subject.log_data }.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'log' do
|
29
|
+
it 'outputs params in log' do
|
30
|
+
subject.logger.should_receive(:info).with('source=hostname measure=load val=10.0')
|
31
|
+
subject.log source: 'hostname', measure: 'load', val: 10.0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#run' do
|
36
|
+
it 'runs in thread' do
|
37
|
+
Thread.should_receive :new
|
38
|
+
subject.run
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'logs data when running' do
|
42
|
+
subject.should_receive(:log_data).at_least(:once).and_return nil
|
43
|
+
subject.run
|
44
|
+
sleep 0.02
|
45
|
+
subject.stop
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#stop' do
|
50
|
+
it 'stops executing' do
|
51
|
+
thread = subject.run
|
52
|
+
thread.should_receive(:exit)
|
53
|
+
subject.stop
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: l2met-syslog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Varaksin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-31 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: l2m compatible logger
|
56
|
+
email:
|
57
|
+
- varaksin86@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- l2met-syslog.gemspec
|
68
|
+
- lib/l2met/syslog.rb
|
69
|
+
- lib/l2met/syslog/version.rb
|
70
|
+
- spec/lib/l2met/syslog_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: allows to log system monitoring information asyncronously
|
96
|
+
test_files:
|
97
|
+
- spec/lib/l2met/syslog_spec.rb
|
98
|
+
- spec/spec_helper.rb
|