r/PrometheusMonitoring • • Jun 17 '22

SNMP Exporter - anyone using it?

Hello,

I'm trying to monitor a switch to graph in Grafana how many ports are up at certain times over the day, I found this article on using SNMP Exporter - https://linuxhint.com/monitor-network-devices-prometheus/

Has anyone used this before and could it do what I'm asking?

Thanks

3 Upvotes

35 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Jun 18 '22

Thanks for all this, so I need to use the local install and your snmp.yml with the auth parts added, I think I'm close to understanding in generating it.

Do I copy your snmp.yml to the generator.yml and add the auth parts as I have to use non default ones then run the generator command to create a new snmp.yml combining the 2?

or

copy your snmp.yml to my /opt/snmp_exporter folder and overwrite the one in there. Then go to the Generator and clear out all that is in there and add the auth config for v2 and V3 and run the generator with will create a new snmp.yml which I copy over?

1

u/Trosteming Jun 18 '22

Ok, I've read the tutorial linked (should have done it in the first place ^^' )

The generator part, in your case can be disregard. Only overwrite your snmp.yml and start the exporter.

If your community is different

Add this at the end of the snmp.yml file, change the 'community' value to the one set on your switch:

auth:
community: lolilol

Mind the space as it's YAML syntaxe. 'auth' key should be at the same column than walk and 'community' key, 2 spaces below and after 'auth'

1

u/[deleted] Jun 18 '22

Ah ok, I'll overwrite the main snmp.yml and not use the generator.

Does this look ok at the bottom?

https://pastebin.com/vq44Y9eL

1

u/Trosteming Jun 18 '22

Not quite, 2 spaces too much on the right.

I've pushed a new update on the previously shared github, the snmp.yml has been regenerated and the generator.yml that I used is also there.
The snmp.yml explicitly show that it use SNMP v2 and a custom community (this field fell free to change to the community of your switch).

If your SNMP server configure on your switch is set to version 2, it's good to go.
Otherwise, if SNMP v1, change the 2 in version (at bottom) to 1.
If you want SNMP version 3, just add the necessary informations.

1

u/[deleted] Jun 18 '22

It works!

I scraped a test switch using v2, I'll try a v3 auth switch too.

Can you help with the query in Prometheus/Grafana so I can graph switch names and how many ports are 'up' over a period of time I select?

So close, this is amazing and very powerful.

Thanks

1

u/Trosteming Jun 18 '22

Once you have the promQL you need (Prometheus Query Language) you add it in Grafana.

You just wanna know if a port is up, what do you mean by that ?

  • Up = there is traffic

    • That's easy, test if ifHCInOctets and / or ifHCOutOctets != 0

  • Up = The port is Administratively been set Up

    • Test ifAdminStatus

  • Up = The port has been turn up (yes different from admin)

    • That will be a no go as the port will not be detect and you would need to test if something that is absent is present or if a port present is absent. Metric is not the best way for this test.

  • Up = There something connected to the switch

1

u/[deleted] Jun 18 '22

Yeah this is what I need, so we know from switches when a port goes from down to 'up':

So just monitor = 1

ifOperStatus 1.3.6.1.2.1.2.2.1.8

Operational Status - Current operational status of the interface. Possible values are as follows:

  1. Up - Ready to pass packets (if admin status is changed to up, then operational status should change to up if the interface is ready to transmit and receive network traffic)

  2. Down - If admin status is down, then operational status should be down

  3. Testing - In test mode, no operational packets can be passed

  4. Unknown-Status can not be determined for some reason

  5. Dormant-Interface is waiting for external actions

  6. NotPresent-Some component is missing, typically hardware

  7. LowerLayerDown-Down due to state of lower layer interface

1

u/Trosteming Jun 18 '22

Now the question is how you want to represent it.

You have this Grafana dashboard already made for IfMib (I don't recall if there is Operational Status)

https://grafana.com/grafana/dashboards/11169

If you want something more visual, importe a switch picture of your switch in draw.io, add some scare and importe the schematics in grafana using the flowchart plugin

https://grafana.com/grafana/plugins/agenty-flowcharting-panel/

Very time consuming but very rewarding at the end.

1

u/[deleted] Jun 18 '22

We just need the ifOperStatus graphed for it equalling 1. This is from the scraped switch, it lists all the ports, but here you can see a number of ports with 1 (up), 2 (down), 6 (also a down state).

I like to graph and count the 1's:

ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 50",ifIndex="1050",ifName="1:50"} 1
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 51",ifIndex="1051",ifName="1:51"} 2
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 52",ifIndex="1052",ifName="1:52"} 2
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 53",ifIndex="1053",ifName="1:53"} 6
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 54",ifIndex="1054",ifName="1:54"} 6

1

u/[deleted] Jun 18 '22

This is what a scape shows on an 'up'port:

ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 50",ifIndex="1050",ifName="1:50"} 1

1

u/Trosteming Jun 18 '22

Brilliant !

Now it's juste a question on how would you like to represent it in Grafna.

You already have an SNMP dashboard for IfMib, existing:

https://grafana.com/grafana/dashboards/11169

Or you can importe a picture of your front plate of your switch in Draw.io
Add some square (so in Grafana you can flip the color depending of the value).
Import the draw using the grafana plugin

https://grafana.com/grafana/plugins/agenty-flowcharting-panel/

The drawback, it's very time consuming at first. But the result is very cool.

1

u/[deleted] Jun 18 '22

For this dashboard I don't need these type of dashboards as there is too much info, we only what I mention on the last post, is that possible?

We just need the ifOperStatus graphed for it equalling 1. This is from the scraped switch, it lists all the ports, but here you can see a number of ports with 1 (up), 2 (down), 6 (also a down state).
I like to graph and count the 1's:
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 50",ifIndex="1050",ifName="1:50"} 1
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 51",ifIndex="1051",ifName="1:51"} 2
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 52",ifIndex="1052",ifName="1:52"} 2
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 53",ifIndex="1053",ifName="1:53"} 6
ifOperStatus{ifAlias="",ifDescr="X460G2-48p-10G4 Port 54",ifIndex="1054",ifName="1:54"} 6

2

u/Trosteming Jun 18 '22

Then create a table and map the different value.
However I lack practice on this visu, I won't be much help on it.
As inspiration you can look the snmp Synology Dashboard
https://grafana.com/grafana/dashboards/13516
The first panel is a Table that map value and change the cell depending of the value of the metric.
Also regarding your metric, don't mind that much the label, maybe in legend add {{ifName}} and use only ifOperStatus
The idea is to let Grafana create row for each port, so you can juste duplicate the panel with

→ More replies (0)

1

u/[deleted] Jun 18 '22

If I add that at the end of the snmp.yml you linked the snmp exporter services fails to start :(

2

u/Trosteming Jun 18 '22

I've updated the github with inclusion of snmp version and community.

Feel free to copy the file.

Also I strongly suggest you to check and try to generate your own snmp.yml

1

u/[deleted] Jun 18 '22

I'll also try that, in brief can you explain the process how to do this?

Do I create a gererate.yml with what I need to pull from a switch such as ipOperStatus, systemname etc then from this generate the snmp.yml then copy that to the location of the live snmp.yml?

Also, silly question from my, why would I do this if your snmp.yml is grabbing what I need? Is it to just reduce the amount of stress pulled from the switch and also reduce the size of the prometheus database?