Checking Bandwidth of Specific Device > Specific Port for X amount of time

Hello,

I am quite new to LibreNMS wonderland and still figuring out lots of beautiful things and applying them to my environment.

Currently I am struggling about creating an alert rule for the following scenario;

I want to monitor the bandwidth of specific port on specific device. If it exceeds the defined amount for X amount of minutes, I want to issue an alert. I also want to re-issue this alert if it still persists after 30 minutes.

Device A
Port B of device A
If → PortB bandwidth usage is greater_than 2Gbps for X minutes, issue an alert

What I tried is;

Rule Name: High Bandwidth Usage

Rule(s):  %devices.sysName = “myDevice” &&
          %ports.ifHighSpeed >= "2000" &&
          %ports.ifName = “sfp-sfpplus2”

Map to: myDeviceIP (ex 1.1.1.1)

Max: 1, Delay: 300, Interval: 1800

Is there anything am I missing? Do I need to specify something else like SQL query etc?

Thanks in advance for any support!

Hello,

%ports.ifHighSpeed is the link speed, not the used bandwidth.

Maybe you want to take a look to the actual Port utilisation over threshold rule included in LibreNMS.

If you dont have it, just click in Create rule from collection.

It is based in percentage from link speed. So, if you have a 1G port and set the rule to trigger at 80%, it will do when bw usage reachs 800Mbps.

Then, if you want to alert when that 80% of usage happens for 30 consecutive minutes, you need to set delay to 1800s.

Interval is the time between alert notifications to transports.

1 Like

Thanks for prompt reply @TheGreatDoc.

If I understand correctly; If I have 10G port, then %ports.ifHighSpeed willl always return 10G or current usage? So basically
Port utilisation over threshold should fix my problem when I set percentage to 20% for 10G port?

Would the following Port utilisation over threshold work as intended then?;

Rule Name: High Bandwidth Usage

Rule(s):  %devices.sysName = “myDevice” &&
          %macros.port_usage_perc >= "20" &&
          %macros.port_up &&
          %ports.ifName = “sfp-sfpplus2”

Map to: myDeviceIP (ex 1.1.1.1)

Max: 1, Delay: 1800, Interval: 300

Thanks!

With that rule, alert will trigger when, for a consecutive period of 30mins (thats 6 consecutives poll cycles).

As you only have set 1 notification, you will get notified once. If you want just one reminder 5 min later, you need to set MAX to 2.

ifHighSpeed will always return the link speed, in your case, 10G (10.000) ifSpeed will return in bits (10.000.000)

1 Like

It’s working as intended now and finally, thank you :slight_smile:

I have off-topic question, is there way to round retrieved value for alerting template?

For Instance;

@foreach ($alert->faults as $key => $value)
Download: {{ (($value['ifOutOctets_rate']*8)/$value['ifSpeed'])*100*100 }} Mbps
Upload  : {{ (($value['ifInOctets_rate']*8)/$value['ifSpeed'])*100*100 }} Mbps
@endforeach 

This returns me values like; 1359.41283 Mbps for Download for instance . I only want to show 1359.4 Mbps. So basicaly I want to round it but couldn’t find a way so far.

Is there any way to achieve this aswell?
Thanks.

I’ve edited your post a little bit for making it readable.

Instead of using > for code pastes, use ``` code ```

As for what you want, you can run php inside the template. Take a look to https://docs.librenms.org/Alerting/Templates/ for examples on @php usages

1 Like

Thank you for the examples, now it is sending the alerts as intended.

@foreach ($alert->faults as $key => $value)
** @php echo 'Download : ' . number_format(((($value['ifOutOctets_rate']*8)/$value['ifSpeed'])*100*100),1); @endphp Mbps
** @php echo 'Upload   : ' . number_format(((($value['ifInOctets_rate']*8)/$value['ifSpeed'])*100*100),1); @endphp Mbps
@endforeach

Glad its working as you need. :+1:

1 Like

As mentioned above you can run php code in the alert templates. Try using the php function number_format() - this is what I use to round disk spaces on my disk space alert template, otherwise I would get about 10 decimal places. :smiley:

@foreach ($alert->faults as $key => $value)
Download: {{ number_format((($value['ifOutOctets_rate']*8)/$value['ifSpeed'])*100*100,1) }} Mbps
Upload  : {{ number_format((($value['ifInOctets_rate']*8)/$value['ifSpeed'])*100*100,1) }} Mbps
@endforeach 

The second argument to number_format() specifies how many decimal places you want.

PS yes I know I’m replying to a 2 year old thread but someone may find this useful.

1 Like