class MetricCollect
- Author
-
Kevin Moser (<kevin.moser@nordstrom.com>)
- 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.
- Author
-
Kevin Moser (<kevin.moser@nordstrom.com>)
- 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.
- Author
-
Kevin Moser (<kevin.moser@nordstrom.com>)
- 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.
Constants
- VERSION
Public Instance Methods
# 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
# 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
# File lib/metric_collect.rb, line 48 def load_logger MetricCollect::Log.new(@config.params[:log_file]) if @config.params[:log_file] end
# 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
# 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
# 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