There might be cases when an operator needs to know which app are accessing a particular server. E.g:
There is a mysql server with IP 10.225.50.32 listening to connections on port 3306 and the operator wants to know which apps are connecting to it.
The mysql server access logs will show a connection coming from the Diego Cell IP (10.225.50.39 in our example).
Locate the diego cell by running
bosh vms | grep 10.225.50.39
and bosh ssh into it.
Run the following script in the diego cell, changing <port> with the one searching for. In this case, port is 3306
for pid in $(sudo lsns --type=net -o PID | grep -v PID); do
sudo nsenter -n -t "${pid}" netstat -tnap | grep <port>
done
It will show an output as following.
tcp 0 0 10.255.172.23:46946 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:37248 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:56104 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:37238 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:60550 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:56142 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:44854 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:47894 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:44870 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.23:56674 10.225.50.32:3306 ESTABLISHED 2283585/java
tcp 0 0 10.255.172.86:42806 10.225.50.4:3306 ESTABLISHED 2735393/bin/cf-auto
tcp 0 0 10.255.172.86:42812 10.225.50.4:3306 ESTABLISHED 2735393/bin/cf-auto
tcp 0 0 10.255.172.86:42850 10.225.50.4:3306 ESTABLISHED 2735393/bin/cf-auto
tcp 0 0 10.255.172.78:41232 10.225.50.4:3306 ESTABLISHED 2699535/sh
In this case, the server IP is known, which is 10.225.50.32, so the pid connecting to that IP trough port 3306 is 2283585.