Show HN: pg_netstat, a Postgres extension to monitor database network traffic
pg_netstat is a Postgres extension to monitor database network traffic. It uses libpcap to capture packets and aggregates at user-specified interval.
(
25 comments
| 158 points
| on HN
)
Systemd seems to report.network traffic stats for managed units. It spawns cgroups for units which among other things track network traffic.
I have spent some time to search for a tool that can ingest realtime network traffic data to Postgres but have no luck, so I developed this extension and used it internally in our team. Thanks Rust, pgx and libpcap, the development journey is easy and enjoyable.
Would like to hear more feedbacks. Any contributions, feature requests, bug report or ideas are welcomed.
Thanks.
I'd be super interested in tooling to help with this. I'm running – literally right now – a Python script that is writing about 100k flows per second into Postgres (TimescaleDB). It is batch rather than realtime, and it geocodes the flows on the way in.
At that point you have root and can use any of the dozen estabilished ways to do the same thing tho ?
Setup like this:
then do this for the easy interpretable proc files: ) SERVER pglog OPTIONS ( filename '/proc/loadavg', header 'false',delimiter ' ' );For harder things, read the file as lines instead of fields, then create a view with some regexes to split it in fields:
Hardest part is creating semi-legible source code in HN ;-)Postgres isn't a great TSDB - the indexes don't understand columns that will only have updates at one end, it doesn't do column compression, range queries are expensive, etc.
Perhaps it's time to just set up a time series database... Like influxDB.
If anyone's curious about TimescaleDB, it's packaged as an extension to Postgres, optimizing for performance, storage, and analysis of time series data. Implementing columnar compression algorithms is a big part of the secret sauce that makes TimescaleDB a popular choice with Postgres and SQL developers. You can read more about that on the Timescale blog (I'm Timescale's community manager btw). https://www.timescale.com/blog/search/?query=compression
If anyone's curious, the youtube channel may be a good place to start, especially this playlist https://www.youtube.com/playlist?list=PLsceB9ac9MHTtM1XWONMR...