Skip to content

Instantly share code, notes, and snippets.

@adlerweb adlerweb/vz.md
Created Sep 12, 2018

Embed
What would you like to do?
Grafana MySQL query to visualize Volkszähler-Data

Using Channel-IDs (that's not UUID)

SELECT
  timestamp/1000 as time_sec, 
  data.value as value, 
  properties.value as metric
FROM data
  LEFT JOIN properties ON (properties.entity_id = data.channel_id)
  LEFT JOIN entities ON (entities.id = data.channel_id)
WHERE 
  (channel_id = 1 || channel_id = 2 || channel_id = 3)  AND 
  (timestamp/1000) >= $__unixEpochFrom() AND 
  (timestamp/1000) <= $__unixEpochTo() AND
  properties.pkey = 'title'
ORDER BY timestamp ASC

Using channel names

SELECT
  timestamp/1000 as time_sec, 
  data.value as value, 
  properties.value as metric
FROM data
  LEFT JOIN properties ON (properties.entity_id = data.channel_id)
  LEFT JOIN entities ON (entities.id = data.channel_id)
WHERE 
  (properties.value = "Flur" || properties.value = "Werkstatt" ) AND
  (timestamp/1000) >= $__unixEpochFrom() AND 
  (timestamp/1000) <= $__unixEpochTo() AND
  properties.pkey = 'title'
ORDER BY timestamp ASC

Using UUID

SELECT
  timestamp/1000 as time_sec, 
  data.value as value, 
  properties.value as metric
FROM data
  LEFT JOIN properties ON (properties.entity_id = data.channel_id)
  LEFT JOIN entities ON (entities.id = data.channel_id)
WHERE 
  (uuid = "12345678-1234-1234-1234-1234567890ab" || uuid = "12345678-1234-1234-1234-1234567890ac" ) AND
  (timestamp/1000) >= $__unixEpochFrom() AND 
  (timestamp/1000) <= $__unixEpochTo() AND
  properties.pkey = 'title'
ORDER BY timestamp ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.