Class: MetricCollect
- Inherits:
-
Object
show all
- Defined in:
- lib/metric_collect/log.rb,
lib/backend/email.rb,
lib/backend/statsd.rb,
lib/metric_collect.rb,
lib/backend/graphite.rb,
lib/metric_collect/config.rb,
lib/metric_collect/metric.rb,
lib/metric_collect/version.rb
Overview
- Author
-
Kevin Moser (<[email protected]>)
- Copyright
-
2012, Nordstrom, Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Classes: Backend, Config, Log, Metric
Constant Summary
collapse
- VERSION =
"0.0.1"
Instance Method Summary
collapse
Instance Method Details
#load_config_from_file ⇒ Object
82
83
84
85
86
|
# File 'lib/metric_collect.rb', line 82
def load_config_from_file
puts "#{MetricCollect::Log.build_time}|INFO|Loading config file #{@config_file}"
@config = MetricCollect::Config.new
@config.instance_eval(IO.read(@config_file))
end
|
#load_dynamic_definitions(metric) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/metric_collect.rb', line 52
def load_dynamic_definitions(metric)
new_metric = MetricCollect::Metric.new("CommandLine")
begin
MetricCollect::Log.info("Loading metric[#{new_metric.name}]")
new_metric.instance_eval(metric)
rescue => error
MetricCollect::Log.fatal("Error loading metric[#{new_metric.name}]", error)
end
@metrics << new_metric
end
|
#load_logger ⇒ Object
48
49
50
|
# File 'lib/metric_collect.rb', line 48
def load_logger
MetricCollect::Log.new(@config.params[:log_file]) if @config.params[:log_file]
end
|
#load_metric_definitions ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/metric_collect.rb', line 63
def load_metric_definitions
unless File.exists?(@config.params[:metrics_directory])
MetricCollect::Log.fatal("Metrics directory supplied does not exist!")
end
metric_files = Dir["#{@config.params[:metrics_directory]}/*.rb"]
@metrics = Array.new
metric_files.each do |filename|
new_metric = MetricCollect::Metric.new(File.basename(filename, ".rb"))
begin
MetricCollect::Log.info("Loading metric[#{new_metric.name}]")
new_metric.instance_eval(IO.read(filename))
rescue => error
MetricCollect::Log.fatal("Error loading metric[#{new_metric.name}]", error)
end
@metrics << new_metric
end
end
|
#run(config_file, metric = nil) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/metric_collect.rb', line 27
def run(config_file, metric=nil)
unless config_file
puts "Config file not specified!!"
exit
end
@config_file = config_file
load_config_from_file
load_logger
unless @config.params[:metrics_directory]
MetricCollect::Log.fatal("You must set a metrics_directory in your config.rb")
end
load_metric_definitions
load_dynamic_definitions(metric) if metric
send_all_metrics
MetricCollect::Log.info("All metrics processed successfully!")
end
|
#send_all_metrics ⇒ Object
88
89
90
91
92
93
|
# File 'lib/metric_collect.rb', line 88
def send_all_metrics
@metrics.each do |metric|
MetricCollect::Log.info("Processing metric[#{metric.name}]")
metric.send(@config)
end
end
|