Skip to content

Example: Observe JS

Lorenzo Mangani edited this page Jun 4, 2021 · 6 revisions

ObserveRTC + paStash

Much like rtcstats, Observer-js can collect and stream webrtc statistics in JSON format. This recipe shows how to collect and use those statistics with an arbitrary backend such as Loki

Setup

Install pastash & the required plugins using npm

npm install -g @pastash/pastash @pastash/output_loki

Pastash Recipe

The following recipe will provide a websocket receiver for observeRTC statistics on port 9090 and shipping to Grafana Loki Create and store this on your filesystem, ie: /some/path/to/pastash.conf and add in your grafana account details:

input {
  ws {
    host => 0.0.0.0
    port => 9090
    ssl => true
    ssl_key => "/etc/letsencrypt/live/your.domain/privkey.pem"
    ssl_cert => "/etc/letsencrypt/live/your.domain/cert.pem"
  }
}

filter {
  json_fields {}
}

output {
  loki {
    basic_auth_password => "some_very_secure_password_hash_here"
    basic_auth_user => "1234"
    host => "logs-us-west1.grafana.net"
    port => 80
    path => "/api/prom/push"
  }
}

Once you're ready, run your paStash socket manually or using pm2

pastash --config_file=/some/path/to/pastash.conf

ObserveJS Demo

Next, run the ObserveJS demo (or your actual observer.js) and point it at your paStash ws/wss socket:

docker run -it --rm \
    -p 9090:9090 \
    -e __PORT__='9090' \
    -e __OBSERVER_JS__='https://observertc.github.io/observer-js/dist/latest/observer.js' \
    -e __OBSERVER_MARKER__='SAMPLE-OBSERVER-MARKER' \
    -e __OBSERVER_BROWSER_ID__='SAMPLE-SAMPLE-BROWSER-ID' \
    -e __OBSERVER_SERVER_ENDPOINT__='ws://localhost:9090/' \
    --name observer-js-demo observertc/observer-js-demo:latest

... et voila'! Your data is ready to go anywhere.

Loki LogQL

Inbound packetsLost

avg_over_time({ws_port="9090"} 
| json packetsLost="receiverStats.inboundRTPStats[0].packetsLost" 
| __error__="" | packetsLost != "" 
| unwrap packetsLost[5m]) by (browserId)

Inbound Jitter

avg_over_time({ws_port="9090"} 
| json jitter="receiverStats.inboundRTPStats[0].jitter" 
| __error__="" | jitter != "" 
| unwrap jitter [5m]) by (browserId)

For more examples: https://grafana.com/docs/loki/latest/logql/

Clone this wiki locally