Skip to content

A simple command line tool to monitor network workload of linux server.

License

Notifications You must be signed in to change notification settings

wood-j/network-detail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. Monitor Network Detail

A simple command line tool to monitor network workload of linux server.

Main logic:

  1. Use command iftop to capture network detail each 2 seconds
  2. Parse command output and save history data to sqlite3 file network_detail.db.

1.1. env

Develop enviroment:

  • golang: 1.20.6

mod:

go mod tidy

1.2. compile

Use following command to compile binary exec.

CGO_ENABLED=1 go build -a -ldflags '-extldflags "-static"' ./network_detail.go

1.3. run

Run cli with:

  • replace with your network device name, example ens160
./network_detail -i ens160

1.4. systemd

For long term running, we suggest to use systemd service

Create or edit file /usr/lib/systemd/system/network-detail.service:

  • replace with your upload path, example /data/deploy/network_detail
[Unit]
Description=Monitor network detail
After=network.target

[Service]
ExecStart=/data/deploy/network_detail/network_detail 
WorkingDirectory=/data/deploy/network_detail/
Restart=always

[Install]
WantedBy=multi-user.target

Apply changes and restart/status service:

systemctl daemon-reload
systemctl restart network-detail
systemctl enable network-detail
systemctl status network-detail

1.5. Query

Just simple sql query to analysis.

1.5.1. Examples

Query detail:

SELECT * FROM  network_detail ORDER BY time DESC;

Query by minute:

SELECT strftime('%Y-%m-%d %H:%M', time) AS minute, sum(send_bytes) as sum_send_bytes, sum(receive_bytes) as sum_receive_bytes
FROM network_detail
GROUP BY minute
ORDER BY minute DESC;

Filter with condition:

SELECT * FROM (
  SELECT strftime('%Y-%m-%d %H:%M', time) AS minute, sum(send_bytes) as sum_send_bytes, sum(receive_bytes) as sum_receive_bytes
  FROM network_detail
  GROUP BY minute
  ORDER BY minute DESC
)
WHERE sum_send_bytes > 1000000 or sum_receive_bytes > 1000000;

About

A simple command line tool to monitor network workload of linux server.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages