statistics 468 B

123456789101112131415161718
  1. #!/usr/bin/lua
  2. local announce = require 'gluon.announce'
  3. local json = require 'luci.jsonc'
  4. local util = require 'luci.util'
  5. local nixio = require 'nixio'
  6. local announce_dir = '/lib/gluon/announce/statistics.d/'
  7. io.write("Access-Control-Allow-Origin: *\n")
  8. io.write("Content-type: text/event-stream\n\n")
  9. while true do
  10. local data = json.stringify(announce.collect_dir(announce_dir))
  11. io.write("data: " .. data .. "\n\n")
  12. io.flush()
  13. nixio.nanosleep(1, 0)
  14. end