NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
PepperEgg
V2EX  ›  NGINX

win 端 Nginx 如何统计流量?

  •  
  •   PepperEgg · Feb 4, 2021 · 3086 views
    This topic created in 1948 days ago, the information mentioned may be changed or developed.

    目前公司开发一个程序,需要特定场景启 ngixn,windows 端的 nginix 貌似没有选项控制台输出吧,也没有流量统计的选项。从 access log 里面下手的话,也是一些 header 信息。。。感觉不好下手啊,求大佬解答。

    Supplement 1  ·  Feb 7, 2021
    不用 nginx 了。。。
    反正仅用反向代理功能,用 go 另写了一个轮子,弄两个接口,齐活。
    13 replies    2021-02-05 10:44:31 +08:00
    julyclyde
        1
    julyclyde  
       Feb 4, 2021
    即使 linux,控制台也没什么输出啊
    都是从日志统计的
    eason1874
        2
    eason1874  
       Feb 4, 2021
    统计什么流量?

    用 OpenResty 可以在日志阶段统计任何东西,包括请求和响应的信息。

    用 Nginx 自身的 mirror 可以把请求镜像发送到另一个地址,但这样就统计不到响应信息,跟 rewrite 一起配置的时候也麻烦。
    ryanbuu
        3
    ryanbuu  
       Feb 4, 2021   ❤️ 2
    ngixn/nginix 是啥
    PolarBears
        4
    PolarBears  
       Feb 4, 2021   ❤️ 1
    我是配置 log_format 成 json 格式输出到文件,然后使用 filebeat 读取日志文件输出到 elasticsearch,之后可以用 kibana 或者 grafana 统计流量
    PolarBears
        5
    PolarBears  
       Feb 4, 2021
    要简单轻量的话应该用 OpenResty 来做比较好
    Lee2019
        6
    Lee2019  
       Feb 4, 2021
    lua ?
    Lemeng
        7
    Lemeng  
       Feb 4, 2021
    Nginx..好吧
    julyclyde
        8
    julyclyde  
       Feb 4, 2021
    @PolarBears 是自己拼一个 json 字符串吗?学到了。确实比空格分割要好!
    PolarBears
        9
    PolarBears  
       Feb 4, 2021   ❤️ 3
    @julyclyde 注意要配置 escape=json,贴一个我自用的配置:

    log_format main escape=json '{"timestamp":"$time_iso8601",'
    '"server_addr":"$server_addr",'
    '"server_port":"$server_port",'
    '"host":"$host",'
    '"hostname":"$hostname",'
    '"client_addr":"$remote_addr",'
    '"client_port":"$remote_port",'
    '"server_name":"$server_name",'
    '"request_uri":"$request_uri",'
    '"uri":"$uri",'
    '"https":"$https",'
    '"x_forwarded_for":"$http_x_forwarded_for",'
    '"scheme":"$scheme",'
    '"request_method":"$request_method",'
    '"args":"$args",'
    '"referer":"$http_referer",'
    '"http_user_agent":"$http_user_agent",'
    '"request_length":$request_length,'
    '"content_length":"$content_length",'
    '"content_type":"$content_type",'
    '"body_bytes_sent":$body_bytes_sent,'
    '"bytes_sent":$bytes_sent,'
    '"request_time":$request_time,'
    '"status":$status,'
    '"upstream_status": "$upstream_status",'
    '"upstream_addr":"$upstream_addr",'
    '"upstream_time":"$upstream_response_time",'
    '"upstream_cache_status":"$upstream_cache_status"'
    '}';
    PepperEgg
        10
    PepperEgg  
    OP
       Feb 4, 2021
    @q1angch0u 不好意思打字有点快没注意
    PepperEgg
        11
    PepperEgg  
    OP
       Feb 4, 2021
    @PolarBears 可以 研究下。
    learningman
        12
    learningman  
       Feb 4, 2021
    @PolarBears 这么玩不会把 io 堵死吗。。。
    julyclyde
        13
    julyclyde  
       Feb 5, 2021
    @learningman 其实并没有多几个字符吧?一个空格变成俩引号一个逗号而已
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2897 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 103ms · UTC 06:20 · PVG 14:20 · LAX 23:20 · JFK 02:20
    ♥ Do have faith in what you're doing.