winshining / nginx-http-flv-module

A media streaming server based on nginx-rtmp-module. In addtion to the features nginx-rtmp-module provides, HTTP-FLV, GOP cache, VHosts (one IP for multi domain names) and JSON style statistics are supported now.
BSD 2-Clause "Simplified" License
2.71k stars 567 forks source link

stat json request #216

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi, I want to use json stat request wut but without success, some problems with the json tree

this work : curl -s http://localhost/stat | jq .... json data ....

But this curl -s http://localhost/stat | jq '.servers[]' gives an error.

What parameters in the request do i have to pass to get applications list for example ?

Thanks

winshining commented 2 years ago

Why jq '.servers'? The most outer key of json is http-flv. So I thought 'jq .http-flv.servers' was OK, but I got a parse error, because in jq, - is a key word.

The following is correct:

jq '.["http-flv"].servers'

The following is the result I have tested:

curl http://localhost:8080/stat | jq '.["http-flv"].servers'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   529  100   529    0     0   103k      0 --:--:-- --:--:-- --:--:--  129k
[
  {
    "port": 1935,
    "server_index": 0,
    "applications": [
      {
        "name": "myapp",
        "live": {
          "streams": [],
          "nclients": 0
        },
        "recorders": {
          "count": 0,
          "lists": []
        }
      }
    ]
  },
  {
    "port": 1975,
    "server_index": 1,
    "applications": [
      {
        "name": "mytest",
        "live": {
          "streams": [],
          "nclients": 0
        },
        "recorders": {
          "count": 0,
          "lists": []
        }
      }
    ]
  }
]
ghost commented 2 years ago

Thanks for this, it's better but why this does not work ? i have one application name called "flv".

curl -s http://localhost/stat | jq '.["http-flv"].servers[] | select(. applications.name == "flv")'

error: jq: error (at :277): Cannot index array with string "name"

Le sam. 4 déc. 2021 à 15:42, XingY Wang @.***> a écrit :

Why jq '.servers'? The most outer key of json is http-flv. So I thought jq .http-flv.servers was OK, but I got a parse error, because in jq, - is a key word.

The following is correct:

jq '.["http-flv"].servers'

The following is the result I have tested:

curl http://localhost:8080/stat | jq '.["http-flv"].servers' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 529 100 529 0 0 103k 0 --:--:-- --:--:-- --:--:-- 129k [ { "port": 1935, "server_index": 0, "applications": [ { "name": "myapp", "live": { "streams": [], "nclients": 0 }, "recorders": { "count": 0, "lists": [] } } ] }, { "port": 1975, "server_index": 1, "applications": [ { "name": "mytest", "live": { "streams": [], "nclients": 0 }, "recorders": { "count": 0, "lists": [] } } ] } ]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/winshining/nginx-http-flv-module/issues/216#issuecomment-986038648, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG7MP54XYTHUANTFYXJ7VADUPISGVANCNFSM5JLNP6CQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- https://Live-Media.fr