Skip to content

Introduction

BrainFrame uses a powerful dashboarding tool called Grafana in order to allow highly customizable realtime visualizations of the BrainFrame Database and API.

With a little SQL knowledge it is possible to quickly get analytics for any specific problem you need solved.

The default login / pass for the dashboard is admin, admin.

Dashboards

A Dashboard contains various Panels which visually display information about the BrainFrame database. BrainFrame populates automatically with dashboards, such as the Stream Uptime dashboard, which shows graphs of which cameras are being processad and when they have been connected / disconnected.

Creating a Graph

First, create a dashboard by clicking the + on the sidebar. Then, give your dashboard a name by clicking the gear icon on the top right.

Now, it's time to add a Panel. Click the graph icon on the top bar, so you see this:

Let's start by adding a query. Click "Add Query", then click the pencil to edit the query as SQL.

For an example query, the following query will give a simple graph of the number of people who entered or exited the "Front Door" Zone over time

SELECT zone_status.tstamp as time, 
       total_count.count_enter AS entered, 
      total_count.count_exit AS exited FROM zone_status
LEFT JOIN total_count ON total_count.zone_status_id=zone_status.id
LEFT JOIN zone ON zone_status.zone_id=zone.id
WHERE
  total_count.class_name='person' AND
  zone.name='Front Door' AND
  zone_status.id >= (SELECT id FROM zone_status WHERE tstamp >= $__unixEpochFrom() ORDER BY tstamp ASC LIMIT 1) AND
  zone_status.id <= (SELECT id FROM zone_status WHERE tstamp < $__unixEpochTo() ORDER BY tstamp DESC LIMIT 1) 

You might notice that the last two lines of the query are fairly complicated. These lines are intended to allow the query to limit results only to results between two timestamps, and to do so in a very efficient way. The macros $__unixEpochFrom() and $__unixEpochTo() retun the current timestamps that the dashboard user is currently requesting.

Thus, feel free to copy paste the following filter into any slow query in order to limit results in a SQL efficient way:

WHERE 
  zone_status.id >= (SELECT id FROM zone_status WHERE tstamp >= $__unixEpochFrom() ORDER BY tstamp ASC LIMIT 1) AND
  zone_status.id <= (SELECT id FROM zone_status WHERE tstamp < $__unixEpochTo() ORDER BY tstamp DESC LIMIT 1) AND
  "< ANY OTHER CONDITIONALS FOR THE QUERY >"