How to check network usage over past X minutes











up vote
1
down vote

favorite
1












I have a media PC (that is also a web test server on the LAN) that I want to reboot every so often as long as it is not in use. I have tests in place for the server using kodi, myth etc (its the display for kodi as well), however, I need to test if anything is using it over the network (file copying, developing websites, watching something etc).



I figure the easiest way to do this is find out how much data has been transferred over the network in the last 3mins or so. How can I do this from a bash script (.sh file run by cron)?










share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    I have a media PC (that is also a web test server on the LAN) that I want to reboot every so often as long as it is not in use. I have tests in place for the server using kodi, myth etc (its the display for kodi as well), however, I need to test if anything is using it over the network (file copying, developing websites, watching something etc).



    I figure the easiest way to do this is find out how much data has been transferred over the network in the last 3mins or so. How can I do this from a bash script (.sh file run by cron)?










    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I have a media PC (that is also a web test server on the LAN) that I want to reboot every so often as long as it is not in use. I have tests in place for the server using kodi, myth etc (its the display for kodi as well), however, I need to test if anything is using it over the network (file copying, developing websites, watching something etc).



      I figure the easiest way to do this is find out how much data has been transferred over the network in the last 3mins or so. How can I do this from a bash script (.sh file run by cron)?










      share|improve this question













      I have a media PC (that is also a web test server on the LAN) that I want to reboot every so often as long as it is not in use. I have tests in place for the server using kodi, myth etc (its the display for kodi as well), however, I need to test if anything is using it over the network (file copying, developing websites, watching something etc).



      I figure the easiest way to do this is find out how much data has been transferred over the network in the last 3mins or so. How can I do this from a bash script (.sh file run by cron)?







      bash cron transfer network-monitoring






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 7 '16 at 1:28









      MicWit

      264312




      264312






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          OK, solution found by using rx_bytes and tx_bytes (received and transmitted bytes, can also use packets or check for dropped packets, see: http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html)



          The script:



          #!/bin/bash

          R1=$(cat /sys/class/net/eth0/statistics/rx_bytes)
          T1=$(cat /sys/class/net/eth0/statistics/tx_bytes)
          sleep $test_time
          R2=$(cat /sys/class/net/eth0/statistics/rx_bytes)
          T2=$(cat /sys/class/net/eth0/statistics/tx_bytes)

          tot=$(( (R2 + T2 - R1 - T1) / 1024 ))

          echo $tot


          Example of use (remember to throw in the amount of time in seconds):



          test_time=10 ~/test.sh


          This would check how many KB were sent/received over a 10 second period. Of course you can edit the script to include only R or T if you just want the sent or received value etc. This command will work from another .sh file or within the terminal, over SSH etc.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f730661%2fhow-to-check-network-usage-over-past-x-minutes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            OK, solution found by using rx_bytes and tx_bytes (received and transmitted bytes, can also use packets or check for dropped packets, see: http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html)



            The script:



            #!/bin/bash

            R1=$(cat /sys/class/net/eth0/statistics/rx_bytes)
            T1=$(cat /sys/class/net/eth0/statistics/tx_bytes)
            sleep $test_time
            R2=$(cat /sys/class/net/eth0/statistics/rx_bytes)
            T2=$(cat /sys/class/net/eth0/statistics/tx_bytes)

            tot=$(( (R2 + T2 - R1 - T1) / 1024 ))

            echo $tot


            Example of use (remember to throw in the amount of time in seconds):



            test_time=10 ~/test.sh


            This would check how many KB were sent/received over a 10 second period. Of course you can edit the script to include only R or T if you just want the sent or received value etc. This command will work from another .sh file or within the terminal, over SSH etc.






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              OK, solution found by using rx_bytes and tx_bytes (received and transmitted bytes, can also use packets or check for dropped packets, see: http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html)



              The script:



              #!/bin/bash

              R1=$(cat /sys/class/net/eth0/statistics/rx_bytes)
              T1=$(cat /sys/class/net/eth0/statistics/tx_bytes)
              sleep $test_time
              R2=$(cat /sys/class/net/eth0/statistics/rx_bytes)
              T2=$(cat /sys/class/net/eth0/statistics/tx_bytes)

              tot=$(( (R2 + T2 - R1 - T1) / 1024 ))

              echo $tot


              Example of use (remember to throw in the amount of time in seconds):



              test_time=10 ~/test.sh


              This would check how many KB were sent/received over a 10 second period. Of course you can edit the script to include only R or T if you just want the sent or received value etc. This command will work from another .sh file or within the terminal, over SSH etc.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                OK, solution found by using rx_bytes and tx_bytes (received and transmitted bytes, can also use packets or check for dropped packets, see: http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html)



                The script:



                #!/bin/bash

                R1=$(cat /sys/class/net/eth0/statistics/rx_bytes)
                T1=$(cat /sys/class/net/eth0/statistics/tx_bytes)
                sleep $test_time
                R2=$(cat /sys/class/net/eth0/statistics/rx_bytes)
                T2=$(cat /sys/class/net/eth0/statistics/tx_bytes)

                tot=$(( (R2 + T2 - R1 - T1) / 1024 ))

                echo $tot


                Example of use (remember to throw in the amount of time in seconds):



                test_time=10 ~/test.sh


                This would check how many KB were sent/received over a 10 second period. Of course you can edit the script to include only R or T if you just want the sent or received value etc. This command will work from another .sh file or within the terminal, over SSH etc.






                share|improve this answer












                OK, solution found by using rx_bytes and tx_bytes (received and transmitted bytes, can also use packets or check for dropped packets, see: http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html)



                The script:



                #!/bin/bash

                R1=$(cat /sys/class/net/eth0/statistics/rx_bytes)
                T1=$(cat /sys/class/net/eth0/statistics/tx_bytes)
                sleep $test_time
                R2=$(cat /sys/class/net/eth0/statistics/rx_bytes)
                T2=$(cat /sys/class/net/eth0/statistics/tx_bytes)

                tot=$(( (R2 + T2 - R1 - T1) / 1024 ))

                echo $tot


                Example of use (remember to throw in the amount of time in seconds):



                test_time=10 ~/test.sh


                This would check how many KB were sent/received over a 10 second period. Of course you can edit the script to include only R or T if you just want the sent or received value etc. This command will work from another .sh file or within the terminal, over SSH etc.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 7 '16 at 4:54









                MicWit

                264312




                264312






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f730661%2fhow-to-check-network-usage-over-past-x-minutes%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                    Eduardo VII do Reino Unido