Determining Shock Length
To figure the compressed dimension, take an eye-to-eye (stud-to-stud) measurement with the truck at rest. From this dimension, subtract the distance between the bump stops. This is your nominal compressed dimension. It is also a good idea to go at least 1/2" shorter to allow for bump stop compression.
This assumes the shocks are mounted vertically and the axle also moves vertically. In cases other than this, the shock movement will generally be less.
If possible, shock measurements should also be taken with the axle at full compression to ensure dimensions are correct. This can be done by twisting up the suspension on a ramp or obstacle, or articulating the suspension by some other means.
Next, jack up the vehicle, or somehow twist it up, to see how much droop you get (with the original shock disconnected). It may also be helpful to disconnect your sway bar as well.
On leaf spring suspensions, you may see the maximum droop as the point where you run out of spring/shackle length and the axle cannot drop any further. Or.... you may have other limiting factors such as tire interference, spring bind, etc.
Get an approximate length from this and then start checking for shocks of the appropriate length in a shock vendor catalog. You may find a shock that matches your range well or you may have to go through a few iterations of comparing available lengths and your travel movement, and possibly consider modifying your existing shock mounts to maximize your shock travel.
A FEW OTHER NOTES........
If you are cutting the dimension close on either compression or extension, note also the effects on movement of the shocks leaning forward or backward, as their travel distances will be different.
For instance, for a given amount of rear axle droop on a vehicle with leaf springs (rear mounted shackle), the shock leaning backwards away from the axle will travel more during droop than will the shock leaning forward.