I make very little money on the book itself because I have a free web-based version hosted on GitHub. However, I don't know how many sales I've foregone because of this.
Curious thing about it is that the GitHub analytics tells you how interested people are in your book. My in-progress book has much more interest just from the analytics. (The Road to Zero. This book explains how to develop your own zero day vulnerabilities for iOS.)
Another thing I think is important is to know the difference between a subject book and a topic book. Subject books provide a wide coverage for a domain. You can make a lot of money if it is a hit. Topic books drill just one detail but authoritatively and comprehensively, so gain you reputation rather than money.
For me, the pleasure is in the research and writing of a book, and having people read it. Professionally, I see it as advertising for my skills. I've landed a FANG role as a result and it certainly makes contracting for roles easier.