Skip to content

Instantly share code, notes, and snippets.

@Sharpie
Last active June 28, 2017 18:41
Show Gist options
  • Save Sharpie/97b3a065cdf526bfd8528e8d679c081e to your computer and use it in GitHub Desktop.
Save Sharpie/97b3a065cdf526bfd8528e8d679c081e to your computer and use it in GitHub Desktop.
Transform ActiveMQ config files into a connection diagram for Graphviz
#!/usr/bin/env ruby
# Generate a DOT file showing links between ActiveMQ brokers using
# a list of activemq.xml files passed as ARGV.
require 'rexml/document'
require 'erb'
broker_map = Hash.new
ARGV.each do |f|
doc = REXML::Document.new(File.read(f))
broker = REXML::XPath.first(doc, '//broker').attribute('brokerName').value
connections = REXML::XPath.match(doc, '//networkConnector')
connection_map = connections.inject(Hash.new) do |map, entry|
dest = entry.attribute('uri').value.match(/([^\/]+):61616/).captures.first
duplex = if entry.attribute('duplex').value == 'true'
true
else
false
end
map[dest] = duplex
map
end
broker_map[broker] = connection_map
end
dot_template = ERB.new(<<-EOT, nil, '<>')
digraph amq_broker_map {
overlap=scale;
concentrate=false;
splines=true;
<% broker_map.each do |source, target_hash| %>
<% target_hash.each do |target, duplex| %>
<% if duplex %>
"<%= source %>" -> "<%= target %>" [dir="both"]
<% else %>
"<%= source %>" -> "<%= target %>"
<% end %>
<% end %>
<% end %>
}
EOT
File.write('amq_broker_map.dot', dot_template.result(binding))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment