file_monitoring 1.0.2 → 1.0.3
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.
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'algorithms'
|
2
2
|
require 'fileutils'
|
3
|
-
require '
|
3
|
+
require 'log4r'
|
4
4
|
require 'params'
|
5
5
|
|
6
6
|
require 'file_monitoring/monitor_path'
|
@@ -41,13 +41,26 @@ module FileMonitoring
|
|
41
41
|
pq.push([priority, elem, dir_stat], -priority)
|
42
42
|
}
|
43
43
|
|
44
|
-
|
44
|
+
#init log4r
|
45
|
+
monitoring_log_path = Params['default_monitoring_log_path']
|
46
|
+
Log.debug1 'File monitoring log: ' + Params['default_monitoring_log_path']
|
47
|
+
monitoring_log_dir = File.dirname(monitoring_log_path)
|
48
|
+
FileUtils.mkdir_p(monitoring_log_dir) unless File.exists?(monitoring_log_dir)
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
@log4r = Log4r::Logger.new 'BBFS monitoring log'
|
51
|
+
@log4r.trace = true
|
52
|
+
formatter = Log4r::PatternFormatter.new(:pattern => "[%d] [%m]")
|
53
|
+
#file setup
|
54
|
+
file_config = {
|
55
|
+
"filename" => Params['default_monitoring_log_path'],
|
56
|
+
"maxsize" => Params['log_rotation_size'],
|
57
|
+
"trunc" => true
|
58
|
+
}
|
59
|
+
file_outputter = Log4r::RollingFileOutputter.new("monitor_log", file_config)
|
60
|
+
file_outputter.level = Log4r::INFO
|
61
|
+
file_outputter.formatter = formatter
|
62
|
+
@log4r.outputters << file_outputter
|
63
|
+
FileStat.set_log(@log4r)
|
51
64
|
|
52
65
|
while true do
|
53
66
|
# pull entry that should be checked next,
|
@@ -32,6 +32,11 @@ module FileMonitoring
|
|
32
32
|
# * <tt>path</tt> - File location
|
33
33
|
# * <tt>stable_state</tt> - Number of iterations to move unchanged file to stable state
|
34
34
|
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
35
|
+
ObjectSpace.define_finalizer(self,
|
36
|
+
self.class.method(:finalize).to_proc)
|
37
|
+
if Params['enable_monitoring']
|
38
|
+
Params['process_vars'].inc('obj add FileStat')
|
39
|
+
end
|
35
40
|
@path ||= path
|
36
41
|
@size = nil
|
37
42
|
@creation_time = nil
|
@@ -42,6 +47,12 @@ module FileMonitoring
|
|
42
47
|
@stable_state = stable_state # number of iteration to move unchanged file to stable state
|
43
48
|
end
|
44
49
|
|
50
|
+
def self.finalize(id)
|
51
|
+
if Params['enable_monitoring']
|
52
|
+
Params['process_vars'].inc('obj rem FileStat')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
def set_output_queue(event_queue)
|
46
57
|
@event_queue = event_queue
|
47
58
|
end
|
@@ -105,8 +116,8 @@ module FileMonitoring
|
|
105
116
|
if (@state != new_state or @state == FileStatEnum::CHANGED)
|
106
117
|
@state = new_state
|
107
118
|
if (@@log)
|
108
|
-
@@log.
|
109
|
-
@@log.flush
|
119
|
+
@@log.info(state + ": " + path)
|
120
|
+
@@log.outputters[0].flush if Params['log_flush_each_message']
|
110
121
|
end
|
111
122
|
if (!@event_queue.nil?)
|
112
123
|
Log.debug1 "Writing to event queue [#{self.state}, #{self.path}]"
|
@@ -124,13 +135,6 @@ module FileMonitoring
|
|
124
135
|
def to_s (indent = 0)
|
125
136
|
(" " * indent) + path.to_s + " : " + state.to_s
|
126
137
|
end
|
127
|
-
|
128
|
-
# Reports current state with identification.
|
129
|
-
# NOTE This format used by log file.
|
130
|
-
def cur_stat
|
131
|
-
# TODO what output format have to be ?
|
132
|
-
Time.now.utc.to_s + " : " + self.state + " : " + self.path
|
133
|
-
end
|
134
138
|
end
|
135
139
|
|
136
140
|
# This class holds current state of directory and methods to control changes
|
@@ -141,10 +145,23 @@ module FileMonitoring
|
|
141
145
|
# * <tt>path</tt> - File location
|
142
146
|
# * <tt>stable_state</tt> - Number of iterations to move unchanged directory to stable state
|
143
147
|
def initialize(path, stable_state = DEFAULT_STABLE_STATE)
|
148
|
+
ObjectSpace.define_finalizer(self,
|
149
|
+
self.class.method(:finalize).to_proc)
|
150
|
+
if Params['enable_monitoring']
|
151
|
+
Params['process_vars'].inc('obj add DirStat')
|
152
|
+
end
|
144
153
|
super
|
145
154
|
@dirs = nil
|
146
155
|
@files = nil
|
147
156
|
@non_utf8_paths = {}
|
157
|
+
ObjectSpace.define_finalizer(self,
|
158
|
+
self.class.method(:finalize).to_proc)
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.finalize(id)
|
162
|
+
if Params['enable_monitoring']
|
163
|
+
Params['process_vars'].inc('obj rem DirStat')
|
164
|
+
end
|
148
165
|
end
|
149
166
|
|
150
167
|
# Adds directory for monitoring.
|
@@ -183,10 +200,10 @@ module FileMonitoring
|
|
183
200
|
child_indent = indent + indent_increment
|
184
201
|
res = super
|
185
202
|
@files.each_value do |file|
|
186
|
-
res += "\n" + file.to_s(
|
203
|
+
res += "\n" + file.to_s(child_indent)
|
187
204
|
end if @files
|
188
205
|
@dirs.each_value do |dir|
|
189
|
-
res += "\n" + dir.to_s(
|
206
|
+
res += "\n" + dir.to_s(child_indent)
|
190
207
|
end if @dirs
|
191
208
|
res
|
192
209
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_monitoring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: log4r
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|