lib/one2influx/one_object/cluster.rb
# Overrides OneObject init_metrics because cluster itself doesn't
# have any own metrics, so they are gathered as sum of metrics of
# hosts that belong to this cluster
Overrides OneObject init_metrics because cluster itself doesn't
have any own metrics, so they are gathered as sum of metrics of
hosts that belong to this cluster
Overrides OneObject init_metrics because cluster itself doesn ' t have any own metrics so they are gathered as sum of metrics of hosts that belong to this cluster
def init_metrics
    @metric_names.each do |metric|
      @metrics[metric.to_s] = 0
    end
    host_ids = @doc.xpath('//HOSTS/ID').map { |node| node.content }
    host_ids.each do |id|
      host = @hosts[id.to_sym]
      @metric_names.each do |metric|
        @metrics[metric.to_sym] ||= 0
        host_metric = metric.split('CLUSTER_')[1]
        next if host_metric.nil?
        if host.metrics.has_key? host_metric.to_sym
          @metrics[metric.to_sym] += host.metrics[host_metric.to_sym].to_i
        else
          ni_element = host.doc.css(host_metric).first
          if ni_element.nil?
            @metric_names = @metric_names.delete(metric)
            @metrics = @metrics.delete(metric.to_sym)
            $LOG.error "Unable to get metric '#{metric}' in #{self.class}." +
                           "XML parsing error in host ID=#{id}."
            next
          end
          @metrics[metric.to_sym] += ni_element.content.to_i
        end
      end
    end
  end
def init_metrics @metric_names . each do | metric | @metrics [ metric . to_s ] = 0 end host_ids = @doc . xpath ( '//HOSTS/ID' ) . map { | node | node . content } host_ids . each do | id | host = @hosts [ id . to_sym ] @metric_names . each do | metric | @metrics [ metric . to_sym ] ||= 0 host_metric = metric . split ( 'CLUSTER_' ) [ 1 ] next if host_metric . nil? if host . metrics . has_key? host_metric . to_sym @metrics [ metric . to_sym ] += host . metrics [ host_metric . to_sym ] . to_i else ni_element = host . doc . css ( host_metric ) . first if ni_element . nil? @metric_names = @metric_names . delete ( metric ) @metrics = @metrics . delete ( metric . to_sym ) $LOG . error "Unable to get metric '#{metric}' in #{self.class}." + "XML parsing error in host ID=#{id}." next end @metrics [ metric . to_sym ] += ni_element . content . to_i end end end end
Overrides OneObject init_metrics because cluster itself doesn't
have any own metrics, so they are gathered as sum of metrics of
hosts that belong to this cluster
Overrides OneObject init_metrics because cluster itself doesn ' t have any own metrics so they are gathered as sum of metrics of hosts that belong to this cluster
# Calculation of this metric would be misleading without this #   value, so I rather remove whole metric and log failure