JunOS and Event scripting

I recently ran into an issue where the mib2d daemon was consuming more than its fair share of memory.

Going so far as to use so much, that it became noticeable in syslog. A little googling turned up an option that is built-in to JunOS. While it won’t solve it, it will work around it (giving Juniper time to patch things up, and keep our gear running until then). The syslog info looks like this:

JunOS log

Jan 8 02:25:12 ex4200 /kernel: Process (46705,mib2d) has exceeded 85% of RLIMIT_DATA: used 115736 KB Max 131072 KB

Event policy

The solution is a combination of a slax script, and and an event script. The event script watches for an event (sounds obvious, it is), and when that event happens, it executes the slax script. Code looks like this:

set event-options generate-event restart-mib2d time-interval 604800
set event-options policy restart-mib2d events restart-mib2d
set event-options policy restart-mib2d within 600000 not events restart-mib2d
set event-options policy restart-mib2d then event-script restart-mib2d

Set the time-interval based on how quickly the memory is being consumed. Units are in seconds. The second number should be just a little smaller than the first.

slax script


version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";

match / {
	<op-script-results> {
		var $restart-mib2d = {
            <command> "restart mib-process gracefully";
        var $result = jcs:invoke($restart-mib2d);

You should nolonger have issues with the mib2d process consuming too many resources.

Note that this should be removed when Juniper fixes the resource issue with mib2d