Skip to content

Instantly share code, notes, and snippets.

@EHadoux
Last active May 18, 2016 10:07
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save EHadoux/5196209 to your computer and use it in GitHub Desktop.
Save EHadoux/5196209 to your computer and use it in GitHub Desktop.
Sonar Widget for Dashing

Description

This is a dashing widget intended to show metrics from a sonar repository.

Usage

This widget currently uses the list widget as a view. You just have to add this snippet to your dashboard:

<li data-row="1", data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="id" data-view="List" data-title="myT" data-unordered="true" data-moreinfo="Sonar"</div>
</li>

And copy sonar.rb in your job folder.

You may have to change the data-sizey value if you want to display more metrics.

Installation

Nothing to do!!

Preview

Acknowledgments

The last revision (&format=json in the uri) has been made by @meadhikari. Reach him for any stuff concerning this.

require 'net/http'
require 'json'
server = "your_sonar_server"
key = "your_project_key"
metrics = %w{your metrics}.join(',')
id = "id"
SCHEDULER.every '10s', :first_in => 0 do |job|
uri = URI("#{server}/api/resources?resource=#{key}&metrics=#{metrics}&format=json")
res = Net::HTTP.get(uri)
j = JSON[res][0]['msr']
send_event(id, { items:
[{ label: 'Metric 1', value: j[0]['val'] },
{label:'Metric 2', value:j[1]['val']},
{label:'Metric n', value:j[n]['val']}
]})
end
@centic9
Copy link

centic9 commented Feb 26, 2014

FYI, if you run a Sonar instance that is secured, i.e. requires authentication for the API calls, then you can use the Widget at https://gist.github.com/aaronkaka/8491321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment