【问题标题】:Troubleshooting a dashing widget对破折号小部件进行故障排除
【发布时间】:2018-08-09 04:05:51
【问题描述】:

我创建了一个小部件来显示服务器负载。但是,它不显示服务器负载。

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

简单地说,显示以下内容。我们如何对这个特定的小部件进行故障排除并找出它出现故障的地方?

【问题讨论】:

    标签: ruby dashing


    【解决方案1】:

    离开docs 中的示例,尝试添加first_in: 选项以及将哈希作为第二个参数传递给send_event

    试试:

    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
    

    文档:

    # :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
    

    【讨论】:

    • 即使在添加 first_in 之后,我也看不到小部件中的任何更改。我猜我们还缺少其他东西。
    猜你喜欢
    • 1970-01-01
    • 2012-04-25
    • 2015-10-10
    • 2016-02-12
    • 2015-12-14
    • 2020-10-02
    • 2011-02-07
    • 2013-11-20
    • 1970-01-01
    相关资源
    最近更新 更多