Code Monkey home page Code Monkey logo

turn-monitor's Introduction

Turn Monitor

Monitor your turn server, no matter what the turn server is.

Why use this project

At the time released this project, the Coturn #666 has some issue about statistics. So I don't know

  1. What is current active connection amounts ?
  2. Is some specific user active right now ?
  3. How many bandwidth are used by users ?

How it works

Turn monitor would listen on network interface and parse every packet to STUN/TURN related packet.

So it can rely on any TURN server.

How to use

You could run by node js or using docker.

Here are parameters you can use

name usage default vale
port The turn monitor server listen at 3001
verbose set true if you want to see every parsed TURN messages false
networkInterfaceId Which network interface should turn server listen at eth0
removeOutdataInterval How long should turn monitor reset the data 10000 (10s, should present in ms format).

Example

$ docker run --env networkInterfaceId=lo0 --env port=8080 --net=host yuanchieh/turn-monitor

If using docker, it must use the same network with TURN server. That's why I use --net=host.
Remember the Macos and windows doesn't support host network.

or

$ npm install
$ networkInterfaceId=lo0 port=8080 ts-node index.ts

or

$ npm install 
$ npm run build
$ networkInterfaceId=lo0 port=8080 node build/index.js

The API and response

Only one api GET /stats?log={boolean}.
Set log to true if you want to see the last 1000 parsed TURN messages.

sample response with log set to true, otherwise the log would return empty string

{
   "currentUserAmount":2,
   "activeUserList":{
      "127.0.0.1:56171":{
         "username":"hello",
         "channelNumber":"4000",
         "bandwidth":1391,
         "lastUpdateTime":"2021-01-05T23:17:09.772Z"
      },
      "127.0.0.1:60718":{
         "username":"hello",
         "channelNumber":"4000",
         "bandwidth":14035,
         "lastUpdateTime":"2021-01-05T23:17:09.819Z"
      }
   },
   "log":[
      {
         "remoteIp":"127.0.0.1:62376",
         "message":{
            "type":"channelData",
            "number":17470,
            "length":256
         },
         "timestamp":"2021-01-05T23:17:01.379Z"
      },
      {
         "remoteIp":"127.0.0.1:58068",
         "message":{
            "type":"channelData",
            "number":17470,
            "length":33155
         },
         "timestamp":"2021-01-05T23:17:01.379Z"
      },
      {
         "remoteIp":"127.0.0.1:56171",
         "message":{
            "type":"stunMessage",
            "class":"request",
            "method":"refresh",
            "transactionId":"3638426662776b784165366a",
            "attributeList":{
               "lifetime":{
                  "length":16,
                  "value":"00000000",
                  "name":"lifetime"
               },
               "username":{
                  "length":24,
                  "value":"hello",
                  "name":"username"
               },
               "realm":{
                  "length":32,
                  "value":"localhost",
                  "name":"realm"
               },
               "nonce":{
                  "length":40,
                  "value":"37373237643431396565623562343732",
                  "name":"nonce"
               },
               "messageIntegrity":{
                  "length":48,
                  "value":"4c8bb5b8f8f677aef9707b8a3125d7f9b463bf21",
                  "name":"messageIntegrity"
               }
            }
         },
         "timestamp":"2021-01-05T23:17:09.772Z"
      },
      {
         "remoteIp":"127.0.0.1:3478",
         "message":{
            "type":"stunMessage",
            "class":"response",
            "method":"refresh",
            "transactionId":"3638426662776b784165366a",
            "attributeList":{
               "lifetime":{
                  "length":16,
                  "value":"00000000",
                  "name":"lifetime"
               },
               "software":{
                  "length":56,
                  "value":"Coturn-4.5.2 'dan Eider'",
                  "name":"software"
               },
               "messageIntegrity":{
                  "length":48,
                  "value":"7aa003c057278874da15c2836fd935aacc58aaaf",
                  "name":"messageIntegrity"
               },
               "fingerprint":{
                  "length":16,
                  "value":"574523d3",
                  "name":"fingerprint"
               }
            }
         },
         "timestamp":"2021-01-05T23:17:09.783Z"
      },
      {
         "remoteIp":"127.0.0.1:3478",
         "message":{
            "type":"channelData",
            "number":16384,
            "length":39
         },
         "timestamp":"2021-01-05T23:17:09.819Z"
      },
      {
         "remoteIp":"127.0.0.1:60718",
         "message":{
            "type":"channelData",
            "number":16384,
            "length":39
         },
         "timestamp":"2021-01-05T23:17:09.819Z"
      },
      {
         "remoteIp":"127.0.0.1:3478",
         "message":{
            "type":"channelData",
            "number":16384,
            "length":39
         },
         "timestamp":"2021-01-05T23:17:09.821Z"
      },
      {
         "remoteIp":"127.0.0.1:60718",
         "message":{
            "type":"stunMessage",
            "class":"request",
            "method":"refresh",
            "transactionId":"4e58623475464d4267712b59",
            "attributeList":{
               "lifetime":{
                  "length":16,
                  "value":"00000000",
                  "name":"lifetime"
               },
               "username":{
                  "length":24,
                  "value":"hello",
                  "name":"username"
               },
               "realm":{
                  "length":32,
                  "value":"localhost",
                  "name":"realm"
               },
               "nonce":{
                  "length":40,
                  "value":"65616264346362363165366433373663",
                  "name":"nonce"
               },
               "messageIntegrity":{
                  "length":48,
                  "value":"e35dc75ba97d2c923e524b0f175b7fb9785a0481",
                  "name":"messageIntegrity"
               }
            }
         },
         "timestamp":"2021-01-05T23:17:09.830Z"
      }
   ]
}

Can I rely on this project

I used in production and it serves well.
At least it doesn't crash or eating up memory.
Find any problem or any suggestion, feel free to open issue.

turn-monitor's People

Contributors

sj82516 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

turn-monitor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.