监视 Azure 认知搜索的操作和活动Monitor operations and activity of Azure Cognitive Search

本文介绍服务(资源)级别以及工作负荷级别(查询和索引)的监视,并推荐用于监视用户访问的框架。This article introduces monitoring at the service (resource) level, at the workload level (queries and indexing), and suggests a framework for monitoring user access.

在不同的领域,你会结合使用内置基础结构和 Azure Monitor 等基础服务,以及可返回统计信息、计数和状态的服务 API。Across the spectrum, you'll use a combination of built-in infrastructure and foundational services like Azure Monitor, as well as service APIs that return statistics, counts, and status. 了解功能的范围有助于构建反馈循环,以便可以解决出现的问题。Understanding the range of capabilities can help you construct a feedback loop so that you can address problems as they emerge.

使用 Azure MonitorUse Azure Monitor

许多服务(包括 Azure 认知搜索)利用 Azure Monitor 来提供警报、指标和日志记录诊断数据。Many services, including Azure Cognitive Search, leverage Azure Monitor for alerts, metrics, and logging diagnostic data. 对于 Azure 认知搜索,内置监视基础结构主要用于资源级监视(服务运行状况)和查询监视For Azure Cognitive Search, the built-in monitoring infrastructure is used primarily for resource-level monitoring (service health) and query monitoring.

以下屏幕截图可帮助你在门户中找到 Azure Monitor 功能。The following screenshot helps you locate Azure Monitor features in the portal.

  • 位于概述主页中的“监视”选项卡显示关键指标的概览。 Monitoring tab, located in the main overview page, shows key metrics at a glance.
  • 紧靠在“概述”下面的“活动日志”报告资源级操作:服务运行状况和 API 密钥请求通知。 Activity log, just below Overview, reports on resource-level actions: service health and API key request notifications.
  • 列表中接下来的“监视”提供可配置的警报、指标和诊断日志。 Monitoring, further down the list, provides configurable alerts, metrics, and diagnostic logs. 可按需创建这些内容。Create these when you need them. 收集并存储数据后,可以查询或可视化信息以获取见解。Once data is collected and stored, you can query or visualize the information for insights.

搜索服务中的 Azure Monitor 集成Azure Monitor integration in a search service

报告数字的精确度Precision of reported numbers

门户页面每隔几分钟刷新一次。Portal pages are refreshed every few minutes. 因此,门户中报告的数字是近似值,旨在让你大致了解系统为请求提供服务时的表现。As such, numbers reported in the portal are approximate, intended to give you a general sense of how well your system is servicing requests. 实际指标(例如每秒查询数 (QPS))可能高于或低于页面上显示的数字。Actual metrics, such as queries per second (QPS) may be higher or lower than the number shown on the page.

活动日志和服务运行状况Activity logs and service health

活动日志从 Azure 资源管理器收集信息,并报告服务运行状况的变化。The Activity log collects information from Azure Resource Manager and reports on changes to service health. 可以监视活动日志来了解服务运行状况相关的严重、错误和警告状态。You can monitor the activity log for critical, error, and warning conditions related to service health.

对于服务中的任务(例如查询、编制索引或创建对象),你会看到每个请求的一般信息性通知(例如“获取管理密钥”和“获取查询密钥”),但看不到特定的操作本身。 For in-service tasks - such as queries, indexing, or creating objects - you'll see generic informational notifications like Get Admin Key and Get Query keys for each request, but not the specific action itself. 如需这种粒度的信息,必须配置诊断日志记录。For information of this grain, you must configure diagnostic logging.

可以通过左侧导航窗格、顶部窗口命令栏中的“通知”或者“诊断并解决问题”页访问活动日志You can access the Activity log from the left-navigation pane, or from Notifications in the top window command bar, or from the Diagnose and solve problems page.

监视存储Monitor storage

“概述”页中内置的选项卡式页面报告资源的使用情况。Tabbed pages built into the Overview page report out on resource usage. 只要开始使用服务,就立即会提供此信息,不需要进行配置。页面每隔几分钟刷新一次。This information becomes available as soon as you start using the service, with no configuration required, and the page is refreshed every few minutes.

对于将哪个层用于生产工作负荷或是否要调整活动副本和分区的数目这样的问题,可以根据这些指标进行最终决策,因为这些指标会显示资源的消耗速度,以及当前配置处理现有负载的有效程度。If you are finalizing decisions about which tier to use for production workloads, or whether to adjust the number of active replicas and partitions, these metrics can help you with those decisions by showing you how quickly resources are consumed and how well the current configuration handles the existing load.

目前不提供存储相关的警报;存储消耗量不会聚合或记录到 Azure Monitor 的 AzureMetrics 表中。Alerts related to storage are not currently available; storage consumption is not aggregated or logged into the AzureMetrics table in Azure Monitor. 需要生成一个自定义解决方案用于发出资源相关的通知,代码可在其中检查存储大小并处理响应。You would need to build a custom solution that emits resource-related notifications, where your code checks for storage size and handles the response. 有关存储指标的详细信息,请参阅获取服务统计信息For more information about storage metrics, see Get Service Statistics.

门户中的“使用情况”选项卡相对于服务层级施加的当前限制显示资源可用性让你直观地进行监视。 For visual monitoring in the portal, the Usage tab shows you resource availability relative to current limits imposed by the service tier.

下图描述免费服务的情况,该服务的上限是每个类型 3 个对象,最大存储为 50 MB。The following illustration is for the free service, which is capped at 3 objects of each type and 50 MB of storage. “基本”或“标准”服务的限制更高,在增加分区计数的情况下,最大存储会按比例增大。A Basic or Standard service has higher limits, and if you increase the partition counts, maximum storage goes up proportionally.

相对于层级限制的使用状态Usage status relative to tier limits

监视工作负荷Monitor workloads

记录的事件包括与索引编制和查询相关的事件。Logged events include those related to indexing and queries. Log Analytics 中的 AzureDiagnostics 表收集与查询和索引编制相关的操作数据。The AzureDiagnostics table in Log Analytics collects operational data related to queries and indexing.

记录的大部分数据是只读操作的数据。Most of the logged data is for read-only operations. 对于不在日志中捕获的其他创建-更新-删除操作,可以在搜索服务中查询系统信息。For other create-update-delete operations not captured in the log, you can query the search service for system information.

OperationNameOperationName 说明Description
ServiceStatsServiceStats 此操作是对获取服务统计信息的例行调用(直接调用或隐式调用),以便在加载或刷新门户概述页时在其中填充信息。This operation is a routine call to Get Service Statistics, either called directly or implicitly to populate a portal overview page when it is loaded or refreshed.
Query.SearchQuery.Search 针对索引的查询请求。有关记录的查询的信息,请参阅监视查询Query requests against an index See Monitor queries for information about logged queries.
Indexing.IndexIndexing.Index 此操作是对添加、更新或删除文档的调用。This operation is a call to Add, Update or Delete Documents.
indexes.Prototypeindexes.Prototype 这是导入数据向导创建的索引。This is an index created by the Import Data wizard.
Indexers.CreateIndexers.Create 通过导入数据向导显式或隐式创建索引器。Create an indexer explicitly or implicitly through the Import Data wizard.
Indexers.GetIndexers.Get 每当运行索引器,就会返回该索引器的名称。Returns the name of an indexer whenever the indexer is run.
Indexers.StatusIndexers.Status 每当运行索引器,就会返回该索引器的状态。Returns the status of an indexer whenever the indexer is run.
DataSources.GetDataSources.Get 每当运行索引器,就会返回数据源的名称。Returns the name of the data source whenever an indexer is run.
Indexes.GetIndexes.Get 每当运行索引器,就会返回索引的名称。Returns the name of an index whenever an indexer is run.

有关工作负荷的 Kusto 查询Kusto queries about workloads

如果启用了日志记录,可以查询 AzureDiagnostics,以获取在服务中运行的操作的列表及其运行时间。If you enabled logging, you can query AzureDiagnostics for a list of operations that ran on your service and when. 还可以关联活动来调查性能的变化。You can also correlate activity to investigate changes in performance.

示例:列出操作Example: List operations

返回操作的列表以及每个操作的计数。Return a list of operations and a count of each one.

| summarize count() by OperationName

示例:关联操作Example: Correlate operations

将查询请求关联到索引编制操作,并在时间图表中呈现数据点,以确定操作是否一致。Correlate query request with indexing operations, and render the data points across a time chart to see operations coincide.

| summarize OperationName, Count=count()
| where OperationName in ('Query.Search', 'Indexing.Index')
| summarize Count=count(), AvgLatency=avg(DurationMs) by bin(TimeGenerated, 1h), OperationName
| render timechart

使用搜索 APIUse search APIs

Azure 认知搜索 REST API 和 .NET SDK 支持采用编程方式访问服务指标、索引和索引器信息,以及文档计数。Both the Azure Cognitive Search REST API and the .NET SDK provide programmatic access to service metrics, index and indexer information, and document counts.

监视用户的访问Monitor user access

由于搜索索引是较大客户端应用程序的一个组件,因此,没有任何内置方法可用于控制或监视每个用户对索引的访问。Because search indexes are a component of a larger client application, there is no built-in methodology for controlling or monitoring per-user access to an index. 对于管理请求或查询请求,假设请求来自客户端应用程序。Requests are assumed to come from a client application, for either admin or query requests. 管理读写操作包括在整个服务中创建、更新和删除对象。Admin read-write operations include creating, updating, deleting objects across the entire service. 只读操作是针对文档集合运行的查询,范围限定为单个索引。Read-only operations are queries against the documents collection, scoped to a single index.

因此,活动日志中显示的内容是对使用管理密钥或查询密钥的调用的引用。As such, what you'll see in the activity logs are references to calls using admin keys or query keys. 相应的密钥包含在源自客户端代码的请求中。The appropriate key is included in requests originating from client code. 服务中未配备用于处理标识令牌或模拟的功能。The service is not equipped to handle identity tokens or impersonation.

确实存在按用户授权的业务要求时,建议与 Azure Active Directory 集成。When business requirements do exist for per-user authorization, the recommendation is integration with Azure Active Directory. 可以使用 $filter 和用户标识来修整用户不应看到的文档的搜索结果。You can use $filter and user identities to trim search results of documents that a user should not see.

无法单独从包含 $filter 参数的查询字符串记录此信息。There is no way to log this information separately from the query string that includes the $filter parameter. 有关报告查询字符串的详细信息,请参阅监视查询See Monitor queries for details on reporting query strings.

后续步骤Next steps

熟练运用 Azure Monitor 是监督任何 Azure 服务(包括 Azure 认知搜索等资源)的关键所在。Fluency with Azure Monitor is essential for oversight of any Azure service, including resources like Azure Cognitive Search. 如果你不熟悉 Azure Monitor,请花些时间阅读资源相关的文章。If you are not familiar with Azure Monitor, take the time to review articles related to resources. 除教程以外,以下文章也是不错的入门资源。In addition to tutorials, the following article is a good place to start.