Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 402719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:09:03+00:00 2026-05-12T17:09:03+00:00

How do I calculate network utilization for both transmit and receive either using C

  • 0

How do I calculate network utilization for both transmit and receive either using C or a shell script?

My system is an embedded linux. My current method is to recorded bytes received (b1), wait 1 second, then recorded again (b2). Then knowing the link speed, I calculate the percentage of the receive bandwidth used.

receive utilization = (((b2 – b1)*8)/link_speed)*100

is there a better method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:09:03+00:00Added an answer on May 12, 2026 at 5:09 pm

    thanks to ‘csl’ for pointing me in the direction of vnstat. using vnstat example here is how I calculate network utilization.

    #define FP32 4294967295ULL
    #define FP64 18446744073709551615ULL
    #define COUNTERCALC(a,b) ( b>a ? b-a : ( a > FP32 ? FP64-a-b : FP32-a-b))
    int sample_time = 2; /* seconds */
    int link_speed = 100; /* Mbits/s */
    uint64_t rx, rx1, rx2;
    float rate;
    
    /* 
     * Either read:
     * '/proc/net/dev' 
     * or 
     * '/sys/class/net/%s/statistics/rx_bytes'
     * for bytes received counter
     */
    
    rx1 = read_bytes_received("eth0"); 
    sleep(sample_time); /* wait */
    rx2 = read_bytes_received("eth0");
    
    /* calculate MB/s first the convert to Mbits/s*/
    rx = rintf(COUNTERCALC(rx1, rx2)/(float)1048576);
    rate = (rx*8)/(float)sample_time;
    
    percent = (rate/(float)link_speed)*100;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following question relevant for ksh script how to calculate the NETWORK IP according
I want to calculate the broadcast of an IP address, I calculated the network
I'm trying to calculate the time it takes to receive all data from a
This program will calculate the average grade for 4 exams using a for loop
I need to be able to monitor the speed of my internal network using
I'm using the igraph package in R to do something rather simple: Calculate the
Well, i'm designing a small affiliate system using PHP and Neo4J in order to
I'm wondering how to calculate number of nodes in CIDR network? for example if
I want to attempt to calculate how much data (bytes) I send/receive over the
In our asp.net 2.0 app we are using httpmodule and httphandler to calculate some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.