WIS2 다운로더는 WIS2 글로벌 브로커에 연결하고, 주제 계층에 대한 구독을 관리하고, 관련 다운로드 디렉터리를 구성할 수 있는 Flask 기반 Python 애플리케이션입니다.
/metrics
엔드포인트를 통해 Prometheus 지표에 액세스합니다.python -m pip install wis2downloader
다음 스키마를 준수하는 로컬 디렉터리에 config.json
파일을 만듭니다.
schema :
type : object
properties :
base_url :
type : string
description :
Base URL for the wis2downloader service.
example : http://localhost:5050
broker_hostname :
type : string
description : The hostname of the global broker to subscribe to.
example : globalbroker.meteo.fr
broker_password :
type : string
description : The password to use when connecting to the specified global broker.
example : everyone
broker_port :
type : number
description : The port the global broker is using for the specified protocol.
example : 443
broker_protocol :
type : string
description : The protocol (websockets or tcp) to use when connecting to the global broker.
example : websockets
broker_username :
type : string
description : The username to use when connecting to the global broker.
example : everyone
download_workers :
type : number
description : The number of download worker threads to spawn.
example : 1
download_dir :
type : string
description : The path to download data to on the server/computer running the wis2downloader.
example : ./downloads
flask_host :
type : string
description : Network interface on which flask should listen when run in dev mode.
example : 0.0.0.0
flask_port :
type : number
description : The port on which flask should listen when run in dev mode.
example : 5050
log_level :
type : string
description : Log level to use
example : DEBUG
log_path :
type : string
description : Path to write log files to.
example : ./logs
min_free_space :
type : number
description :
Minimum free space (GB) to leave on download volume / disk after download.
Files exceeding limit will not be saved.
example : 10
save_logs :
type : boolean
description : Write log files to disk (true) or stdout (false)
example : false
mqtt_session_info :
type : string
description :
File to save session information (active subscriptions and MQTT client id) to.
Used to persist subscriptions on restart.
example : mqtt_session.json
validate_topics :
type : boolean
description : Whether to validate the specified topic against the published WIS2 topic hierarchy.
example : true
아래에 예가 나와 있습니다.
{
"base_url" : " http://localhost:5050 " ,
"broker_hostname" : " globalbroker.meteo.fr " ,
"broker_password" : " everyone " ,
"broker_port" : 443 ,
"broker_protocol" : " websockets " ,
"broker_username" : " everyone " ,
"download_workers" : 1 ,
"download_dir" : " downloads " ,
"flask_host" : " 0.0.0.0 " ,
"flask_port" : 5050 ,
"log_level" : " DEBUG " ,
"log_path" : " logs " ,
"min_free_space" : 10 ,
"mqtt_session_info" : " mqtt_session.json " ,
"save_logs" : false ,
"validate_topics" : true
}
리눅스(배시)
export WIS2DOWNLOADER_CONFIG= < path_to_your_config_file >
Windows(명령 프롬프트)
set WIS2DOWNLOADER_CONFIG= < path_to_your_config_file >
Windows(PowerShell)
$env :WIS2DOWNLOADER_CONFIG = < path_to_your_config_file >
개발자 모드(Windows 및 Linux)
wis2downloader
gunicorn 사용(Linux에만 해당)
gunicorn --bind 0.0.0.0:5050 -w 1 wis2downloader.app:app
참고 : 다운로더가 추가 스레드를 생성하고 MQTT 연결이 지속되기 때문에 하나의 작업자만 지원됩니다.
이제 Flask 애플리케이션이 실행 중이어야 합니다. 애플리케이션을 중지해야 하는 경우 터미널에서 Ctrl+C
사용하여 중지할 수 있습니다.
다운로더의 API 정의는 /swagger
엔드포인트에서 찾을 수 있습니다. 로컬로 실행하는 경우 [http://localhost:5050/swagger]를 참조하세요. 여기에는 다양한 엔드포인트를 시험해 볼 수 있는 기능이 포함됩니다.
/subscriptions
엔드포인트에 대한 POST 요청을 통해 구독을 추가할 수 있습니다. 요청 본문은 JSON으로 인코딩되어야 하며 다음 스키마를 준수해야 합니다.
schema :
type : object
properties :
topic :
type : string
description : The WIS2 topic to subscribe to
example : cache/a/wis2/+/data/core/weather/surface-based-observations/#
target :
type : string
description : Sub directory to save data to
example : surface-obs
required :
- topic
이 예에서는 WIS2 센터에서 surface-based-observations
주제에 게시된 모든 알림을 구독하며, 다운로드된 데이터는 download_dir
의 surface-obs
하위 디렉터리에 기록됩니다.
참고:
target
지정하지 않으면 기본적으로 데이터가 게시되는 주제가 지정됩니다.+
와일드카드는 위의 예에서 WIS2 센터와 일치하는 단일 수준의 일치 항목을 지정하는 데 사용됩니다.#
와일드카드는 발생하는 수준 이하의 모든 주제와 일치합니다. 위의 예에서는 캐시/a/wis2/+/data/core/weather/surface-based-observations 아래에 게시된 모든 주제가 일치됩니다. curl -X ' POST '
' http://127.0.0.1:5050/subscriptions '
-H ' accept: application/json '
-H ' Content-Type: application/json '
-d ' {
"topic": "cache/a/wis2/+/data/core/weather/surface-based-observations/#",
"target": "surface-obs"
} '
구독은 구독을 취소할 주제인 {topic}
인 /subscriptions/{topic}
엔드포인트에 대한 DELETE 요청을 통해 삭제됩니다.
curl -X DELETE http://localhost:5050/subscriptions/cache/a/wis2/%2B/data/core/weather/%23
cache/a/wis2/+/data/core/weather/#
구독이 취소됩니다. +
( %2B
) 및 #
( %23
) 기호를 URL 인코딩해야 합니다.
현재 구독은 /subscriptions
엔드포인트에 대한 GET 요청을 통해 나열될 수 있습니다.
curl http://localhost:5050/subscriptions
활성 구독 목록은 JSON 개체로 반환되어야 합니다.
다운로더에 대한 Prometheus 지표는 /metrics
엔드포인트에 대한 GET 요청을 통해 발견됩니다.
curl http://localhost:5050/metrics
모든 버그, 개선 사항 및 문제는 GitHub에서 관리됩니다.