summaryrefslogtreecommitdiff
path: root/lib/oxidized/node
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-05-07 12:23:36 +0300
committerSaku Ytti <saku@ytti.fi>2014-05-07 12:23:36 +0300
commit94926f53db8a7244f1af34e30607fdc2908ffa8e (patch)
tree06f5947a27a4d2f3854bf6b94ea1e606d49bf949 /lib/oxidized/node
parenteff861dc81aed658cbccfcc2ea86b3d7f02d975d (diff)
Stats for node
So that we can easily check last time node failed/succceded etc
Diffstat (limited to 'lib/oxidized/node')
-rw-r--r--lib/oxidized/node/stats.rb33
1 files changed, 33 insertions, 0 deletions
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