Using NetConsole for Debug Logging of Unikernels

Nanos has many different logging options. You can log to serial, you can log to files, you can ship things over syslog. We even made a syslog klib so you don't have to modify your code. Today we'll show you yet another way to log.

One of our engineers added netconsole logging support earlier this year. It is an interesting feature that allows you to separate your debug logging from the normal console output and ship it to a specific ip and port. Why would you want to do this? Performance testing for one. Logging to serial/vga is super slow. Serial by itself is insanely slow but even if you disable that having the vga support is still performance taxing so if you are trying to do performance debugging and you still want to get some debug output this is a nice little feature to have in your back pocket.

By default, when running in user-mode, output is shot out via the host ip of 10.0.2.2 and port 4444, however you can change these via the manifest options of netconsole_ip and netconsole_port. Let's try a little example:

package main

import (
	"fmt"
	"time"
)

func main() {

	for i := 0; i < 1000; i++ {

		fmt.Println("yo")

		time.Sleep(1 * time.Second)
	}
}

In our manifest we specify the console we want - in this case 'net'. You can add consoles with '+' and remove them with '-'.

➜  g cat config.json
{
  "ManifestPassthrough": {
    "consoles": ["+net"]
  }
}

Then we run it:

➜  g ops run -c config.json g
booting /Users/eyberg/.ops/images/g.img ...
en1: assigned 10.0.2.15
yo
yo
en1: assigned FE80::2044:69FF:FE82:C12E
yo
yo

Now we set up a netcat listener (server). You just set it to listen on port 4444 and specify UDP as the the L4 transport.

➜ nc -l -u 4444
yo
yo
yo
yo
yo
^C

If everything works you should start seeing output. This new suite of tooling is extremely powerful and versatile and will help you debug your unikernels for performance issues.

Deploy Your First Open Source Unikernel In Seconds

Get Started Now.