Skip to content

Instantly share code, notes, and snippets.

@NikolasK-source
Forked from adlerweb/vz.md
Last active June 1, 2020 19:22
Show Gist options
  • Save NikolasK-source/64da9f50b60f1a06ae3a8bfcad05de26 to your computer and use it in GitHub Desktop.
Save NikolasK-source/64da9f50b60f1a06ae3a8bfcad05de26 to your computer and use it in GitHub Desktop.
Grafana MySQL query to visualize Volkszähler-Data

Using Channel-IDs (that's not UUID)

SELECT
  timestamp * 0.001 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) >= $__unixEpochFrom() * 1000 AND 
  (timestamp) <= $__unixEpochTo() * 1000 AND
  properties.pkey = 'title'
ORDER BY timestamp ASC

Using channel names

SELECT
  timestamp * 0.001 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) >= $__unixEpochFrom() * 1000 AND 
  (timestamp) <= $__unixEpochTo() * 1000 AND
  properties.pkey = 'title'
ORDER BY timestamp ASC

Using UUID

SELECT
  timestamp * 0.001 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) >= $__unixEpochFrom() * 1000 AND 
  (timestamp) <= $__unixEpochTo() * 1000 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