Shopify / dashing

The exceptionally handsome dashboard framework in Ruby and Coffeescript.
http://shopify.github.com/dashing/
MIT License
10.98k stars 1.18k forks source link

Dynamically add widgets on screen #313

Open dav3860 opened 10 years ago

dav3860 commented 10 years ago

Hi,

Thank you for this great framework!

I can't find a way to dynamically add widgets on screen. The idea is to get alerts from our monitoring system and to display a widget for each host in alert, not a to have a fixed number of widgets. I'm not sure on how to do that. The job could return a send_event for each host, with a specific id, but how would i loop through all the hots/widgets in the *.erb. The data-ids need to be linked to each event... Can you help me ?

sammarx commented 10 years ago

I managed to get this working in the ugliest way possible.

In my job definition, I set an array (using the sinatra set method) with my list of monitors, and pass a send_event to each monitor.

Then in the dashboard, I access the array through the settings.$VARNAME.

https://gist.github.com/sammarx/8806031

This is a proof of concept.
I'm going to look into extending dashing to pass a set_local method or something along those lines.

dav3860 commented 10 years ago

Thank you for the workaround!

davejohnston commented 9 years ago

Hi Guys, I came across this and the solution works for me. The problem is that I need to refresh the page to see when new widgets have appeared.
Is there anyway to trigger a page refresh from the job? for example if you keep track of the number of roles, if this changes, then trigger a refresh ?

terraboops commented 9 years ago

@davejohnston - You can trigger a refresh from the job by running this send_even:

send_event('refresh_sample', {event: 'reload', dashboard: 'sample'}, 'dashboards')

Replace refresh_sample with whatever you want to call the event, some descriptive name. Replace dashboard: 'sample' with the name of the dashboard you wish to refresh.

<rant> In general, my suggestion to solve this problem is to create a single widget that scales to the number of data sources you wish to display from multiple jobs and looks like individual widgets. This solution will fit nicely into Dashing.

Dynamically generating the HTML for the Dashboards is another option if you do not want to create your own widget, but it will instead require you to build a backend for dynamically generating the content of the Dashboard ERB files.

Doing this in a sane way is outside the scope of Dashing IMHO, but could be written as a Sinatra Extension packaged as a Gem that extends your ability to define the view model used for each Dashboard or adds some view helpers for data synchronisation and iteration. </endrant>