我使用 docker compose 部署了基本的 FIWARE Scorpio 堆栈:
services:
postgres:
image: postgis/postgis
ports:
- "5432"
environment:
POSTGRES_USER: ngb
POSTGRES_PASSWORD: ngb
POSTGRES_DB: ngb
scorpio:
image: scorpiobroker/all-in-one-runner:java-latest
environment:
DBHOST: postgres
ports:
- "9090:9090"
depends_on:
- postgres
我还有一个.sh代码来添加实体,其中一部分是:
SCORPIO_URL="http://localhost:9090/ngsi-ld/v1/temporal/entities"
NGSI_LD_CONTEXT="https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.7.jsonld"
FIWARE_SERVICE="test_service"
FIWARE_SERVICEPATH="/weather"
create_weather_entity() {
response=$(curl -X POST "$SCORPIO_URL" \
-H "Content-Type: application/ld+json" \
-H "fiware-service: $FIWARE_SERVICE" \
-H "fiware-servicepath: $FIWARE_SERVICEPATH" \
-d '{
"id": "urn:ngsi-ld:WeatherObserved:001",
"type": "WeatherObserved",
"temperature": {
"value": 23,
"unitCode": "CEL",
"type": "Property",
"observedAt": "2024-10-10T12:00:00Z"
},
"barometricPressure": {
"value": 720,
"unitCode": "hPa",
"type": "Property",
"observedAt": "2024-10-10T12:00:00Z"
},
"dateObserved": {
"value": "2024-10-10T12:00:00Z",
"type": "Property"
},
"source": {
"value": "http://www.aemet.es",
"type": "Property"
},
"@context": [
{
"WeatherObserved": "urn:mytypes:WeatherObserved",
"temperature": "myuniqueuri:temperature",
"barometricPressure": "myuniqueuri:barometricPressure",
"dateObserved": "myuniqueuri:dateObserved",
"source": "myuniqueuri:source"
},
"'$NGSI_LD_CONTEXT'"
]
}')
echo "Create WeatherObserved Response: $response"
}
以及模拟测量发送的代码:
SCORPIO_URL="http://localhost:9090/ngsi-ld/v1/temporal/entities/"
NGSI_LD_CONTEXT="https://fiware.github.io/data-models/context.jsonld"
FIWARE_SERVICE="test_service"
FIWARE_SERVICEPATH="/weather"
send_weather_measurements() {
local temperature=$(shuf -i 15-35 -n 1)
local pressure=$(shuf -i 700-750 -n 1)
local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")
echo "Sending WeatherObserved measurement:"
echo " Temperature: ${temperature} °C"
echo " Barometric Pressure: ${pressure} hPa"
echo " Observed At: ${timestamp}"
curl -X PATCH "${SCORPIO_URL}urn:ngsi-ld:WeatherObserved:001/attrs" \
-H "Content-Type: application/ld+json" \
-H "fiware-service: $FIWARE_SERVICE" \
-H "fiware-servicepath: $FIWARE_SERVICEPATH" \
-d '{
"temperature": {
"type": "Property",
"value": '"$temperature"',
"observedAt": "'"$timestamp"'"
},
"barometricPressure": {
"type": "Property",
"value": '"$pressure"',
"observedAt": "'"$timestamp"'"
},
"dateObserved": {
"type": "Property",
"value": "'"$timestamp"'"
},
"@context": "'$NGSI_LD_CONTEXT'"
}'
}
我想将这些历史上下文存储到postgres sql db中(不行),然后将其连接到Grafana(这部分应该可以)。
当我这样做时:
curl -X GET“http://localhost:9090/ngsi-ld/v1/temporal/entities/urn:ngsi-ld:WeatherObserved:001”
-H“内容类型:application/ld+json”
-H“固件服务:test_service”
-H“固件服务路径:/天气”
它有效,因此实体被保存。但是当我检查 postgres 数据库内部时,我只看到这些表,而找不到与我的实体对应的表:
tiger | faces | table | ngb
tiger | featnames | table | ngb
tiger | geocode_settings | table | ngb
tiger | geocode_settings_default | table | ngb
tiger | loader_lookuptables | table | ngb
tiger | loader_platform | table | ngb
tiger | loader_variables | table | ngb
tiger | pagc_gaz | table | ngb
tiger | pagc_lex | table | ngb
tiger | pagc_rules | table | ngb
tiger | place | table | ngb
tiger | place_lookup | table | ngb
tiger | secondary_unit_lookup | table | ngb
tiger | state | table | ngb
tiger | state_lookup | table | ngb
tiger | street_type_lookup | table | ngb
tiger | tabblock | table | ngb
tiger | tabblock20 | table | ngb
tiger | tract | table | ngb
tiger | zcta5 | table | ngb
tiger | zip_lookup | table | ngb
tiger | zip_lookup_all | table | ngb
tiger | zip_lookup_base | table | ngb
tiger | zip_state | table | ngb
tiger | zip_state_loc | table | ngb
topology | layer | table | ngb
topology | topology | table | ngb
我应该如何将历史值存储到 postgres SQL 数据库中?
预先感谢您的帮助!
您不需要了解底层数据库即可组合 NGSI-LD 上下文代理和 Grafana 显示。您只需要使用适当的 Grafana 源,例如 https://github.com/bfi-de/ngsild-grafana-datasource
由于 NGSI-LD 接口(
/entities
和 /temporal/entities
)定义良好,因此可以创建直接查询上下文代理的 Grafana 源。这是比尝试查询无论如何都可能发生变化的底层数据库更好的方法。
对于 Scorpio,默认情况下可以使用临时接口(与使用 Mintaka 插件的 Orion-LD 不同),因此用于在源中配置“Context Broker”和“Temporal Broker”的 URL 可以相同。
有关此主题的更多信息,您可以观看以下视频