Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding rrd-iftraff collector to collect traffic on network interfaces

  • Loading branch information...
commit c63ad7720a7679c8bde4351c5d87c4e7fe8069d8 1 parent 71a8ac0
Antonio Zanardo authored August 20, 2011

Showing 1 changed file with 74 additions and 0 deletions. Show diff stats Hide diff stats

  1. 74  rrd-iftraff
74  rrd-iftraff
... ...
@@ -0,0 +1,74 @@
  1
+#!/usr/bin/env python
  2
+#
  3
+# Copyright (c) J. A. Zanardo Jr. <zanardo@gmail.com>
  4
+# Please refer to COPYING for license details
  5
+# Please refer to README for general instructions
  6
+#
  7
+
  8
+"""
  9
+
  10
+Network interface traffic collector.
  11
+
  12
+Usage:
  13
+
  14
+    rrd-iftraff RRDHOST:RRDPORT RRDNAME INTERFACE
  15
+
  16
+Suggested data configuration:
  17
+
  18
+    --step=60
  19
+    DS:rx:COUNTER:120:0:U
  20
+    DS:tx:COUNTER:120:0:U
  21
+    RRA:AVERAGE:0.5:1:120
  22
+    RRA:AVERAGE:0.5:5:288
  23
+    RRA:AVERAGE:0.5:30:336
  24
+    RRA:AVERAGE:0.5:120:360
  25
+    RRA:AVERAGE:0.5:1440:360
  26
+
  27
+Suggested graph configuration:
  28
+
  29
+    --title=Network traffic on eth0
  30
+    --lower-limit=0
  31
+    DEF:rx=localhost-iftraff-eth0.rrd:rx:AVERAGE
  32
+    DEF:tx=localhost-iftraff-eth0.rrd:tx:AVERAGE
  33
+    CDEF:tx8=tx,8,*
  34
+    CDEF:rx8=rx,8,*
  35
+    VDEF:txt=tx,TOTAL
  36
+    VDEF:rxt=rx,TOTAL
  37
+    AREA:rx8#32CD32:RX
  38
+    GPRINT:rx8:MAX:Max\:%3.0lf%S
  39
+    GPRINT:rx8:AVERAGE:Avg\:%3.0lf%S
  40
+    GPRINT:rx8:LAST:Now\:%3.0lf%Sbits/s\\n
  41
+    LINE1:tx8#0000FF:TX
  42
+    GPRINT:tx8:MAX:Max\:%3.0lf%S
  43
+    GPRINT:tx8:AVERAGE:Avg\:%3.0lf%S
  44
+    GPRINT:tx8:LAST:Now\:%3.0lf%Sbits/s\\n
  45
+    COMMENT:Total\:
  46
+    GPRINT:rxt:%3.3lf%sb RX
  47
+    GPRINT:txt:%3.3lf%sb TX   total transferred (in this graph period)
  48
+
  49
+"""
  50
+
  51
+import socket, sys, re
  52
+
  53
+rrdhost, rrdport = sys.argv[1].split(':')
  54
+rrdname = sys.argv[2]
  55
+interface = sys.argv[3]
  56
+
  57
+rx = None
  58
+tx = None
  59
+
  60
+fp = open('/proc/net/dev')
  61
+for line in fp:
  62
+    s = re.split(' *', line)
  63
+    if s[1] == interface + ':':
  64
+        rx = int(s[2])
  65
+        tx = int(s[10])
  66
+fp.close()
  67
+
  68
+if rx is None or tx is None:
  69
+    exit(1)
  70
+
  71
+# Sending data via UDP
  72
+msg = "%s N:%d:%d" % ( rrdname, rx, tx ) 
  73
+socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(msg, (rrdhost, int(rrdport)))
  74
+sys.stderr.write(msg + '\n')

0 notes on commit c63ad77

Please sign in to comment.
Something went wrong with that request. Please try again.