IngMiad
IngMiad

Reputation: 1

Question on Visualization of FIWARE STH data with Grafana

I have a question based on FIWARE timescale database design when using STH and grafana for visualization.

**Background**:

I created a test project based on FIWARE using Docker-Compose. The project currently includes:

  • Orion-LD + Mongo-DB
  • STH based on Mintaka and Timescale-DB
  • OPC UA Dummy Car Server and OPC UA IoT-Agent
  • Grafana

The solutions seems to work quite well: OPC UA dummy car server sends data via OPC UA Iot-Agent and I can also send commands back to OPC dummy car server. I am also able to query historic context for the car entity using orion-ld:

  1. Request
curl --location --request GET 'http://localhost:8080/temporal/entities/?type=Device&pageSize=2&lastN=3&timeproperty=modifiedAt&options=count&timerel=before&timeAt=2022-07-15T15:28:00Z' \
--header 'NGSILD-Tenant: opcua_car' \
--header 'Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"'\''' \
--header 'NGSILD-Path: /demo'
  1. Response:
[
    {
        "id": "urn:ngsi-ld:Device:age01_Car",
        "type": "Device",
        "Acceleration": [
            {
                "type": "Property",
                "value": 0.0,
                "modifiedAt": "2022-07-15T13:40:02.960Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:a10c6606-0443-11ed-9e31-0242ac120103"
            },
            {
                "type": "Property",
                "value": 3.0,
                "modifiedAt": "2022-07-15T13:40:01.978Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:a0775408-0443-11ed-9cfd-0242ac120103"
            },
            {
                "type": "Property",
                "value": 0.0,
                "modifiedAt": "2022-07-15T13:25:54.342Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:a73b926a-0441-11ed-bca6-0242ac120103"
            }
        ],
        "Stop_status": {
            "type": "Property",
            "value": {
                "type": "commandStatus",
                "@value": "UNKNOWN"
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2ed12-0441-11ed-b967-0242ac120103"
        },
        "Engine_Oxigen": [
            {
                "type": "Property",
                "value": 80.0,
                "modifiedAt": "2022-07-15T13:24:41.752Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:7bf736f4-0441-11ed-8bcd-0242ac120103"
            },
            {
                "type": "Property",
                "value": 78.5,
                "modifiedAt": "2022-07-15T13:24:40.734Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:7b5c32e4-0441-11ed-ac6e-0242ac120103"
            },
            {
                "type": "Property",
                "value": 77.0,
                "modifiedAt": "2022-07-15T13:24:39.726Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:7ac21740-0441-11ed-b111-0242ac120103"
            }
        ],
        "Stop_info": {
            "type": "Property",
            "value": {
                "type": "commandResult",
                "@value": " "
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2ed8a-0441-11ed-b967-0242ac120103"
        },
        "Accelerate_info": {
            "type": "Property",
            "value": {
                "type": "commandResult",
                "@value": " "
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2ee66-0441-11ed-b967-0242ac120103"
        },
        "Error_status": {
            "type": "Property",
            "value": {
                "type": "commandStatus",
                "@value": "UNKNOWN"
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2ec0e-0441-11ed-b967-0242ac120103"
        },
        "Accelerate_status": {
            "type": "Property",
            "value": {
                "type": "commandStatus",
                "@value": "UNKNOWN"
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2edf8-0441-11ed-b967-0242ac120103"
        },
        "EngineStopped": [
            {
                "type": "Property",
                "value": true,
                "modifiedAt": "2022-07-15T13:23:50.922Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:5dab3b8c-0441-11ed-9f1d-0242ac120103"
            },
            {
                "type": "Property",
                "value": true,
                "modifiedAt": "2022-07-15T13:21:25.497Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:06fd291c-0441-11ed-9ed9-0242ac120103"
            }
        ],
        "Engine_Temperature": [
            {
                "type": "Property",
                "value": 80.0,
                "modifiedAt": "2022-07-15T13:24:21.691Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:70023236-0441-11ed-8db7-0242ac120103"
            },
            {
                "type": "Property",
                "value": 78.0,
                "modifiedAt": "2022-07-15T13:24:20.700Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:6f6b16c6-0441-11ed-9541-0242ac120103"
            },
            {
                "type": "Property",
                "value": 76.0,
                "modifiedAt": "2022-07-15T13:24:19.696Z",
                "instanceId": "urn:ngsi-ld:attribute:instance:6ed1d326-0441-11ed-81be-0242ac120103"
            }
        ],
        "Error_info": {
            "type": "Property",
            "value": {
                "type": "commandResult",
                "@value": " "
            },
            "modifiedAt": "2022-07-15T13:21:24.893Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:06a2ec9a-0441-11ed-b967-0242ac120103"
        }
    }
]

Now I want to visualize time-series data using grafana. For QL + subscription this is documented very well (see here): We will have to use table 'et<entitytype>', time column 'time_index' and metric column 'entity_type'. I tested the scenario successfully using TimescaleDB.

Issue:

I can't find any information on how to visualize data with grafana using STH. TimescaleDB now has different tables for entities, attributes, subattributes and more. Using Grafana I am not sure how to query the entities correctly. Especially I have problems with the example above, where no observedAt but the modifiedAt property is being used as timeproperty.

So actually I am able to query timeseries data with the described STH infrastructure using orion-ld, but not to visualize them with grafana. Do you have recommendations on that?


Update: to keep it more simple you could also use the sample from FIWARE instead of my custom example from above: https://github.com/FIWARE/tutorials.Short-Term-History

Just clone code, switch to branch NGSI-LD, add Grafana to the example in docker-compose:

...
  grafana:
    labels:
      org.test: 'fiware'
    image: grafana/grafana:6.1.6
    container_name: grafana
    networks:
      default:
        ipv4_address: 172.18.1.8
    ports:
      - "3003:3000"

... and start the example as described by ./services orion legacy. Afterwards open farm http://localhost:3000 and do some stuff (refill hay, water on, start tractor, ...)

If you query OCB you get temporal data easily. For example heartRate of cow002:

curl --location --request GET 'http://localhost:8080/temporal/entities/urn:ngsi-ld:Animal:cow002' \
--header 'NGSILD-Tenant: openiot' \
--header 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--header 'attrs: heartRate'

Response:

{
    "id": "urn:ngsi-ld:Animal:cow002",
    "type": "Animal",
    "heartRate": [
        {
            "type": "Property",
            "value": 51.0,
            "observedAt": "2022-09-26T13:37:25.823Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:5ba7d35c-3da0-11ed-a105-0242ac120109",
            "unitCode": "5K",
            "providedBy": {
                "object": "urn:ngsi-ld:Device:cow002",
                "type": "Relationship",
                "instanceId": "urn:ngsi-ld:attribute:instance:5ba7d3fc-3da0-11ed-a105-0242ac120109"
            }
        },
        {
            "type": "Property",
            "value": 52.0,
            "observedAt": "2022-09-26T13:37:35.523Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:6184922e-3da0-11ed-abeb-0242ac120109",
            "unitCode": "5K",
            "providedBy": {
                "object": "urn:ngsi-ld:Device:cow002",
                "type": "Relationship",
                "instanceId": "urn:ngsi-ld:attribute:instance:618492ce-3da0-11ed-abeb-0242ac120109"
            }
        },
        {
            "type": "Property",
            "value": 51.0,
            "observedAt": "2022-09-26T13:38:00.610Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:705e724c-3da0-11ed-a516-0242ac120109",
            "unitCode": "5K",
            "providedBy": {
                "object": "urn:ngsi-ld:Device:cow002",
                "type": "Relationship",
                "instanceId": "urn:ngsi-ld:attribute:instance:705e72e2-3da0-11ed-a516-0242ac120109"
            }
        },
        {
            "type": "Property",
            "value": 52.0,
            "observedAt": "2022-09-26T13:38:15.597Z",
            "instanceId": "urn:ngsi-ld:attribute:instance:794d239e-3da0-11ed-a8c0-0242ac120109",
            "unitCode": "5K",
            "providedBy": {
                "object": "urn:ngsi-ld:Device:cow002",
                "type": "Relationship",
                "instanceId": "urn:ngsi-ld:attribute:instance:794d242a-3da0-11ed-a8c0-0242ac120109"
            }
        },
        ...

In timescale db you now can find tables for attributes, subattributes, entities and more stuff filled with some data. When I want to visualize the same example of cow002 and heartRate with grafana, I am not sure which table or tables I need to query. I am even not able to find the attribute heartRate in any of the tables.

Could you please assist how data can be visualized using grafana and Short Time History? Tutorials / Documentation don't mention how to visualize STH data with grafana with the different table structure. Maybe we can use the example of the heartRate to keep example simple.

Thank you in advance!

Upvotes: 0

Views: 151

Answers (1)

IngMiad
IngMiad

Reputation: 1

Yeah I finally found a solution and described it here in case of Scorpio: https://github.com/FIWARE/tutorials.Short-Term-History/issues/15

It is far more complicated to visualize data when you use STH instead of QL+subscriptions, but it is possible with more advanced Grafana queries.

Upvotes: 0

Related Questions