1

我有 Orion、Cygnus 和 STH-Comet(以正式模式安装和配置)。每个组件都在一个容器泊坞窗中。我用docker-compose.yml实现了基础设施。

Cygnus 容器配置如下:

    image: fiware/cygnus-ngsi:latest
    hostname: cygnus
    container_name: cygnus
    volumes:
      - /home/ubuntu/cygnus/multisink_agent.conf:/opt/fiware-cygnus/docker/cygnus-ngsi/multisink_agent.conf
    depends_on:
      - mongo
    networks:
      - default
    expose:
      - "5050"
      - "5080"
    ports:
      - "5050:5050"
      - "5080:5080" 
    environment:
      - CYGNUS_SERVICE_PORT=5050
      - CYGNUS_MONITORING_TYPE=http
      - CYGNUS_AGENT_NAME=cygnus-ngsi
      - CYGNUS_MONGO_SERVICE_PORT=5050
      - CYGNUS_MONGO_HOSTS=mongo:27017
      - CYGNUS_MONGO_USER=
      - CYGNUS_MONGO_PASS=
      - CYGNUS_MONGO_ENABLE_ENCODING=false
      - CYGNUS_MONGO_ENABLE_GROUPING=false
      - CYGNUS_MONGO_ENABLE_NAME_MAPPINGS=false
      - CYGNUS_MONGO_DATA_MODEL=dm-by-entity
      - CYGNUS_MONGO_ATTR_PERSISTENCE=column
      - CYGNUS_MONGO_DB_PREFIX=sth_
      - CYGNUS_MONGO_COLLECTION_PREFIX=sth_   
      - CYGNUS_MONGO_ENABLE_LOWERCASE=false
      - CYGNUS_MONGO_BATCH_TIMEOUT=30
      - CYGNUS_MONGO_BATCH_TTL=10
      - CYGNUS_MONGO_DATA_EXPIRATION=0
      - CYGNUS_MONGO_COLLECTIONS_SIZE=0
      - CYGNUS_MONGO_MAX_DOCUMENTS=0
      - CYGNUS_MONGO_BATCH_SIZE=1
      - CYGNUS_LOG_LEVEL=DEBUG
      - CYGNUS_SKIP_CONF_GENERATION=false 
      - CYGNUS_STH_ENABLE_ENCODING=false
      - CYGNUS_STH_ENABLE_GROUPING=false
      - CYGNUS_STH_ENABLE_NAME_MAPPINGS=false
      - CYGNUS_STH_DB_PREFIX=sth_
      - CYGNUS_STH_COLLECTION_PREFIX=sth_
      - CYGNUS_STH_DATA_MODEL=dm-by-entity
      - CYGNUS_STH_ENABLE_LOWERCASE=false
      - CYGNUS_STH_BATCH_TIMEOUT=30
      - CYGNUS_STH_BATCH_TTL=10
      - CYGNUS_STH_DATA_EXPIRATION=0
      - CYGNUS_STH_BATCH_SIZE=1

Obs:在 multisink_agent.conf 文件中,我更改了服务和服务路径:

cygnus-ngsi.sources.http-source-mongo.handler.default_service = tese

cygnus-ngsi.sources.http-source-mongo.handler.default_service_path = /iot

STH-Comet 容器如下所示:

    image: fiware/sth-comet:latest
    hostname: sth
    container_name: sth
    depends_on:
      - cygnus
      - mongo
    networks:
      - default
    expose:
      - "8666"
    ports:
      - "8666:8666"
    environment:
      - STH_HOST=0.0.0.0
      - STH_PORT=8666
      - DB_URI=mongo:27017
      - DB_USERNAME=
      - DB_PASSWORD=
      - LOGOPS_LEVEL=DEBUG

在 STH-Comet config.js 文件中,我启用了 CORS,并更改了 defaultService 和 defaultServicePath。该文件如下所示:

var config = {};

// STH server configuration
//--------------------------
config.server = {
    host: 'localhost',
    port: '8666',
    // Default value: "testservice".
    defaultService: 'tese',
    // Default value: "/testservicepath".
    defaultServicePath: '/iot',
    filterOutEmpty: 'true',
    aggregationBy: ['day', 'hour', 'minute'],
    temporalDir: 'temp',
    maxPageSize: '100'
};

// Cors Configuration
config.cors = {
    // The enabled is use to set CORS policy
    enabled: 'true',
    options: {
        origin: ['*'],
        headers: [
            'Access-Control-Allow-Origin',
            'Access-Control-Allow-Headers',
            'Access-Control-Request-Headers',
            'Origin, Referer, User-Agent'
        ],
        additionalHeaders: ['fiware-servicepath', 'fiware-service'],
        credentials: 'true'
    }
};

// Database configuration
//------------------------
config.database = {
    dataModel: 'collection-per-entity',
    user: '',
    password: '',
    authSource: '',
    URI: 'localhost:27017',
    replicaSet: '',
    prefix: 'sth_',
    collectionPrefix: 'sth_',
    poolSize: '5',
    writeConcern: '1',
    shouldStore: 'both',
    truncation: {
        expireAfterSeconds: '0',
        size: '0',
        max: '0'
    },
    ignoreBlankSpaces: 'true',
    nameMapping: {
        enabled: 'false',
        configFile: './name-mapping.json'
    },
    nameEncoding: 'false'
};

// Logging configuration
//------------------------
config.logging = {
   
    level: 'debug',
    format: 'pipe',
    proofOfLifeInterval: '60',
    processedRequestLogStatisticsInterval: '60'
};

module.exports = config;

我使用 Cygnus 来保存历史数据。STH-Comet 仅用于查询原始数据和聚合数据。

天鹅座在猎户座上的签名是这样做的:

  "description": "A subscription All Entities",
  "subject": {
    "entities": [
      {
        "idPattern": ".*"
      }
    ],
    "condition": {
      "attrs": []
    }
  },
  "notification": {
    "http": {
      "url": "http://cygnus:5050/notify"
    },
    "attrs": [],
    "attrsFormat":"legacy"
  },
  "expires": "2040-01-01T14:00:00.00Z",
  "throttling": 5
}

用于 fiware-service 和 fiware-servicepath 的标头是:

固件服务:tese

固件服务路径:/iot

实体数据存储在orion-tese中。我有收藏:entities

{
        "_id" : {
                "id" : "Tank1",
                "type" : "Tank",
                "servicePath" : "/iot"
        },
        "attrNames" : [
                "temperature"
        ],
        "attrs" : {
                "temperature" : {
                        "value" : 0.333,
                        "type" : "Float",
                        "mdNames" : [ ],
                        "creDate" : 1594334464,
                        "modDate" : 1594337770
                }
        },
        "creDate" : 1594334464,
        "modDate" : 1594337771,
        "lastCorrelator" : "f86d0d74-c23c-11ea-9c82-0242ac1c0005"
}

原始数据和聚合数据存储在sth_tese中。我有收藏:

sth_/iot_Tank1_Tank.aggr

sth_/iot_Tank1_Tank

sth_ /iot_Tank1_Tank原始数据在 mongoDB 中:

{
        "_id" : ObjectId("5f079d0369591c06b0fc981a"),
        "temperature" : 279,
        "recvTime" : ISODate("2020-07-09T22:41:05.670Z")
}
{
        "_id" : ObjectId("5f07a9eb69591c06b0fc981b"),
        "temperature" : 0.333,
        "recvTime" : ISODate("2020-07-09T23:36:11.160Z")
}

当我运行时:http://localhost:8666/STH/v1/contextEntities/type/Tank/id/Tank1/attributes/temperature?aggrMethod=sum&aggrPeriod=minute

或者

http://localhost:8666/STH/v2/entities/Tank1/attrs/temperature?type=Tank&aggrMethod=sum&aggrPeriod=minute

我有结果:"sum": 279"sum": 0.333。我可以恢复所有聚合数据,最大值、最小值、总和、总和 2。

当我尝试检索原始数据时,困难在于 STH-Comet,返回码为 200,值返回为空。

我尝试过使用 API v1 和 v2,但无济于事。

使用 v2 请求:

http://sth:8666/STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10

返回

{
  "type": "StructuredValue",
  "value": []
}

使用 v1 请求:

http://sth:8666/STH/v1/contextEntities/type/Tank/id/Tank1/attributes/temperature?lastN=10

返回

{
  "contextResponses": [{
    "contextElement": {
      "attributes": [{
        "name": "temperature",
        "values": []
      }],
      "id": "Tank1",
      "isPattern": false,
      "type": "Tank"
    },
    "statusCode": {
      "code": "200",
      "reasonPhrase": "OK"
    }
  }]
}

STH-Comet 日志显示它在线并连接到正确的数据库:

time=2020-07-09T22:39:06.698Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_DB_CONN_OPEN | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Establishing connection to the database at mongodb://@mongo:27017/sth_tese
time=2020-07-09T22:39:06.879Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_DB_CONN_OPEN | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Connection successfully established to the database at mongodb://@mongo:27017/sth_tese
time=2020-07-09T22:39:07.218Z | lvl=INFO | corr=n/a | trans=n/a | op=OPER_STH_SERVER_START | from=n/a | srv=n/a | subsrv=n/a | comp=STH | msg=Server started at http://0.0.0.0:8666

带有 api v2 请求的 STH-Comet 日志:

time=2020-07-09T23:46:47.400Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=GET /STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10
time=2020-07-09T23:46:47.404Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=Getting access to the raw data collection for retrieval...
time=2020-07-09T23:46:47.408Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=The raw data collection for retrieval exists
time=2020-07-09T23:46:47.412Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=No raw data available for the request: /STH/v2/entities/Tank1/attrs/temperature?type=Tank&lastN=10
time=2020-07-09T23:46:47.412Z | lvl=DEBUG | corr=998811d9-fac2-4701-b37c-bb9ae1b45b81 | trans=998811d9-fac2-4701-b37c-bb9ae1b45b81 | op=OPER_STH_GET | from=n/a | srv=tese | subsrv=/iot | comp=STH | msg=Responding with no points

根据日志,它建立连接以恢复原始数据:msg=Getting access to the raw data collection for retrieval.... 确认原始数据存在:msg=The raw data collection for retrieval exists。但是,它无法恢复此数据并生成原始数据不可用且不返回任何点的消息:msg=No raw data available for the requestmsg=Responding with no points

我已经阅读了文档中的配置部分。我已经重新安装了所有东西,好几次。我梳理了所有设置,但找不到任何可以证明这个问题的理由。

会是什么呢?有 STH-Comet 专业知识的人可以提供任何指导吗?

谢谢!

4

1 回答 1

0

有时 STH 尝试恢复信息的方式与 Cygnus 存储信息的方式不匹配。但是,这里的情况并非如此。STH 使用的数据模型配置为config.database.dataModel并且似乎是正确的:(collection-per-entity因为您有类似 的集合sth_/iot_Tank1_Tank,它对应于单个实体,即 ID 为 Tank1 且类型为 Tank 的集合)。

假设 config.js 中的设置没有被DATA_MODELenv var覆盖(尽管检查这一点是明智的,查看实际上被注入到运行 STH 的 docker 容器的 env vars,我猜想用docker inspect)唯一的方法我认为我们可以继续调试是检查在 MongoDB 上执行 STH 的哪个实际查询以No raw data available for the request.

MongoDB 有一个分析器,可以记录在数据库中完成的每个查询。因此,程序如下:

  1. 避免(或最小化)MongoDB 实例的任何其他使用,以避免分析器记录的信息中出现“噪音”
  2. 以“所有查询”模式启动分析器(即分析级别 2)
  3. 在 STH API 进行查询
  4. 停止探查器
  5. 由于步骤 3 中完成的请求,检查分析器记录的查询

解释 MongoDB 分析器的用法超出了此答案的范围,但如果您还不知道,我上面提供的参考资料是一个很好的起点。

获得有关查询的信息后,请提供反馈作为对此答案的评论。谢谢!

于 2020-07-20T09:03:04.920 回答