select 
    'big_number'  as component
  , 4             as columns
;
-- total Instances
select 
    'Instances'   as title
  , (select count(*) from instances where failure>=0 and failure<5)          as value
;
-- total Users
select 
    'Users'  as title
  , (select sum(users) from (  SELECT 
    instance_id,
	users,
    MAX(insertedAt)
  FROM stats
  GROUP BY instance_id))        as value
;
-- total Groups
select 
    'Groups' as title
  , (select sum(local_groups) from (  SELECT 
    instance_id,
	local_groups,
    MAX(insertedAt)
  FROM stats
  GROUP BY instance_id))   as value
;
-- total Events
select 
    'Events' as title
  , (select sum(local_events) from (  SELECT 
    instance_id,
	local_events,
    MAX(insertedAt)
  FROM stats
  GROUP BY instance_id))   as value
;

----- over time ----
select 
    'title'   as component
  , 'Over time' as contents
;

-- instances
select 
    'chart'             as component
  , 'Instances'  as title
  , 'area'              as type
  , 'blue-lt'           as color
  --, 5                   as marker
  , TRUE                as time
;
SELECT 
    count(instance_id) as y
  , insertedAt  as x
  , insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j 
;
-- users
select 
    'chart'             as component
  , 'Users' as title
  , 'area'              as type
  , 'blue-lt'           as color
  --, 5                   as marker
  , TRUE                as time
;
SELECT 
    sum(users) as y
  , insertedAt  as x
  , insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j 
;
-- events
select 
    'chart'             as component
  , 'Events' as title
  , 'area'              as type
  , 'blue-lt'           as color
  --, 5                   as marker
  , TRUE                as time
;
SELECT 
    sum(local_events) as y
  , insertedAt  as x
  , insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j 
;
-- groups
select 
    'chart'             as component
  , 'Groups' as title
  , 'area'              as type
  , 'blue-lt'           as color
  --, 5                   as marker
  , TRUE                as time
;
SELECT 
    sum(local_groups) as y
  , insertedAt  as x
  , insertedAt / (3600*24) as j
FROM stats
GROUP BY j
order by j 
;
