-2

My application makes many requests in a day to a webservice (say 172.20.20.20:11111) on a different server.

I would like to know how I can count the number of connections that are established (the number of current connections to the external webservice)

Phil
  • 123
  • 1
  • 1
  • 5

2 Answers2

1

You can log all new outgoing connections to "172.20.20.20:11111" with iptables

iptables -A OUTPUT -m state --state NEW -j LOG --log-prefix "ConnectionTracking"

After that you can get/count all new connections to given IP from your logfile with something like grep "ConnectionTracking" /var/log/YOUR_LOGFILE | wc -l

deagh
  • 2,019
  • 5
  • 19
  • 19
0

You can run

netstat -n | grep 172.20.20.20:11111 | grep ESTABLISHED | wc -l

netstat shows the established TCP sessions. First grep filters the server / port combinations, the second filters established sessions, and finally wc is used to count the number of connections.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63