Skip to content

Instantly share code, notes, and snippets.

@meadhikari
Forked from EHadoux/Readme.md
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meadhikari/4f5ef37de9a1c1e57abd to your computer and use it in GitHub Desktop.
Save meadhikari/4f5ef37de9a1c1e57abd to your computer and use it in GitHub Desktop.

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment