rubydashing

Troubleshooting a dashing widget


I have created a widget, to display the server load. However, it doesn't display the server load.

dashboard.erb

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="serverload" data-view="Graph" data-title="Server load" data-moreinfo="1 min intervals" ></div>
</li>

jobs/serverload.rb

points = []
(1..10).each do |i|
  points << { x: i, y: 0 }
end
last_x = points.last[:x]

SCHEDULER.every '1m' do
  points.shift
  last_x += 1
  uptime = %x('uptime').gsub(/.*: /, '\1').gsub(/,/, '\1')
  points << { x: last_x, y: uptime[0..3].to_f }
  send_event('loadavg1min', points: points)
end

It simply, displays the following. How can we troubleshoot this particular widget and figure out where it is failing?

enter image description here


Solution

  • Going off of the example in the docs, try adding the first_in: option as well as passing in a hash as the second argument to send_event

    Try:

    SCHEDULER.every '1m', first_in: 1.second.since do
      points.shift
      last_x += 1
      uptime = %x('uptime').gsub(/.*: /, '\1').gsub(/,/, '\1')
      points << { x: last_x, y: uptime[0..3].to_f }
      send_event('loadavg1min', { points: points })
    end
    

    docs:

    # :first_in sets how long it takes before the job is first run. In this case, 
    it is run immediately
    Dashing.scheduler.every '1m', first_in: 1.second.since do |job|
      Dashing.send_event('karma', { current: rand(1000) })
    end