Count number of tcp connections per second











up vote
0
down vote

favorite












I have a service which can only handle a max of 10 requests per second and I need to monitor how often this is exceeded. I have seen various solutions with tcpdump, ss, netstat, ntop but none seem to give what I need. I guess the monitoring would need to be split into two scripts. One collecting the data via tcpdump running as root e.g:



tcpdump -i eth0 src ldapproxy and port ldap and '(tcp-syn|tcp-ack)!=0'


and then another script to analyse the output and give a max queries per second since the last check and this is the bit where I am stuck.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have a service which can only handle a max of 10 requests per second and I need to monitor how often this is exceeded. I have seen various solutions with tcpdump, ss, netstat, ntop but none seem to give what I need. I guess the monitoring would need to be split into two scripts. One collecting the data via tcpdump running as root e.g:



    tcpdump -i eth0 src ldapproxy and port ldap and '(tcp-syn|tcp-ack)!=0'


    and then another script to analyse the output and give a max queries per second since the last check and this is the bit where I am stuck.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a service which can only handle a max of 10 requests per second and I need to monitor how often this is exceeded. I have seen various solutions with tcpdump, ss, netstat, ntop but none seem to give what I need. I guess the monitoring would need to be split into two scripts. One collecting the data via tcpdump running as root e.g:



      tcpdump -i eth0 src ldapproxy and port ldap and '(tcp-syn|tcp-ack)!=0'


      and then another script to analyse the output and give a max queries per second since the last check and this is the bit where I am stuck.










      share|improve this question















      I have a service which can only handle a max of 10 requests per second and I need to monitor how often this is exceeded. I have seen various solutions with tcpdump, ss, netstat, ntop but none seem to give what I need. I guess the monitoring would need to be split into two scripts. One collecting the data via tcpdump running as root e.g:



      tcpdump -i eth0 src ldapproxy and port ldap and '(tcp-syn|tcp-ack)!=0'


      and then another script to analyse the output and give a max queries per second since the last check and this is the bit where I am stuck.







      linux networking monitoring






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 21:06









      Rui F Ribeiro

      38.2k1475125




      38.2k1475125










      asked Apr 4 '16 at 12:02









      Chris Lewis

      11




      11






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Here's some awk to get you started:



          awk '/ > /{
          split($1,t,":"); time = (t[1]*60+t[2])*60+t[3]
          diff = time-lasttime; lasttime = time
          event[++i] = diff; window += diff; tod[i] = $1
          while(window>=1){
          window -= event[1]
          for(j=1;j<i;j++){
          event[j] = event[j+1]
          tod[j] = tod[j+1]
          }
          i--
          }
          if(i+1>10) printf "%d events in %f secs at %sn",i+1,window,tod[i]
          } '


          It keeps (in array event) all the timestamps (converted to float seconds) which are in a running window of 1 second. When the window is exceeded by a new event, the 1st recorded event is removed and all the events shifted down one. i says how many events there are, not counting the one corresponding to the start of the window, which is always at relative time zero. The script prints how many events were in the window when the number exceeds 10. Example output:



          11 events in 0.962827 secs at 14:53:51.262827


          The pattern / > / is to match only incoming packets. You may need to refine this to match the lines that interest you.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            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',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f274190%2fcount-number-of-tcp-connections-per-second%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
            0
            down vote













            Here's some awk to get you started:



            awk '/ > /{
            split($1,t,":"); time = (t[1]*60+t[2])*60+t[3]
            diff = time-lasttime; lasttime = time
            event[++i] = diff; window += diff; tod[i] = $1
            while(window>=1){
            window -= event[1]
            for(j=1;j<i;j++){
            event[j] = event[j+1]
            tod[j] = tod[j+1]
            }
            i--
            }
            if(i+1>10) printf "%d events in %f secs at %sn",i+1,window,tod[i]
            } '


            It keeps (in array event) all the timestamps (converted to float seconds) which are in a running window of 1 second. When the window is exceeded by a new event, the 1st recorded event is removed and all the events shifted down one. i says how many events there are, not counting the one corresponding to the start of the window, which is always at relative time zero. The script prints how many events were in the window when the number exceeds 10. Example output:



            11 events in 0.962827 secs at 14:53:51.262827


            The pattern / > / is to match only incoming packets. You may need to refine this to match the lines that interest you.






            share|improve this answer

























              up vote
              0
              down vote













              Here's some awk to get you started:



              awk '/ > /{
              split($1,t,":"); time = (t[1]*60+t[2])*60+t[3]
              diff = time-lasttime; lasttime = time
              event[++i] = diff; window += diff; tod[i] = $1
              while(window>=1){
              window -= event[1]
              for(j=1;j<i;j++){
              event[j] = event[j+1]
              tod[j] = tod[j+1]
              }
              i--
              }
              if(i+1>10) printf "%d events in %f secs at %sn",i+1,window,tod[i]
              } '


              It keeps (in array event) all the timestamps (converted to float seconds) which are in a running window of 1 second. When the window is exceeded by a new event, the 1st recorded event is removed and all the events shifted down one. i says how many events there are, not counting the one corresponding to the start of the window, which is always at relative time zero. The script prints how many events were in the window when the number exceeds 10. Example output:



              11 events in 0.962827 secs at 14:53:51.262827


              The pattern / > / is to match only incoming packets. You may need to refine this to match the lines that interest you.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Here's some awk to get you started:



                awk '/ > /{
                split($1,t,":"); time = (t[1]*60+t[2])*60+t[3]
                diff = time-lasttime; lasttime = time
                event[++i] = diff; window += diff; tod[i] = $1
                while(window>=1){
                window -= event[1]
                for(j=1;j<i;j++){
                event[j] = event[j+1]
                tod[j] = tod[j+1]
                }
                i--
                }
                if(i+1>10) printf "%d events in %f secs at %sn",i+1,window,tod[i]
                } '


                It keeps (in array event) all the timestamps (converted to float seconds) which are in a running window of 1 second. When the window is exceeded by a new event, the 1st recorded event is removed and all the events shifted down one. i says how many events there are, not counting the one corresponding to the start of the window, which is always at relative time zero. The script prints how many events were in the window when the number exceeds 10. Example output:



                11 events in 0.962827 secs at 14:53:51.262827


                The pattern / > / is to match only incoming packets. You may need to refine this to match the lines that interest you.






                share|improve this answer












                Here's some awk to get you started:



                awk '/ > /{
                split($1,t,":"); time = (t[1]*60+t[2])*60+t[3]
                diff = time-lasttime; lasttime = time
                event[++i] = diff; window += diff; tod[i] = $1
                while(window>=1){
                window -= event[1]
                for(j=1;j<i;j++){
                event[j] = event[j+1]
                tod[j] = tod[j+1]
                }
                i--
                }
                if(i+1>10) printf "%d events in %f secs at %sn",i+1,window,tod[i]
                } '


                It keeps (in array event) all the timestamps (converted to float seconds) which are in a running window of 1 second. When the window is exceeded by a new event, the 1st recorded event is removed and all the events shifted down one. i says how many events there are, not counting the one corresponding to the start of the window, which is always at relative time zero. The script prints how many events were in the window when the number exceeds 10. Example output:



                11 events in 0.962827 secs at 14:53:51.262827


                The pattern / > / is to match only incoming packets. You may need to refine this to match the lines that interest you.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 4 '16 at 14:11









                meuh

                31k11754




                31k11754






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f274190%2fcount-number-of-tcp-connections-per-second%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

                    Accessing regular linux commands in Huawei's Dopra Linux

                    Can't connect RFCOMM socket: Host is down

                    Kernel panic - not syncing: Fatal Exception in Interrupt