Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
If you have ever used iftop or any other of the plethora of available network monitoring tools on Linux, you must be at least a bit impressed of the level of detail of information that you can view/summarize through them.
Most of these tools use libpcap to inspect packets in real time and aggregate/store their details; now comes the question: what if I would like to read this information with a webservice API?
An iftopsvc microservice
It turns out this is a neat use-case for a tiny iftop microservice. With this API we could retrieve network usage statistics based on IP address, protocol type and sent/received bytes count.
I went ahead and added a minimal RESTful API to iftop; this is the output of a call to /iftop/history:
Beautiful, isn’t it? There is also a method for /iftop/version that allows reading the current version.
You can run it with:
iftop -SÂ 8080
By default it will drop root privileges to user nobody and group nogroup(configurable).
Enabling the webservice will disable the curses or text-based output and the iftop logging output (on standard error) will become more similar to a webservice:
You can get the latest version of my iftop patches from here:
Upstreaming
In hindsight I am delighted to have chosen iftop because the code comments are hilarious. My best pick:
Also, I haven't implemented removal of items from the tree. So sue me.
The patches have been sent upstream, however I have not received any reply from the maintainer yet. I do not have high hopes in them being accepted but regardless you can already use them and the webservice API feature by cloning the GitHub repository and building iftop.
A RESTful API for iftop was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.