Once upon a time Tobi Oetiker created The Multi Router Traffic Grapher (MRTG):
...a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing graphical images which provide a LIVE visual representation of this traffic... MRTG is based on Perl and C and works under UNIX and Windows NT...
MRTG runs as a scheduled task: cron daemon is used on UNIX systems to run MRTG each 5 minutes, for example. MRTG creates traffic graphs as PNG files embedded in simple HTML pages. All pages (with daily, weekly, monthly and yearly graphs) are created in a single directory backed by (Apache) web server: you can watch your Internet traffic (almost) LIVE by means of any web browser.
Under the hood, you'll find that Tobi's MRTG uses some kind of RRD files to store traffic data (MRTG native format or RRDTool file format). So, I thought, it should be possible to create a similar application in pure Java using JRobin. I did not want to compete with MRTG, I just wanted to prove that JRobin is useful for the same purposes as Tobi's famous RRDTool and MRTG. But if you want to measure your internet traffic in a simple and efficient way, you'll be probably satisfied.
So, JRobin-MRTG is finally here. It consists of two separate applications: the client and the server one. These two applications communicate through protocol. You can run one server application and as many client applications on as many different machines as you want. Client applications are used to control the server: to remotely add, edit, update or delete monitored network interfaces and to request specific traffic graphs.
Server application is used to:
To run server application, issue the following command from the command line:
java -jar mrtg-server-[version].jar
The command line could be more complex if you don't have X-server (windows) installed and you don't want to be interrupted once you log out (common situation on many network servers). In that case use the following command:
nohup java -Djava.awt.headless=true -jar mrtg-server-[version].jar > /dev/null 2>&1 &
The server application uses port 35353 to communicate with unlimited number of client applications. It can be reached with any JRobin-MRTG client from the internet (unless firewall blocks XMLRPC communication between clients and the server application). If you want to restrict access to the server application, add IP addresses of trusted clients to the command line. For example:
java -Djava.awt.headless=true -jar mrtg-server-[version].jar 192.168.1.23 192.168.1.24
When server application is run for the first time, mrtg directory will be created in your $HOME directory. Newly created directory has two subdirectories: conf and rrd. The first directory (conf) containts a single XML file - hardware.dat. It holds complete information about monitored internet devices and interfaces. The second directory (rrd) contains RRD files, one file per each monitored network interface. If you monitor internet traffic through interface Serial2 on the router belgrade2.eunet.yu, you will find a file named Serial2@belgrade2.eunet.yu.rrd in this directory.
Server application requires the following libraries to be present:
All requested libraries can be found in the libs directory of this distribution.
Client application is used to control the work of the server application. Java swing library is used to create the client UI. This UI is used to:
Client application requires already mentioned Jakarta XML-RPC library for communication with the server (it can be found in the libs directory of this distribution). To run client application issue the following command from the command line:
java -jar mrtg-client-[version].jar
You will be asked to specify the address of the host on which JRobin-MRTG server application is running. Once you are connected, you will see the client application's UI.
Client UI has two preview panes: the left (tree) pane contains information about monitored network interfaces. The right (text) pane contains information about the selected element of the tree on the left side. Network devices (like routers and switches) are commonly denoted as 'routers'.
Note: Displayed information is not constantly updated! It gets updated whenever you add, update or remove a single router or its interface. If you want to refresh the displayed data so that it corresponds with the actual data on the server, right click anywhere on the client or choose Reload data from MRTG host from the MRTG menu. However, all kind of graphs are always generated using the latest available information from the server. And the graphs are constantly refreshed if necessary. They are as LIVE as Tobi's MRTG graphs are :)
In my humble opinion, client UI is simple and intuitive. You should have no problem to start monitoring your internet traffic load in a matter of minutes. I will explain only a few of the most interesting operations here.
Newly defined interface appears on the left side of the screen, probably with [-1] number added to its name. It means that MRTG server still does not know the real number of the interface on the router. But if you reload data from MRTG sever a few seconds later, you will probably see some positive number instead of [-1]. It means that the new interface exists on the router. You can be sure that the traffic monitoring process has started successfully.
I have tried to make JRobin-MRTG as clever as I could - if router gets reconfigured so that its interfaces change its corresponding interface numbers, JRobin-MRTG server application will notice this and update interface numbers on the fly.
Note:
Have fun! :)