Skip to content

Example: Janus Events

Lorenzo Mangani edited this page Oct 3, 2021 · 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

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
  }
}

# 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"
  }
}

Use it

That's it - your events are sitting in Loki ready to be queried and used creatively!

Filter Logs

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"

Chart from Logs!

Let's extract a metric from our filtered logs and render it. 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