Skip to content

Example: Janus Events

Lorenzo Mangani edited this page Apr 21, 2022 · 16 revisions

Janus Event Handlers link

Just like media and transport plugins, Event Handlers plugins in Janus themselves, meaning their modular nature allows for extensibility. When enabling Event handlers, Janus and other plugins generate real-time events related to several different aspects that may be happening during its lifetime: these events are then passed to all the available event handler plugins, plugins that can then decide to do with these events whatever they want. They might choose to store these events somehow, aggregate, dump or process them, format and send them to an external application, and so on.

❤️ PaStash love Janus Events! (and any JSON payload)

This recipe shows how to handle unstructured objects such as the Janus events with a minimalistic, schemaless and index-less approach for storage in cLoki or Loki using tags and pipelining functions.

Settings

Configure janus.eventhandler.sampleevh.cfg to use paStash as event receiver:

[general]
enabled = yes
events = all
grouping = no
backend = http://localhost:8090

Make sure grouping is not enabled. MQTT and AMQP methods are also supported.

Setup

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

Recipe

Configure paStash to receive and handle the events send by your Janus instance(s):

# Read Janus events from existing files or in realtime - or both!
input {
  file {
    path => "/var/log/janus.log"
    start_index => 0
  }
  http {
    host => 127.0.0.1
    port => 8090
  }
  mqtt {
    address => ["mqtt://broker.hivemq.com"]
    topic => janus1234
  }
}

# Filter json events, use the real timestamp and extract tags of choice
filter {
  json_fields {}
  regex {
    regex => /(\d{13})/
    fields => [timestamp]
    numerical_fields => [timestamp]
  }
  compute_date_field {
    from_field => timestamp
    field => "@timestamp"
    date_format => 'YYYY-MM-DDTHH:mm:ss.SSSZ'
  }
  omit {
    whitelist => ['@timestamp','message', 'opaque_id', 'session_id', 'type']
  }
}

# Ship the tagged events to Loki or any other backend
output {
  loki {
    host => localhost
    port => 3100
    path => "/loki/api/v1/push"
  }
}

Let's LogQL!

That's it! - your events are now sitting in cLoki ready to be queried and used creatively using LogQL in Grafana.

Remember:

  • Logs are not indexed (cheap)
  • Events can be found using Labels (fingerprints) and filtered/transformed by pipelines using extracted Tags

Filter Logs w/ JSON Parsing & Filtering

Let's try a filter to quickly find all events with type 32 and video media type:

{emitter="MyJanusInstance"} | json | type="32" | event_media="video"
{
   "mid":"v1",
   "mindex":1,
   "media":"video",
   "base":90000,
   "rtt":0,
   "lost":0,
   "lost-by-remote":0,
   "jitter-local":0,
   "jitter-remote":0,
   "in-link-quality":0,
   "in-media-link-quality":0,
   "out-link-quality":100,
   "out-media-link-quality":100,
   "packets-received":0,
   "packets-sent":173,
   "bytes-received":0,
   "bytes-sent":87513,
   "bytes-received-lastsec":0,
   "bytes-sent-lastsec":7368,
   "nacks-received":0,
   "nacks-sent":0,
   "retransmissions-received":0
}

Synthetic Timeseries extraction from Logs!

We're now ready to extract any metric from our filtered logs and render it magically. How many packets sent did we log?

avg_over_time({emitter="MyJanusInstance"} | json | type="32" | event_media="video" | unwrap event_packets_sent[1s]) by (type)
Clone this wiki locally