Sign inSign up

frozenmountain/liveswitch-usage-service

By frozenmountain

Updated about 3 years ago

LiveSwitch Usage Service releases.

Image
0

512

frozenmountain/liveswitch-usage-service repository overview

The LiveSwitch Usage Service collects connection and client events from the LiveSwitch servers and aggregates daily usage based on them.

Quick Start

Do the following:

  1. Create a network for your server cluster:
    sudo docker network create liveswitch
  1. Start Postgres:
    sudo docker run -d \
        --env POSTGRES_PASSWORD='password' \
        --network liveswitch \
        --publish 5432:5432 \
        --restart always \
        --name postgres \
        postgres
  1. Create two databases for collecting events and storing usage:
    sudo docker exec -it postgres \
        psql "postgresql://postgres:password@localhost" -c "CREATE DATABASE liveswitch_events;"

    sudo docker exec -it postgres \
        psql "postgresql://postgres:password@localhost" -c "GRANT ALL PRIVILEGES ON DATABASE liveswitch_events TO postgres;"

    sudo docker exec -it postgres \
        psql "postgresql://postgres:password@localhost" -c "CREATE DATABASE liveswitch_usage;"

    sudo docker exec -it postgres \
        psql "postgresql://postgres:password@localhost" -c "GRANT ALL PRIVILEGES ON DATABASE liveswitch_usage TO postgres;"
  1. Start your LiveSwitch Usage Service docker image.
   sudo docker run -d \
       --env ConnectionStrings:PostgresEvents='User ID=postgres;Password=password;Host=postgres;Port=5432;Database=liveswitch_events' \
       --env ConnectionStrings:PostgresUsage='User ID=postgres;Password=password;Host=postgres;Port=5432;Database=liveswitch_usage' \
       --network liveswitch \
       --publish 80:80 \
       --restart always \
       --name liveswitch-usage-service \
       frozenmountain/liveswitch-usage-service
  1. Configure your LiveSwitch Server to send the following webhook events to your LiveSwitch Usage Service /events endpoint. (e.g. http://localhost/events):
    • connection.connected
    • connection.closed
    • connection.failed
    • connection.initializing
    • channel.client.left

NOTE: All of these webhook events must be configured and sent to the usage service for the usage aggregation to work.

The events can be configured using environment variables on your Gateway or using the LiveSwitch Server Console.

To configure using environment variables, set the following environment variables on your Gateway container:

Applications:0:ApplicationId='my-app-id'
Applications:0:SharedSecret='--replaceThisWithYourOwnSharedSecret--'
Applications:0:Channels:0:ChannelIdPattern='*'
Applications:0:Channels:0:Webhooks:0:Name='LiveSwitch Usage Service'
Applications:0:Channels:0:Webhooks:0:Events:0='connection.connected'
Applications:0:Channels:0:Webhooks:0:Events:1='connection.closed'
Applications:0:Channels:0:Webhooks:0:Events:2='connection.failed'
Applications:0:Channels:0:Webhooks:0:Events:3='connection.initializing'
Applications:0:Channels:0:Webhooks:0:Events:4='channel.client.left'
Applications:0:Channels:0:Webhooks:0:Batch=true
Applications:0:Channels:0:Webhooks:0:Reliable=true
Applications:0:Channels:0:Webhooks:0:Url='http://localhost/events'

To create and configure the webhooks using the LiveSwitch Server Console, see Webhook Configuration.

NOTE: When configuring events using the LiveSwitch Server Console, please make sure the Batch and Reliable checkboxes are checked.

Swagger

The swagger interface can be found by going to the /swagger path of your LiveSwitch Usage Service (e.g. http://localhost/swagger). There are two public endpoints you can access from this interface.

  1. /aggregate

This endpoint will manually start an aggregation for the specified date. The LiveSwitch Usage Service automatically aggregates at the end of the day so calling this endpoint is only necessary if you want to generate daily usage before the end of the day.

  1. /usage

This endpoint returns daily usage. The request can be filtered by an Application ID, as well as start and end dates.

Daily Usage

The daily usage output is JSON formatted as follows

[
  {
    "applicationId": "ApplicationId",
    "startTimestamp": "2023-01-01T00:00:00Z",
    "endTimestamp": "2023-01-01T23:59:59Z",
    "messagesSent": 518
    "messagesReceived": 37,
    "messageBytesSent": 46718,
    "messageBytesReceived": 532,
    "participantMinutes": {
      "0": 968,
      "307200": 1532,
      "921600": 325,
      "2073600": 45,
    },
    "peakConcurrentUsers": 17,
    "createdOn": "2023-01-02T00:00:00.809108Z",
    "signature": ""
  }
]

The participant minutes are separated by resolution (width * height). Common resolutions are:

  • "0" : audio-only
  • "307200": 640 x 480
  • "921600": 1280 x 720 (720p)
  • "2073600": 1920 x 1080 (1080p)

The signature property at the end is required when sending the usage information to the LiveSwitch team. It is enabled as a parameter to the /usage endpoint.

Tag summary

Content type

Image

Digest

sha256:dfdb7e2b2

Size

89 MB

Last updated

about 3 years ago

docker pull frozenmountain/liveswitch-usage-service