QPS use online log statistics interface

background:

In recent docking sentinel to the project, using the jMeter pressure measurement to determine the rules limiting the value of QPS, QPS value at the same time want to look at the line interface.

material:

Log is the log of the locally generated test pressure, it is important format

2019-07-03T11:16:23+0800|127.0.0.1|-|-|GET|http|127.0.0.1|/iptv/api/new/video/play/get?...
2019-07-03T11:16:23+0800|127.0.0.1|-|-|GET|http|127.0.0.1|/iptv/api/new/video/play/get?...
2019-07-03T11:16:23+0800|127.0.0.1|-|-|GET|http|127.0.0.1|/iptv/api/new/video/play/get?...

problem:

How statistics QPS per second that an interface?

analysis:

See the following logs, 2019-07-03T11: 16: 23 +0800 | 127.0.0.1 | - | - | GET | HTTP | 127.0.0.1 | / the IPTV / API / new new / Video / Play / GET ...; in fact? , we are to count the interface / iptv / api / new / video / play / get the same number of seconds (ie: the number of seconds the same time, 23 2019-07-03T11:: 16 ) the number of occurrences.

Solution:

Throws first command line: tail -f  Host-the access.log | grep '/ IPTV / API / new new / Video / Play / GET' | awk -F '|' '{Print substr ($ 1,1,19)}' | uniq -c

  1. First, the tail -f uninterrupted query log (-f uninterrupted for the latest statistics indicate up log)
  2. Second, we want to lock the specified line (i.e., the access log includes the specified interface), grep command is generally used, such as grep  / IPTV / API / new new / Video / Play / GET , to give a corresponding request line of the log
  3. Taken in the corresponding column second time stage and print (i.e.: 2019-07-03T11: 16: 23 is ), commonly used commands and tools cut awk, Demo here with awk:
    1. The above log format is '|' dividing the designated delimiter is -F parameter awk employed |, after dividing a result we take the first, i.e., $ 1; substr then taken first to 19 (Format : 2019-07-03T11: 16: 21), a print result is printed:
      2019-07-03T11:16:21
      2019-07-03T11:16:21
      2019-07-03T11:16:21
      2019-07-03T11:16:22
      2019-07-03T11:16:22
      2019-07-03T11:16:22
      2019-07-03T11:16:22
      2019-07-03T11:16:23
      2019-07-03T11:16:23
      2019-07-03T11:16:23
      2019-07-03T11:16:23

       

  4. The results were to re statistics, common tools uniq, parameter specifies -c:

    20 2019-07-03T11:05:22
    14 2019-07-03T11:05:23
    22 2019-07-03T11:05:24
    20 2019-07-03T11:05:25
    20 2019-07-03T11:05:26
    20 2019-07-03T11:05:27
    20 2019-07-03T11:05:28

     

Command Line Roundup:

tail -f host-access.log | grep '/iptv/api/new/video/play/get' | awk -F '|' '{print substr($1,1,19)}' | uniq -c

    Obtaining incremental log | line information corresponding to each request | same time the number of seconds taken | count to weight

result:

QPS value of about 20 per second

Note: The use of statistical tools cut QPS, Portal

Published 75 original articles · won praise 48 · Views 350,000 +

Guess you like

Origin blog.csdn.net/KingJin_CSDN_/article/details/94884513