whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [2/3] Commit bb8aa9b: monitor the production of public json
Date Sun, 17 Jan 2016 18:11:35 GMT
Commit bb8aa9b69fddcd718bd2840528a0ff1fb07e7956:
    monitor the production of public json


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/status/monitor.rb                                        | ++++++ --
www/status/monitors/public_json.rb                           | +++++++++++ 
------------------------------------------------------------
37 changes: 33 additions, 4 deletions.
------------------------------------------------------------


diff --git a/www/status/monitor.rb b/www/status/monitor.rb
index 49cbbc6..3f60025 100644
--- a/www/status/monitor.rb
+++ b/www/status/monitor.rb
@@ -13,7 +13,7 @@ class Monitor
 
   attr_reader :status
 
-  def initialize
+  def initialize(args = [])
     status_file = File.expand_path('../status.json', __FILE__)
     File.open(status_file, File::RDWR|File::CREAT, 0644) do |file|
       # lock the file
@@ -33,6 +33,8 @@ def initialize
       # invoke each monitor, collecting status from each
       newstatus = {}
       self.class.singleton_methods.sort.each do |method|
+        next if args.length > 0 and not args.include? method.to_s
+
         # invoke method to determine current status
         begin
           previous = baseline[method] || {mtime: Time.at(0).gmtime.iso8601}
@@ -88,6 +90,11 @@ def initialize
 
   # default fields, and propagate status 'upwards'
   def normalize(status)
+    # convert strings and arrays to status hashes
+    if status.instance_of? String or status.instance_of? Array
+      status = {data: status}
+    end
+
     # convert symbols to strings
     status.keys.each do |key|
       status[key.to_s] = status.delete(key) if key.instance_of? Symbol
@@ -113,13 +120,14 @@ def normalize(status)
       if status['data'].instance_of? Hash
         # find the values with the highest status level
         highest = status['data'].
-          group_by {|key, value| LEVELS.index(value['level']) || 9}.max
+          group_by {|key, value| LEVELS.index(value['level']) || 9}.max ||
+          [9, []]
 
         # adopt that level
         status['level'] = LEVELS[highest.first] || 'danger'
 
         group = highest.last
-        if group.length > 1
+        if group.length != 1
           # indicate the number of item with that status
           status['title'] = "#{group.length} #{ISSUE_TYPE[status['level']]}"
         else
@@ -148,5 +156,5 @@ def normalize(status)
 
 # for debugging purposes
 if __FILE__ == $0
-  puts JSON.pretty_generate(Monitor.new.status)
+  puts JSON.pretty_generate(Monitor.new(ARGV).status)
 end
diff --git a/www/status/monitors/public_json.rb b/www/status/monitors/public_json.rb
new file mode 100644
index 0000000..90466fb
--- /dev/null
+++ b/www/status/monitors/public_json.rb
@@ -0,0 +1,21 @@
+#
+# Monitor status of public json directory
+#
+
+def Monitor.public_json(previous_status)
+  logs = File.expand_path('../../www/logs/public-*')
+
+  status = {}
+
+  Dir[logs].each do |log|
+    name = File.basename(log).sub('public-', '')
+
+    if File.size(log) == 0
+      status[name] = {data: "Last updated #{File.mtime(log)}"}
+    else
+      status[name] = {level: 'danger', data: File.readlines(log)}
+    end
+  end
+
+  {data: status}
+end

Mime
View raw message