extract ip+port from connect
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 24 Jul 2014 19:55:03 +0000 (15:55 -0400)
committerJulien Desfossez <jdesfossez@efficios.com>
Thu, 24 Jul 2014 19:55:03 +0000 (15:55 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
LTTngAnalyzes/common.py
LTTngAnalyzes/syscalls.py
iotop.py

index 9f67021e758f84e49c234b3e903e8262c0661ff6..15edaf18b98cd85b5813b8ec727d4f34b507df48 100644 (file)
@@ -1,6 +1,8 @@
 import math
 import time
 import os
+import socket
+import struct
 from enum import IntEnum
 from socket import AddressFamily
 
@@ -160,3 +162,6 @@ def getFolderSize(folder):
         elif os.path.isdir(itempath):
             total_size += getFolderSize(itempath)
     return total_size
+
+def int_to_ipv4(ip):
+    return socket.inet_ntoa(struct.pack("!I", ip))
index d6111e36285b9337cd704717e4619d6fec8a7b8b..37dd85a2e54e4b562611fa770886d7375cb5d611 100644 (file)
@@ -21,7 +21,7 @@ class Syscalls():
     # list nof syscalls that open a FD on disk (in the exit_syscall event)
     DISK_OPEN_SYSCALLS = ["sys_open", "sys_openat"]
     # list of syscalls that open a FD on the network (in the exit_syscall event)
-    NET_OPEN_SYSCALLS = ["sys_accept", "sys_socket", "sys_connect"]
+    NET_OPEN_SYSCALLS = ["sys_accept", "sys_socket"]
     # list of syscalls that can duplicate a FD
     DUP_OPEN_SYSCALLS = ["sys_fcntl", "sys_dup2"]
     # merge the 3 open lists
@@ -110,6 +110,12 @@ class Syscalls():
             current_syscall["filename"] = event["filename"]
             if event["flags"] & O_CLOEXEC == O_CLOEXEC:
                 current_syscall["cloexec"] = 1
+        elif name in ["sys_accept"] and "family" in event.keys():
+            if event["family"] == AddressFamily.AF_INET:
+                ipport = "%s:%d" % (int_to_ipv4(event["v4addr"]), event["sport"])
+                current_syscall["filename"] = ipport
+            else:
+                current_syscall["filename"] = "socket"
         elif name in Syscalls.NET_OPEN_SYSCALLS:
             current_syscall["filename"] = "socket"
         elif name == "sys_dup2":
@@ -194,6 +200,13 @@ class Syscalls():
             ret_string =  "%s %s(%d)" % (ns_to_hour_nsec(event.timestamp),
                     name, event["fd"])
             self.track_close(name, t, event, c)
+        # when a connect occurs, no new FD is returned, but we can fix
+        # the "filename" if we have the destination info
+        elif name in ["sys_connect"] and "family" in event.keys():
+            if event["family"] == AddressFamily.AF_INET:
+                fd = self.get_fd(t, event["fd"])
+                ipport = "%s:%d" % (int_to_ipv4(event["v4addr"]), event["dport"])
+                fd.filename = ipport
         return ret_string
 
     def get_fd(self, proc, fd):
index 7b234a75f6f096ed6216194498fb21eb69479845..3c4f51c2259c845e2185acdc7215458935923d73 100755 (executable)
--- a/iotop.py
+++ b/iotop.py
@@ -177,6 +177,16 @@ class IOTop():
                 break
         for line in graph.graph('Files Read', values, sort=2):
             print(line)
+        for f in files.values():
+            if f["write"] == 0:
+                continue
+            values.append(("%s %s %s" % (f["name"],
+                convert_size(f["write"]), f["other"]), f["write"]))
+            count = count + 1
+            if limit > 0 and count >= limit:
+                break
+        for line in graph.graph('Files Write', values, sort=2):
+            print(line)
 
     def output_read(self, args):
         count = 0
This page took 0.030541 seconds and 5 git commands to generate.