Dusko Pijetlovic

My personal notes where I store things I find interesting or might need in the future.

How To Create Networking Diagrams with Graphviz and Kroki

04 Mar 2022 » howto, diagram, java, graph, graphviz, plaintext, text, tex, latex, visualization, sysadmin, documentation

OS: FreeBSD 13
Shell: csh


% cat graph.dot
graph networkdiagram {

  /*
     Colours for the lines relate to the line speed
     green is for 100 Mbit (100 Mb/s) (IBM Management)
     blue is for Gigabit (1 Gb/s)
     red is for 10 Gigabit (10 Gb/s)
  */

  imagepath="/usr/home/dusko/scratch/graphviz_network/images"

  label="\nCompute Cluster Network Diagram";

  node [shape="none", fontname="arial", fontsize=10, labelloc="b", color="#ffffff"];
  splines="compound";

  fw [label="Edge firewall", image="firewall.png"];
  panel [label="Patch panel", image="patchPanel24Port.png"];
  sw1 [label="Cisco switch", image="gigabitSwitch.png"];
  sw2 [label="Compute cluster switch", image="gigabitSwitch.png"];
  srv1 [label="WebMO and cluster storage", image="rackmountServer1U.png"];
  srv2 [label="Compute nodes 101-114", image="serverBlades.png"];
  srv3 [label="Compute nodes 201-214", image="serverBlades.png"];
  srv4 [label="Compute management node", image="rackmountServer1U.png"];
  cloud [label="Internet", image="cloud.png"];

  cloud -- fw [color="red"];
  fw -- panel [color="red"];
  sw1 -- panel [color="red"];
  panel -- srv4 [color="blue"];

  {
    rank="same";
    srv1; srv2; srv3; srv4;
  }

  srv1 -- sw1 [color="blue"];
  srv1 -- sw2 [color="blue"];
  srv1 -- sw2 [color="green"];
  srv2 -- sw2 [color="blue"];
  srv2 -- sw2 [color="green"];
  srv3 -- sw2 [color="blue"];
  srv3 -- sw2 [color="green"];
  srv4 -- sw2 [color="blue"];
}

To generate the diagram with Graphviz:

% dot -Tpng graph.dot -o graph.png

To generate the diagram with PlantUML via a self-managed instance of Kroki (How to Run Kroki on FreeBSD 13 with Java or How to Run Kroki on FreeBSD 13 with vm-bhyve and Debian GNU/Linux VM):

% cat \
 graph.dot | \
 http \
 http://localhost:8000/plantuml/png \
 Content-Type:text/plain > \
 graph.png

NOTE:
Supported output formats in PlantUML: png, svg, jpeg, base64, txt or utxt.

% xv graph.png

Displaying a png image of a network diagram created by Graphviz

NOTE:
Online Graphviz tools

  • For realtime collaboration: http://graphvizrepl.com

    Graphviz-REPL gives you a two-pane interface for quickly creating and iterating through graphviz diagrams. You type DOT syntax on the left, and the image will appear on the right after just a moment.


References: