Skip to content

Instantly share code, notes, and snippets.

@alprut
Last active March 20, 2022 13:01
Show Gist options
  • Save alprut/0646337a1a771d2e3dd1209bb6da4c8f to your computer and use it in GitHub Desktop.
Save alprut/0646337a1a771d2e3dd1209bb6da4c8f to your computer and use it in GitHub Desktop.

Using Grafana Worldmap with Rails

Installation of worldmap panel plugin

$ grafana-cli plugins install grafana-worldmap-panel

Or install a plugin under development which replaces the map by Google Maps Satellite View with the following command.

$ sudo grafana.grafana-cli -pluginUrl https://github.com/ammpio/worldmap-panel/archive/master.zip plugins install grafana-worldmap-panel

Configuration example

Map Data Option

Field Value
Location Data table
Aggregation total

Field Mapping

Field Value
Table Query Format coordinates
Location Name Field value
Metric Field value
Latitude Field latitude
Longitude Field longitude

Query

SELECT
  ts AS "time",
  latitude,
  longitude,
  value
FROM sensor_data
WHERE
  $__timeFilter(ts)
ORDER BY 1

Database Schema on Rails

  create_table "sensor_data", force: :cascade do |t|
    t.datetime "ts", precision: nil
    t.integer "value"
    t.float "latitude"
    t.float "longitude"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

You can create the above schema by the following command.

 $ rails generate model SensorDatum ts:timestamp value:integer latitude:float longitude:float
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment