Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Based on <https://quantumleap.readthedocs.io/>.
Start the show:

``` shell name=start
task compose -- pull
task compose -- up --detach --wait
task install
task start

open https://orion.quantumleap.local.itkdev.dk
open https://grafana.quantumleap.local.itkdev.dk
Expand Down Expand Up @@ -75,6 +75,57 @@ task compose -- exec --no-TTY orion curl --silent --show-error localhost:1026/v2
EOF
```

``` shell name=scorpio-entity-create
# https://fiware-scorpio.readthedocs.io/en/master/user/walkthrough_apiv2.html#entity-creation
task compose -- exec --no-TTY scorpio curl --silent --show-error localhost:9090/ngsi-ld/v1/entities --header 'content-type: application/json' --data @- <<EOF
{
"id": "urn:room1",
"type": "Room",
"temperature": {
"value": 23,
"type": "Float"
},
"pressure": {
"value": 720,
"type": "Integer"
}
}
EOF
```

``` shell name=scorpio-entity-get
task compose -- exec --no-TTY scorpio curl --silent --show-error 'localhost:9090/ngsi-ld/v1/entities?type=*'
```

``` shell name=scorpio-entity-update
# https://fiware-scorpio.readthedocs.io/en/master/user/walkthrough_apiv2.html#entity-creation
task compose -- exec --no-TTY scorpio curl --silent --show-error localhost:9090/ngsi-ld/v1/entities/urn%3Aroom1/attrs --header 'content-type: application/json' --data @- <<EOF
{
"temperature": {
"value": $((1 + RANDOM % 10)),
"observedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
}
EOF

# https://stackoverflow.com/a/49189559
task compose -- exec --no-TTY scorpio curl --silent --show-error localhost:9090/ngsi-ld/v1/entities/urn%3Aroom1/attrs/temperature --header 'content-type: application/json' --request PATCH --data @- <<EOF
{
"value": $((1 + RANDOM % 10)),
"observedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOF
```

``` shell name=scorpio-temporal
#task compose -- exec scorpio curl --silent --show-error 'localhost:9090/ngsi-ld/v1/entities?type=Room'
# task compose -- exec scorpio curl --silent --show-error 'localhost:9090/ngsi-ld/v1/temporal/entities?type=Room&attr=pressure'
# task compose -- exec scorpio curl --silent --show-error 'localhost:9090/ngsi-ld/v1/temporal/entities?type=Room&attr=pressure&options=temporalValues'
task compose -- exec scorpio curl --silent --show-error 'localhost:9090/ngsi-ld/v1/temporal/entities?type=Room&attr=pressure&timerel=between&timeAt=2025-05-05T12:03:58.903Z&endTimeAt=2027-05-05T13:03:58.903Z&options=temporalValues'

# temporal/temporal/entities?type=Room&attrs=pressure&timerel=between&timeAt=2026-05-05T12:03:58.903Z&endTimeAt=2026-05-05T13:03:58.903Z&format=temporalValues
```

Talk to the timescale database:

``` shell name=timescale-query
Expand Down Expand Up @@ -109,3 +160,20 @@ COMPOSE_PROJECT_NAME=quantumleap
COMPOSE_DOMAIN=quantumleap.srvitkiotlab.itkdev.dk
COMPOSE_FILES=docker-compose.yml,docker-compose.prod.yml
```

## Grafana plugins

### NGSI-LD Grafana datasource plugin

[NGSI-LD Grafana datasource plugin](https://github.com/bfi-de/ngsild-grafana-datasource); datasource setup:

| Name | Value |
|---------------------|----------------------------------|
| Context broker URL | `http://scorpio:9090` |
| Temporal broker URL | `http://scorpio:9090/ngsi-ld/v1` |
| Format parameter | options |
| Access | proxy |
| Flavour | generic |

> [!IMPORTANT]
> The value of "Temporal broker URL" _must_ be the value of "Context broker URL" followed by `/ngsi-ld/v1`.
20 changes: 20 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,27 @@ dotenv:
vars:
DOCKER_COMPOSE: '{{.TASK_DOCKER_COMPOSE | default "docker compose"}}'

includes:
grafana:plugins:
taskfile: ./grafana/plugins/Taskfile.yml
dir: ./grafana/plugins

tasks:
install:
desc: Install plugins
cmds:
- task: grafana:plugins:update

start:
desc: Start the show
cmds:
- task: compose
vars:
TASK_ARGS: pull
- task: compose
vars:
TASK_ARGS: up --detach --remove-orphans --wait

grafana:reset-database:
desc: Reset Grafana database
prompt: Really?
Expand Down
43 changes: 42 additions & 1 deletion docker-compose.quantumleap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

networks:
quantumleap:
scorpio:

services:
orion:
Expand Down Expand Up @@ -115,11 +116,51 @@ services:
# - GF_SERVER_HTTP_PORT=80
# https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#data
- GF_PATHS_DATA=/var/lib/grafana # The default value

- GF_PATHS_PLUGINS=/var/lib/grafana/plugins # The default value
# https://github.com/bfi-de/ngsild-grafana-datasource/blob/main/README.md
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=ngsild-grafana-datasource
volumes:
# https://grafana.com/docs/grafana/latest/setup-grafana/configure-docker/
#- ./grafana/grafana.ini://etc/grafana/grafana.ini
# https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/
- ./grafana/provisioning:/etc/grafana/provisioning
- ./grafana/provisioning:/etc/grafana/provisioning
# Cf. environment variable GF_PATHS_DATA
- ./.docker/data/grafana/grafana.db:/var/lib/grafana/grafana.db

# https://github.com/bfi-de/ngsild-grafana-datasource/blob/main/README.md
- ./grafana/plugins/ngsild-grafana-datasource:/var/lib/grafana/plugins/ngsild-grafana-datasource:ro

scorpio:
image: scorpiobroker/all-in-one-runner:java-latest
environment:
DBHOST: scorpio-db
# ports:
# - "9090"
depends_on:
- scorpio-db
networks:
- frontend
- quantumleap
- scorpio
labels:
- "traefik.enable=true"
- "traefik.docker.network=frontend"
- "traefik.http.routers.${COMPOSE_PROJECT_NAME:?}_scorpio.rule=Host(`scorpio.${COMPOSE_DOMAIN:?}`)"
- "traefik.http.services.${COMPOSE_PROJECT_NAME:?}_scorpio.loadbalancer.server.port=9090"
# HTTPS config
- "traefik.http.routers.${COMPOSE_PROJECT_NAME:?}.middlewares=redirect-to-https"
- "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

scorpio-db:
image: postgis/postgis
ports:
- "5432"
environment:
POSTGRES_USER: ngb
POSTGRES_PASSWORD: ngb
POSTGRES_DB: ngb
networks:
- scorpio
volumes:
- .docker/data/scorpio-db:/var/lib/postgresql/data
4 changes: 4 additions & 0 deletions grafana/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore almost anything
*
!.gitignore
!Taskfile.yml
14 changes: 14 additions & 0 deletions grafana/plugins/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: '3'

vars:
NGSILD_GRAFANA_DATASOURCE_VERSION: 1.2.2

tasks:
update:
desc: Update all plugins
cmds:
# https://github.com/bfi-de/ngsild-grafana-datasource/blob/main/README.md
- curl --location --silent https://github.com/bfi-de/ngsild-grafana-datasource/releases/download/v{{.NGSILD_GRAFANA_DATASOURCE_VERSION}}/ngsild-grafana-datasource-{{.NGSILD_GRAFANA_DATASOURCE_VERSION}}.tgz --output ngsild-grafana-datasource.tgz
- tar xf ngsild-grafana-datasource.tgz
28 changes: 28 additions & 0 deletions scripts/scorpio-generate-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

echo "Creating entity"
# https://fiware-scorpio.readthedocs.io/en/master/user/walkthrough_apiv2.html#entity-creation
task compose -- exec --no-TTY scorpio curl --silent --show-error localhost:9090/ngsi-ld/v1/entities --header 'content-type: application/json' --data @- <<EOF
{
"id": "urn:room1",
"type": "Room",
"temperature": {
"value": 23,
"type": "Float"
},
"pressure": {
"value": 720,
"type": "Integer"
}
}
EOF

echo
echo "Updating entity values …"

while true; do
"$script_dir/scorpio-one-ping-only"
sleep 10
done
14 changes: 14 additions & 0 deletions scripts/scorpio-one-ping-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

task compose -- exec --no-TTY scorpio curl --silent --show-error localhost:9090/ngsi-ld/v1/entities/urn%3Aroom1/attrs --header 'content-type: application/json' --data @- <<EOF
{
"temperature": {
"value": $((1 + RANDOM % 10)),
"observedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
},
"pressure": {
"value": $((1 + RANDOM % 87)),
"observedAt": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
}
EOF