diff options
Diffstat (limited to 'lib/oxidized')
-rw-r--r-- | lib/oxidized/node.rb | 4 | ||||
-rw-r--r-- | lib/oxidized/node/stats.rb | 33 |
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 65f0c1f..d7de991 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -1,10 +1,11 @@ module Oxidized require 'resolv' + require_relative 'node/stats' class MethodNotFound < OxidizedError; end class ModelNotFound < OxidizedError; end class Node attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars - attr_accessor :last, :running, :user, :msg, :from + attr_accessor :last, :running, :user, :msg, :from, :stats alias :running? :running def initialize opt @name = opt[:name] @@ -16,6 +17,7 @@ module Oxidized @auth = resolve_auth opt @prompt = resolve_prompt opt @vars = opt[:vars] + @stats = Stats.new # model instance needs to access node instance @model.node = self diff --git a/lib/oxidized/node/stats.rb b/lib/oxidized/node/stats.rb new file mode 100644 index 0000000..6b5719c --- /dev/null +++ b/lib/oxidized/node/stats.rb @@ -0,0 +1,33 @@ +module Oxidized + class Node + class Stats + MAX_STAT = 10 + + # @param [Job] job job whose information add to stats + # @return [void] + def add job + stat = { + :start => job.start, + :end => job.end, + :time => job.time, + } + @stats[job.status] ||= [] + @stats[job.status].shift if @stats[job.status].size > MAX_STAT + @stats[job.status].push stat + end + + # @param [Symbol] status stats for specific status + # @return [Hash,Array] Hash of stats for every status or Array of stats for specific status + def get status=nil + status ? @stats[status] : @stats + end + + private + + def initialize + @stats = {} + end + + end + end +end |