安裝和執行異常偵測器容器Install and run Anomaly Detector containers

異常偵測器具有下列容器:The Anomaly Detector has the following container:

函數Function 功能Features
異常偵測器Anomaly detector
  • 會偵測即時發生的異常狀況。Detects anomalies as they occur in real-time.
  • 以批次方式偵測整個資料集的異常狀況。Detects anomalies throughout your data set as a batch.
  • 推斷資料的預期正常範圍。Infers the expected normal range of your data.
  • 支援異常偵測敏感度調整, 更適合您的資料。Supports anomaly detection sensitivity adjustment to better fit your data.
  • 如需有關 Api 的詳細資訊, 請參閱:For detailed information about the APIs, please see:

    如果您沒有 Azure 訂用帳戶,請在開始前建立 免費帳戶If you don't have an Azure subscription, create a free account before you begin.

    必要條件Prerequisites

    使用異常偵測器容器之前, 您必須符合下列必要條件:You must meet the following prerequisites before using Anomaly Detector containers:

    必要項Required 用途Purpose
    Docker 引擎Docker Engine 您必須在主機電腦上安裝 Docker 引擎。You need the Docker Engine installed on a host computer. Docker 提供可在 macOSWindowsLinux 上設定 Docker 環境的套件。Docker provides packages that configure the Docker environment on macOS, Windows, and Linux. 如需 Docker 和容器基本概念的入門,請參閱 Docker 概觀 (英文)。For a primer on Docker and container basics, see the Docker overview.

    Docker 必須設定為允許容器與 Azure 連線,以及傳送帳單資料至 Azure。Docker must be configured to allow the containers to connect with and send billing data to Azure.

    在 Windows 上,也必須將 Docker 設定為支援 Linux 容器。On Windows, Docker must also be configured to support Linux containers.

    熟悉 DockerFamiliarity with Docker 您應具備對 Docker 概念 (例如登錄、存放庫、容器和容器映像等) 的基本了解,以及基本 docker 命令的知識。You should have a basic understanding of Docker concepts, like registries, repositories, containers, and container images, as well as knowledge of basic docker commands.
    異常偵測器資源Anomaly Detector resource 若要使用這些容器,您必須具備:In order to use these containers, you must have:

    Azure_異常_偵測器資源, 用來取得相關聯的 API 金鑰和端點 URI。An Azure Anomaly Detector resource to get the associated API key and endpoint URI. 這兩個值都可在 Azure 入口網站的異常偵測器總覽和金鑰頁面上取得, 而且必須要有才能啟動容器。Both values are available on the Azure portal's Anomaly Detector Overview and Keys pages and are required to start the container.

    {API_KEY} :[金鑰] 頁面上有兩個可用的資源金鑰之一{API_KEY}: One of the two available resource keys on the Keys page

    {ENDPOINT_URI} :[總覽] 頁面上所提供的端點{ENDPOINT_URI}: The endpoint as provided on the Overview page

    要求存取容器登錄Request access to the container registry

    您必須先完成並提交異常偵測器容器要求表單, 以要求容器的存取權。You must first complete and submit the Anomaly Detector Container Request form to request access to the container.

    該表格需要有關您本身、您的公司,以及您將會使用該容器之使用者情節的資訊。The form requests information about you, your company, and the user scenario for which you'll use the container. 您已提交表單之後,Azure 認知服務小組會檢閱,以確保您符合私人容器登錄的存取權的準則。After you've submitted the form, the Azure Cognitive Services team reviews it to ensure that you meet the criteria for access to the private container registry.

    重要

    您必須使用與在表單中的 Microsoft 帳戶 (MSA) 或 Azure Active Directory (Azure AD) 帳戶相關聯的電子郵件地址。You must use an email address that's associated with either a Microsoft Account (MSA) or Azure Active Directory (Azure AD) account in the form.

    如果您的要求獲得核准,您會收到一封電子郵件,說明如何取得您的認證和存取私人容器登錄庫的指示。If your request is approved, you'll receive an email with instructions that describe how to obtain your credentials and access the private container registry.

    使用 Docker CLI 來驗證私人容器登錄Use the Docker CLI to authenticate the private container registry

    您可以向私人容器登錄的認知服務容器中任一種,但建議的方法,從命令列是使用Docker CLIYou can authenticate with the private container registry for Cognitive Services Containers in any of several ways, but the recommended method from the command line is to use the Docker CLI.

    使用docker login命令所示,在下列範例中,登入containerpreview.azurecr.io,認知服務容器的私用容器登錄。Use the docker login command, as shown in the following example, to log in to containerpreview.azurecr.io, the private container registry for Cognitive Services Containers. 取代 <使用者名稱> 的使用者名稱與 <密碼> 提供認證,您已收到的密碼Azure 認知服務小組。Replace <username> with the user name and <password> with the password that's provided in the credentials you received from the Azure Cognitive Services team.

    docker login containerpreview.azurecr.io -u <username> -p <password>
    

    如果您已受保護您的認證在文字檔中,您可以藉由串連該文字檔的內容cat命令,以docker login命令,如下列範例所示。If you've secured your credentials in a text file, you can concatenate the contents of that text file, by using the cat command, to the docker login command, as shown in the following example. 取代 <passwordFile> 使用的路徑和名稱的文字檔案,其中包含密碼和 <username> 的使用者名稱提供您的認證。Replace <passwordFile> with the path and name of the text file that contains the password and <username> with the user name that's provided in your credentials.

    cat <passwordFile> | docker login containerpreview.azurecr.io -u <username> --password-stdin
    

    主機電腦The host computer

    主機是可執行 Docker 容器的 x64 型電腦。The host is a x64-based computer that runs the Docker container. 它可以是您內部部署的電腦,或是在 Azure 中裝載服務的 Docker,例如:It can be a computer on your premises or a Docker hosting service in Azure, such as:

    容器的需求和建議Container requirements and recommendations

    下表描述要針對異常偵測器容器配置的最低和建議 CPU 核心和記憶體。The following table describes the minimum and recommended CPU cores and memory to allocate for Anomaly Detector container.

    QPS (每秒查詢數)QPS(Queries per second) 最小值Minimum 建議Recommended
    10 QPS10 QPS 4核心, 1 GB 記憶體4 core, 1-GB memory 8核心 2 GB 記憶體8 core 2-GB memory
    20 QPS20 QPS 8核心, 2 GB 記憶體8 core, 2-GB memory 16核心 4 GB 記憶體16 core 4-GB memory

    每個核心必須至少 2.6 GHz 或更快。Each core must be at least 2.6 gigahertz (GHz) or faster.

    核心和記憶體會對應至 --cpus--memory 設定,用來作為 docker run 命令的一部分。Core and memory correspond to the --cpus and --memory settings, which are used as part of the docker run command.

    使用 docker pull 取得容器映像Get the container image with docker pull

    使用 docker pull 命令下載容器映像。Use the docker pull command to download a container image.

    容器Container 存放庫Repository
    cognitive-services-anomaly-detectorcognitive-services-anomaly-detector containerpreview.azurecr.io/microsoft/cognitive-services-anomaly-detector:latest

    提示

    您可以使用 docker images (英文) 命令來列出已下載的容器映像。You can use the docker images command to list your downloaded container images. 例如,下列命令會列出每個已下載之容器映像的識別碼、存放庫和標籤,並將它格式化為表格:For example, the following command lists the ID, repository, and tag of each downloaded container image, formatted as a table:

    docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
    
    IMAGE ID         REPOSITORY                TAG
    <image-id>       <repository-path/name>    <tag-name>
    

    異常偵測器容器的 Docker pullDocker pull for the Anomaly Detector container

    docker pull containerpreview.azurecr.io/microsoft/cognitive-services-anomaly-detector:latest
    

    如何使用容器How to use the container

    容器位於主機電腦上時,請透過下列程序來使用容器。Once the container is on the host computer, use the following process to work with the container.

    1. 使用所需的計費設定執行容器Run the container, with the required billing settings. docker run 命令有相關範例可供參考。More examples of the docker run command are available.
    2. 查詢容器的預測端點Query the container's prediction endpoint.

    透過 docker run 執行容器Run the container with docker run

    使用 docker run 命令來執行三個容器的其中一個。Use the docker run command to run any of the three containers. 此命令會使用下列參數:The command uses the following parameters:

    預留位置Placeholder Value
    {API_KEY}{API_KEY} 此金鑰用來啟動容器, 並可在 Azure 入口網站的異常偵測器金鑰頁面上取得。This key is used to start the container, and is available on the Azure portal's Anomaly Detector Keys page.
    {ENDPOINT_URI}{ENDPOINT_URI} [計費端點 URI] 值可在 Azure 入口網站的異常偵測器 [總覽] 頁面上取得。The billing endpoint URI value is available on the Azure portal's Anomaly Detector Overview page.

    請以您自己的值取代下列範例 docker run 命令中的參數。Replace these parameters with your own values in the following example docker run command.

    docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 \
    containerpreview.azurecr.io/microsoft/cognitive-services-anomaly-detector:latest \
    Eula=accept \
    Billing={ENDPOINT_URI} \
    ApiKey={API_KEY}
    

    此命令:This command:

    • 從容器映射執行異常偵測器容器Runs an Anomaly Detector container from the container image
    • 配置一個 CPU 核心和 4 GB 的記憶體Allocates one CPU core and 4 gigabytes (GB) of memory
    • 公開 TCP 連接埠 5000,並為容器配置虛擬 TTYExposes TCP port 5000 and allocates a pseudo-TTY for the container
    • 在容器結束之後自動將其移除。Automatically removes the container after it exits. 容器映像仍可在主機電腦上使用。The container image is still available on the host computer.

    重要

    必須指定 EulaBillingApiKey 選項以執行容器,否則容器將不會啟動。The Eula, Billing, and ApiKey options must be specified to run the container; otherwise, the container won't start. 如需詳細資訊,請參閱帳單For more information, see Billing.

    在相同的主機上執行多個容器Running multiple containers on the same host

    如果您打算使用公開的連接埠執行多個容器,請務必使用不同的連接埠執行每個容器。If you intend to run multiple containers with exposed ports, make sure to run each container with a different port. 例如,在連接埠 5000 上執行第一個容器,以及在連接埠 5001 上執行第二個容器。For example, run the first container on port 5000 and the second container on port 5001.

    以您使用的容器值,取代 <container-registry><container-name>Replace the <container-registry> and <container-name> with the values of the containers you use. 這些容器值不必是相同的容器。These do not have to be the same container. 您可以在主機上同時執行異常偵測器容器和 LUIS 容器, 或您可以讓多個異常偵測器容器執行。You can have the Anomaly Detector container and the LUIS container running on the HOST together or you can have multiple Anomaly Detector containers running.

    在連接埠 5000 上執行第一個容器。Run the first container on port 5000.

    docker run --rm -it -p 5000:5000 --memory 4g --cpus 1 \
    <container-registry>/microsoft/<container-name> \
    Eula=accept \
    Billing={ENDPOINT_URI} \
    ApiKey={API_KEY}
    

    在連接埠 5001 上執行第二個容器。Run the second container on port 5001.

    docker run --rm -it -p 5000:5001 --memory 4g --cpus 1 \
    <container-registry>/microsoft/<container-name> \
    Eula=accept \
    Billing={ENDPOINT_URI} \
    ApiKey={API_KEY}
    

    每個後續容器應該位於不同的連接埠。Each subsequent container should be on a different port.

    查詢容器的預測端點Query the container's prediction endpoint

    容器會提供以 REST 為基礎的查詢預測端點 API。The container provides REST-based query prediction endpoint APIs.

    針對容器 API 請使用主機 http://localhost:5000 。Use the host, http://localhost:5000, for container APIs.

    驗證容器正在執行Validate that a container is running

    有數種方式可驗證容器正在執行。There are several ways to validate that the container is running. 找出有問題之容器的外部 IP位址和公開端口, 然後開啟您最愛的網頁瀏覽器。Locate the External IP address and exposed port of the container in question, and open your favorite web browser. 使用下列各種要求 Url 來驗證容器是否正在執行。Use the various request URLs below to validate the container is running. 下面所列的範例要求 url http://localhost:5000是, 但您的特定容器可能會有所不同。The example request URLs listed below are http://localhost:5000, but your specific container may vary. 請記住, 您會依賴容器的外部 IP位址和公開的埠。Keep in mind that you're to rely on your container's External IP address and exposed port.

    要求 URLRequest URL 用途Purpose
    http://localhost:5000/ 容器會提供首頁。The container provides a home page.
    http://localhost:5000/status 使用 HTTP GET 要求, 以驗證容器是否正在執行, 而不會造成端點查詢。Requested with an HTTP GET, to validate that the container is running without causing an endpoint query. 此要求可用來進行 Kubernetes 活躍度和整備度探查 (英文)。This request can be used for Kubernetes liveness and readiness probes.
    http://localhost:5000/swagger 容器會為端點提供一組完整的檔, 並使用 [試用] 功能。The container provides a full set of documentation for the endpoints and a Try it out feature. 使用此功能,您可以將自己的設定輸入至以 Web 為基礎的 HTML 表單並進行查詢,而無須撰寫任何程式碼。With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. 當查詢傳回時,會提供範例 CURL 命令來示範所需的 HTTP 標頭和本文格式。After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

    容器的首頁

    停止容器Stop the container

    若要關閉的容器,容器執行所在的命令列環境中選取Ctrl + CTo shut down the container, in the command-line environment where the container is running, select Ctrl+C.

    疑難排解Troubleshooting

    如果您在啟用輸出掛接和記錄的情況下執行容器,容器將會產生記錄檔,有助於排解在啟動或執行容器時所發生的問題。If you run the container with an output mount and logging enabled, the container generates log files that are helpful to troubleshoot issues that happen while starting or running the container.

    帳務Billing

    異常偵測器容器會使用您 Azure 帳戶上的_異常_偵測器資源, 將帳單資訊傳送至 azure。The Anomaly Detector containers send billing information to Azure, using an Anomaly Detector resource on your Azure account.

    至容器的查詢會使用於 Azure 資源的定價層計費<ApiKey>Queries to the container are billed at the pricing tier of the Azure resource that's used for the <ApiKey>.

    Azure 認知服務容器在未連線至計費端點以進行計量的情況下,將無法被授權以執行。Azure Cognitive Services containers aren't licensed to run without being connected to the billing endpoint for metering. 您必須讓容器隨時都能與計量端點進行帳單資訊的通訊。You must enable the containers to communicate billing information with the billing endpoint at all times. 認知服務容器不會將客戶資料 (例如正在分析的影像或文字) 傳送至 Microsoft。Cognitive Services containers don't send customer data, such as the image or text that's being analyzed, to Microsoft.

    連接到 AzureConnect to Azure

    容器需要計費引數值才能執行。The container needs the billing argument values to run. 這些值讓容器能夠連線到計費端點。These values allow the container to connect to the billing endpoint. 容器會每隔 10 到 15 分鐘回報使用量。The container reports usage about every 10 to 15 minutes. 如果容器未在允許的時間範圍內連線到 Azure,容器會繼續執行,但在還原計費端點之前不會提供查詢。If the container doesn't connect to Azure within the allowed time window, the container continues to run but doesn't serve queries until the billing endpoint is restored. 以 10 到 15 分鐘的相同時間間隔嘗試連線 10 次。The connection is attempted 10 times at the same time interval of 10 to 15 minutes. 如果無法在 10 次嘗試內連線到計費端點,則容器會停止執行。If it can't connect to the billing endpoint within the 10 tries, the container stops running.

    計費引數Billing arguments

    針對docker run命令來啟動容器時,必須指定下列選項中的所有三個有效的值:For the docker run command to start the container, all three of the following options must be specified with valid values:

    選項Option 說明Description
    ApiKey 用來追蹤帳單資訊的認知服務資源的 API 金鑰。The API key of the Cognitive Services resource that's used to track billing information.
    此選項的值必須設定為 佈建的資源中指定的 API 金鑰BillingThe value of this option must be set to an API key for the provisioned resource that's specified in Billing.
    Billing 用來追蹤帳單資訊的認知服務資源端點。The endpoint of the Cognitive Services resource that's used to track billing information.
    此選項的值必須設定為已佈建 Azure 資源的端點 URI。The value of this option must be set to the endpoint URI of a provisioned Azure resource.
    Eula 表示您接受容器的授權。Indicates that you accepted the license for the container.
    此選項的值必須設定為接受The value of this option must be set to accept.

    如需這些選項的詳細資訊,請參閱設定容器For more information about these options, see Configure containers.

    部落格文章Blog posts

    開發人員範例Developer samples

    開發人員範例可從我們的 GitHub 存放庫取得。Developer samples are available at our GitHub repository.

    檢視網路研討會View webinar

    加入網路研討會以了解:Join the webinar to learn about:

    • 如何將認知服務部署到任何使用 Docker 的機器How to deploy Cognitive Services to any machine using Docker
    • 如何將認知服務部署到 AKSHow to deploy Cognitive Services to AKS

    總結Summary

    在本文中, 您已瞭解下載、安裝及執行異常偵測器容器的概念和工作流程。In this article, you learned concepts and workflow for downloading, installing, and running Anomaly Detector containers. 摘要說明:In summary:

    • 異常偵測器提供一個適用于 Docker 的 Linux 容器, 並使用批次和串流、預期的範圍推斷和敏感度調整來封裝異常偵測。Anomaly Detector provides one Linux container for Docker, encapsulating anomaly detection with batch vs streaming, expected range inference, and sensitivity tuning.
    • 容器映射是從專用於容器預覽的私人 Azure Container Registry 下載。Container images are downloaded from a private Azure Container Registry dedicated for containers preview.
    • 容器映像是在 Docker 中執行。Container images run in Docker.
    • 您可以藉由指定容器的主機 URI, 使用 REST API 或 SDK 來呼叫異常偵測器容器中的作業。You can use either the REST API or SDK to call operations in Anomaly Detector containers by specifying the host URI of the container.
    • 將容器具現化時,您必須指定帳單資訊。You must specify billing information when instantiating a container.

    重要

    認知服務容器在未連線至 Azure 以進行計量的情況下,將無法被授權以執行。Cognitive Services containers are not licensed to run without being connected to Azure for metering. 客戶必須啟用容器以持續與計量服務進行帳單資訊的通訊。Customers need to enable the containers to communicate billing information with the metering service at all times. 認知服務容器不會將客戶資料 (例如正在分析的時間序列資料) 傳送給 Microsoft。Cognitive Services containers do not send customer data (e.g., the time series data that is being analyzed) to Microsoft.

    後續步驟Next steps