# # Author: Seth Vargo # # Copyright 2014 Chef Software, 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. # module Falcore class Node::Base def initialize(data = {}) @data = data.dup end # # The unique ID for this node. This is the {display_name}, but any dots # (+.+) are substituted with dashes (+-+), because dots are the delimiters # for StatsD and other common dumpers. # # @return [String] # def id "jenkins.#{display_name.gsub(/\./, '-')}" end # @return [String] def display_name @data['displayName'] end # @return [true, false] def idle? !!@data['idle'] end # @return [Integer] def executors @data['numExecutors'].to_i end # @return [true, false] def offline? !!@data['offline'] end # @return [true, false] def temporarily_offline? !!@data['temporarilyOffline'] end # @return [Integer] def response_time Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.ResponseTimeMonitor', 'average').to_f end # @return [Integer] def temporary_space Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.TemporarySpaceMonitor', 'size').to_i end # @return [Integer] def disk_space Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.DiskSpaceMonitor', 'size').to_i end # @return [Integer] def free_memory Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.SwapSpaceMonitor', 'availablePhysicalMemory').to_i end # @return [Integer] def total_memory Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.SwapSpaceMonitor', 'totalPhysicalMemory').to_i end # @return [Integer] def free_swap Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.SwapSpaceMonitor', 'availableSwapSpace').to_i end # @return [Integer] def total_swap Util.deep_fetch(@data, 'monitorData', 'hudson.node_monitors.SwapSpaceMonitor', 'totalSwapSpace').to_i end # @private def to_s "#<#{self.class}>" end # @private def inspect list = Node::Base.public_instance_methods(false) .reject { |name| [:to_s, :inspect].include?(name) } .sort .map { |name| "#{name}: #{public_send(name).inspect}" } "#<#{self.class} #{list.join(', ')}>" end end end