Changeset 1403
- Timestamp:
- 02/23/07 17:42:40 (6 years ago)
- File:
-
- 1 edited
-
ccsd/trunk/crcnetd/_utils/ccsd_common.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ccsd/trunk/crcnetd/_utils/ccsd_common.py
r1395 r1403 577 577 578 578 return socket.gethostbyname(name) 579 580 def getFQDN(): 581 """Returns the fully qualified hostname of the current host""" 582 fd = os.popen("/bin/hostname -f", "r") 583 hostname = fd.read() 584 fd.close() 585 return hostname.strip() 579 586 580 587 def bitsToNetmask(length): … … 1044 1051 return "" 1045 1052 1053 def getTrafficCounters(): 1054 """Returns a dictionary of the current traffic counters for each interface""" 1055 ifaces = {} 1056 1057 # Read /proc 1058 try: 1059 fp = open("/proc/net/dev", "r") 1060 lines = fp.readlines() 1061 fp.close() 1062 except: 1063 log_error("Could not read interface traffic counters!", sys.exc_info()) 1064 return ifaces 1065 1066 # Parse values, skip first two header lines 1067 for line in lines[2:]: 1068 parts = line.strip().split(":") 1069 if len(parts) != 2: 1070 log_warn("Ignoring invalid /proc/net/dev line: %s" % line) 1071 continue 1072 ifname = parts[0].strip() 1073 counters = parts[1].strip().split() 1074 if len(counters) != 16: 1075 log_warn("Ignoring invalid /proc/net/dev entry '%s': %s" % \ 1076 (ifname, parts[2])) 1077 continue 1078 iface = {"rx":long(counters[0]), "rx_packets":long(counters[1]), \ 1079 "tx":long(counters[8]), "tx_packets":long(counters[9])} 1080 ifaces[ifname] = iface 1081 1082 return ifaces 1083 1046 1084 def route_cmp(a, b): 1047 1085 """Comparison function to sort the route table by netmask then prefix"""
Note: See TracChangeset
for help on using the changeset viewer.
