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

1Jan 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:

1set event-options generate-event restart-mib2d time-interval 604800
2set event-options policy restart-mib2d events restart-mib2d
3set event-options policy restart-mib2d within 600000 not events restart-mib2d
4set 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

/var/db/scripts/op/restart-mib2d.slax:

 1version 1.0;
 2ns junos = "http://xml.juniper.net/junos/*/junos";
 3ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
 4ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
 5import "../import/junos.xsl";
 6
 7match / {
 8	<op-script-results> {
 9		var $restart-mib2d = {
10            <command> "restart mib-process gracefully";
11        }
12        var $result = jcs:invoke($restart-mib2d);
13    }
14}

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

Copyright

Comments