V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
PepperEgg
V2EX  ›  NGINX

win 端 Nginx 如何统计流量?

  •  
  •   PepperEgg · 2021-02-04 14:40:15 +08:00 · 2377 次点击
    这是一个创建于 1148 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    第 1 条附言  ·  2021-02-07 09:53:10 +08:00
    不用 nginx 了。。。
    反正仅用反向代理功能,用 go 另写了一个轮子,弄两个接口,齐活。
    13 条回复    2021-02-05 10:44:31 +08:00
    julyclyde
        1
    julyclyde  
       2021-02-04 14:44:45 +08:00
    即使 linux,控制台也没什么输出啊
    都是从日志统计的
    eason1874
        2
    eason1874  
       2021-02-04 15:07:53 +08:00
    统计什么流量?

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

    用 Nginx 自身的 mirror 可以把请求镜像发送到另一个地址,但这样就统计不到响应信息,跟 rewrite 一起配置的时候也麻烦。
    q1angch0u
        3
    q1angch0u  
       2021-02-04 15:17:18 +08:00   ❤️ 2
    ngixn/nginix 是啥
    PolarBears
        4
    PolarBears  
       2021-02-04 15:31:19 +08:00   ❤️ 1
    我是配置 log_format 成 json 格式输出到文件,然后使用 filebeat 读取日志文件输出到 elasticsearch,之后可以用 kibana 或者 grafana 统计流量
    PolarBears
        5
    PolarBears  
       2021-02-04 15:36:33 +08:00
    要简单轻量的话应该用 OpenResty 来做比较好
    Lee2019
        6
    Lee2019  
       2021-02-04 15:59:57 +08:00
    lua ?
    Lemeng
        7
    Lemeng  
       2021-02-04 16:11:49 +08:00
    Nginx..好吧
    julyclyde
        8
    julyclyde  
       2021-02-04 16:39:22 +08:00
    @PolarBears 是自己拼一个 json 字符串吗?学到了。确实比空格分割要好!
    PolarBears
        9
    PolarBears  
       2021-02-04 17:01:38 +08:00   ❤️ 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
       2021-02-04 17:53:02 +08:00
    @q1angch0u 不好意思打字有点快没注意
    PepperEgg
        11
    PepperEgg  
    OP
       2021-02-04 17:53:32 +08:00
    @PolarBears 可以 研究下。
    learningman
        12
    learningman  
       2021-02-04 21:00:12 +08:00
    @PolarBears 这么玩不会把 io 堵死吗。。。
    julyclyde
        13
    julyclyde  
       2021-02-05 10:44:31 +08:00
    @learningman 其实并没有多几个字符吧?一个空格变成俩引号一个逗号而已
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5394 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:47 · PVG 16:47 · LAX 01:47 · JFK 04:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.