How To Monitor Cisco Switches IN/OUT Traffic Using Prometheus and Grafana

10,546 views
Skip to first unread message

Emmanuel Yong

unread,
Jun 3, 2017, 1:11:05 AM6/3/17
to Prometheus Users
Dear All,

Just Sharing A Quick Guide On How To Monitor Cisco Switches IN/OUT Traffic Using Prometheus and Grafana

What Is Required:
- Prometheus
- SNMP_Exporter for Prometheus
- Grafana

SNMP.yml Configuration

ciscosw: 
  version: 2
  auth:
    community: public

  walk:
  - 1.3.6.1.4.1.9.9.13.1.4.1
  - 1.3.6.1.2.1.1.3
  - 1.3.6.1.2.1.2.2.1.4
  - 1.3.6.1.2.1.2
  - 1.3.6.1.2.1.31.1
  - 1.3.6.1.2.1.31.1.1.1

  metrics:
  - name: ciscoEnvMonFanState
    oid: 1.3.6.1.4.1.9.9.13.1.4.1.3.1057
    type: gauge

  - name: sysUpTime
    oid: 1.3.6.1.2.1.1.3
    type: gauge

  - name: ifHCInOctets
    oid: 1.3.6.1.2.1.31.1.1.1.6
    type: gauge
    indexes:
    - labelname: interface
      type: gauge

    lookups:
       - labels: [interface]
         oid: 1.3.6.1.2.1.2.2.1.2
         labelname: interface
         type: DisplayString
       - labels: [interface]
         oid: 1.3.6.1.2.1.31.1.1.1.18
         labelname: alias
         type: DisplayString         

  - name: ifHCOutOctets
    oid: 1.3.6.1.2.1.31.1.1.1.10
    type: gauge
    indexes:
    - labelname: interface
      type: gauge   
      
    lookups:
       - labels: [interface]
         oid: 1.3.6.1.2.1.2.2.1.2
         labelname: interface
         type: DisplayString      
       - labels: [interface]
         oid: 1.3.6.1.2.1.31.1.1.1.18
         labelname: alias
         type: DisplayString

Prometheus.yml Confguration

  - job_name: 'snmp'
    static_configs:
      - targets: ['1.1.1.1','2.2.2.2']   
    metrics_path: /snmp
    params:
      module: [ciscosw]
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - source_labels: []
        target_label: __address__
        replacement: 127.0.0.1:9116

Grafana Configuration

Templating Configuration


Retrieve Switches Device Name
Variable: $device
Query: label_values({job="snmp"},instance)


Retrieve Switches Interface
Variable: $Interface
Query: query_result(ifHCOutOctets{job="snmp",instance="$Device"})
Regex: .interface="(.?)",.*


Metrics Query


To Get Inbound Traffic
irate(ifHCInOctets{job='snmp',instance='$Device',interface=~'$Interface'}[5m])*8


To Have More Meaningful legend, I Use The Following
{{interface}} - In


To Get Outbound Traffic
irate(ifHCOutOctets{job='snmp',instance=~'$Device',interface=~'$Interface'}[5m]) * 8


To Have More Meaningful legend, I Use The Following
{{interface}} - Out


Hope This Quick Configuration Guide Will Help Someone Out There, and If Need More Info or Improve Further. Give A Comment


Thank You

nisha...@gmail.com

unread,
Feb 6, 2018, 8:18:32 AM2/6/18
to Prometheus Users

Hello Emmanuel, 

Thanks for sharing this post! 

I am trying to do the same setup and it appears that the Query: query_result(ifHCOutOctets{job="snmp",instance="$Device"})  is not returning a interface name.  Instead it returns the following output.  I am not sure whats missing!  Any help is much appreciated. 

ifInOctets{ifIndex="151060481",instance="<MYSWITCHIP>",job="snmp"} 0 1517922850000


Regards
Nishanth

Emmanuel Yong

unread,
Feb 7, 2018, 7:50:13 PM2/7/18
to Prometheus Users
Dear Nishanth,

Here is a snippet of my snmp.yml

  - name: ifHCInOctets
    oid: 1.3.6.1.2.1.31.1.1.1.6
    type: gauge
    help: The total number of octets received on the interface, including framing
      characters - 1.3.6.1.2.1.31.1.1.1.6
    indexes:
    - labelname: interface
      type: gauge

    lookups:
       - labels: [interface]
         oid: 1.3.6.1.2.1.2.2.1.2
         labelname: interface
         type: DisplayString
       - labels: [interface]
         oid: 1.3.6.1.2.1.31.1.1.1.18
         labelname: alias
         type: DisplayString         

  - name: ifHCOutOctets
    oid: 1.3.6.1.2.1.31.1.1.1.10
    type: gauge
    help: The total number of octets transmitted out of the interface, including framing
      characters - 1.3.6.1.2.1.31.1.1.1.10
    indexes:
    - labelname: interface
      type: gauge   
      
    lookups:
       - labels: [interface]
         oid: 1.3.6.1.2.1.2.2.1.2
         labelname: interface
         type: DisplayString      
       - labels: [interface]
         oid: 1.3.6.1.2.1.31.1.1.1.18
         labelname: alias
         type: DisplayString

Basically You need to reference the interface name to its appropriate index

nid...@gmail.com

unread,
Feb 7, 2018, 8:12:33 PM2/7/18
to Prometheus Users
Nishanth, 

In the "Regex" field, enter: 

/.interface="(.*)",.*/

Also, the variable names are case sensitive, therefore if you use $device, change the second query to :

query_result(ifHCOutOctets{job="snmp",instance="$device"})

nisha...@gmail.com

unread,
Feb 15, 2018, 4:54:47 AM2/15/18
to Prometheus Users
Thank you. So its working after the changes mentioned. 

I would like to monitor CPU/PSU/Interface resets etc... and I have defined a new module cisco_sw in my snmp.yml for this. I am able to use my SNMP exporter and walk the OIDs. Now I have if_mib module also exists in my SNMP.yml. How can I use two modules to scrape a single set of target in prometheus? 

Regards
Nishanth

Brian Brazil

unread,
Feb 15, 2018, 5:05:14 AM2/15/18
to nisha...@gmail.com, Prometheus Users
On 15 February 2018 at 09:54, <nisha...@gmail.com> wrote:
Thank you. So its working after the changes mentioned. 

I would like to monitor CPU/PSU/Interface resets etc... and I have defined a new module cisco_sw in my snmp.yml for this. I am able to use my SNMP exporter and walk the OIDs. Now I have if_mib module also exists in my SNMP.yml. How can I use two modules to scrape a single set of target in prometheus? 

You can only scrape one module at a time, so create a combined module with the config from both.

Brian
 

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/2a3ba8c0-23a5-45ef-9b06-c89a48e53047%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Nishanth

unread,
Feb 15, 2018, 5:48:32 AM2/15/18
to Brian Brazil, Prometheus Users
Hello Bryan,

Ok, but what if I duplicate the prometheus job with a different module name? Which one is more efficient? Combining the module in to a single one or duplicating the jobs? 

The context is suppose if I have different vendor appliances to monitor, certain OIDs will be specific to that vendor hence It doesn’t make sense to walk all OIDs.  

Regards 
Nishant 

To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.

To post to this group, send email to promethe...@googlegroups.com.
--
_Sent from my IPhone

Brian Brazil

unread,
Feb 15, 2018, 6:29:45 AM2/15/18
to Nishanth, Prometheus Users
On 15 February 2018 at 10:48, Nishanth <nisha...@gmail.com> wrote:
Hello Bryan,

Ok, but what if I duplicate the prometheus job with a different module name? Which one is more efficient? Combining the module in to a single one or duplicating the jobs? 

The efficiency difference is minor, you want one job for sanity. 

The context is suppose if I have different vendor appliances to monitor, certain OIDs will be specific to that vendor hence It doesn’t make sense to walk all OIDs.  

It's (usually) harmless to walk additional OIDs, but I would long term expect to end up with a module per device type/role. 

Brian
 

Regards 
Nishant 

To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.

To post to this group, send email to prometheus-users@googlegroups.com.
--
_Sent from my IPhone



--

netr...@gmail.com

unread,
Sep 19, 2018, 10:52:07 PM9/19/18
to Prometheus Users
Hi !

Where do I place the authentication config for the different devices?

It looks like I have to write it per module in snmp.yml being generated by generate.

How to override that acording to the device being observed?

Regards,

quinta-feira, 15 de Fevereiro de 2018 às 09:29:45 UTC-2, Brian Brazil escreveu:
On 15 February 2018 at 10:48, Nishanth <nisha...@gmail.com> wrote:
Hello Bryan,

Ok, but what if I duplicate the prometheus job with a different module name? Which one is more efficient? Combining the module in to a single one or duplicating the jobs? 

The efficiency difference is minor, you want one job for sanity. 

The context is suppose if I have different vendor appliances to monitor, certain OIDs will be specific to that vendor hence It doesn’t make sense to walk all OIDs.  

It's (usually) harmless to walk additional OIDs, but I would long term expect to end up with a module per device type/role. 

Brian
 

Regards 
Nishant 

To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.

To post to this group, send email to promethe...@googlegroups.com.
--
_Sent from my IPhone



--

k...@wetech.io

unread,
Oct 13, 2018, 7:35:25 AM10/13/18
to Prometheus Users
Thanks! working for Meraki gear as well:)
Reply all
Reply to author
Forward
0 new messages