summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-06-12 12:37:32 +0300
committerSaku Ytti <saku@ytti.fi>2018-06-12 12:37:32 +0300
commit9fab2a507fcf10ae5c61bbd8e6a3534f64a66589 (patch)
tree42e4b5484b500ab0576a3f319925618b1abe88c4
parentba61f8cc8e138a128834d462d78bf5cfed50965c (diff)
Honor mtime in stats
Store N last mtimes
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/oxidized/node/stats.rb16
2 files changed, 13 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 19c788b..73194e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## Master
* FEATURE: add frr support to cumulus model (@User4574 / @bobthebutcher)
+* FEATURE: honour MAX_STAT in mtime, to store last N mtime
## 0.23.0
diff --git a/lib/oxidized/node/stats.rb b/lib/oxidized/node/stats.rb
index fbc2cf7..9b153ee 100644
--- a/lib/oxidized/node/stats.rb
+++ b/lib/oxidized/node/stats.rb
@@ -1,7 +1,6 @@
module Oxidized
class Node
class Stats
- attr_accessor :mtime
MAX_STAT = 10
# @param [Job] job job whose information add to stats
@@ -36,15 +35,24 @@ module Oxidized
@stats[:counter].reduce(0) { |m, h| h[0] == :success ? m : m + h[1] }
end
+ def mtimes
+ @mtimes
+ end
+
+ def mtime
+ mtimes.last
+ end
+
def update_mtime
- @mtime = Time.now.utc
+ @mtimes.push Time.now.utc
+ @mtimes.shift if @mtimes.size > MAX_STAT
end
private
def initialize
- @mtime = "unknown"
- @stats = {}
+ @mtimes = Array.new(MAX_STAT, "unknown")
+ @stats = {}
@stats[:counter] = Hash.new 0
end
end