# Socket Interface

### Introduction

Collectl actually provides 2 different mechanisms for socket communications and depending on which style you intend to use, you should pick the appropriate one. Regardless of which style you choose, collectl will send all data that might normally go to a terminal to that interface, prepended with the hostname for easy recognition at the other end. One should also note that you can simultaneously record the data locally in a raw file, a file in plot format or even both depending on your needs.

### Short-lived communications

The model for this type of communications is one in which some other tool such as colmux starts collectl on one or more remote systems, instructing it to send its output back to the initiator until the initiator terminates the connection. At this time collectl will permanently exist. Using this style the initiator of the communications opens the socket and then typically starts collectl using ssh and includes its address/port in the command string using collectl's -A switch. The key things to note when using this style are:

- This mechanism will never survive a reboot without extra work on the initiator's part which must include restarting collectl
- As soon as it starts, collectl will open a socket to the specified address and immediately start sending its output back to it
- If the other end of the socket goes away, collectl will exit
- If collectl is unexpectedly terminated (such as sigint or reboot), it will close the socket without warning the other end and therefore the program at the other end of the communication path must be prepared to deal with it

### Long-lived communications

This mechanism has collectl create the initial socket and listen for a remote connection. In this mode, collectl continues to collect data and at the beginning of each monitoring interval looks for a new socket connection request. If it receives a request, collectl then creates a connection back to the requestor and immediately starts sending data to it. If that connection terminates collectl closes down its side and then goes back to listening for a new connection. The key points about this style are:

- This style of communications will survive a reboot if configured in collectl.conf
- The switch to put collectl into this mode is also -A but rather than supplying an address as the argument use the text server
- The other end of the connection needs to periodically try to connect and if it fails must try again. If that connection exits, it must clean up its end and go back to trying to reconnect again.
- If you want collectl to terminate you much manually do so, noting after a reboot it will restart.
- To verify collectl is functioning as expected, run the utility /usr/share/collectl/util/client.pl passing it the address of the system collectl is running on. It will display anything collectl sends to it over the socket.

updated Feb 21, 2011