您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

如何监视 Azure Redis 缓存How to monitor Azure Redis Cache

Azure Redis 缓存使用 Azure Monitor 提供用于监视缓存实例的几个选项。Azure Redis Cache uses Azure Monitor to provide several options for monitoring your cache instances. 可以查看度量值、将度量值图表固定到启动面板、自定义监视图表的日期和时间范围、在图表中添加和删除度量值,以及设置符合特定条件时发出的警报。You can view metrics, pin metrics charts to the Startboard, customize the date and time range of monitoring charts, add and remove metrics from the charts, and set alerts when certain conditions are met. 借助这些工具,可以监视 Azure Redis 缓存实例的运行状况,以及管理缓存应用程序。These tools enable you to monitor the health of your Azure Redis Cache instances and help you manage your caching applications.

每分钟使用 Redis INFO 命令收集约两次 Azure Redis 缓存实例的指标,然后将其自动存储 30 天(请参阅导出缓存指标以配置不同保留期策略),以便这些指标可以显示在指标图表中并由预警规则进行评估。Metrics for Azure Redis Cache instances are collected using the Redis INFO command approximately twice per minute and automatically stored for 30 days (see Export cache metrics to configure a different retention policy) so they can be displayed in the metrics charts and evaluated by alert rules. 深入了解用于每个缓存指标的不同 INFO 值,请参阅可用指标和报告间隔For more information about the different INFO values used for each cache metric, see Available metrics and reporting intervals.

若要查看缓存指标,请浏览Azure 门户中的缓存实例。To view cache metrics, browse to your cache instance in the Azure portal. Azure Redis 缓存在“概述”边栏选项卡和“Redis 指标”边栏选项卡上提供一些内置图表。Azure Redis Cache provides some built-in charts on the Overview blade and the Redis metrics blade. 通过添加或删除度量值以及更改报告间隔可以自定义每个图表。Each chart can be customized by adding or removing metrics and changing the reporting interval.

Redis 指标

查看预配置的指标图表View pre-configured metrics charts

“概述”边栏选项卡具有以下预配置的监视图表。The Overview blade has the following pre-configured monitoring charts.

监视图表Monitoring charts

“概述”边栏选项卡中的“监视”部分有“命中数和未命中数”、“获取数和设置数”、“连接数”以及“总命令数”图表。The Monitoring section in the Overview blade has Hits and Misses, Gets and Sets, Connections, and Total Commands charts.

监视图表

图表使用情况Usage charts

“概述”边栏选项卡中的“使用情况”部分有“Redis 服务器负载”、“内存使用情况”、“网络带宽”和“CPU 使用率”图表,并且还显示缓存实例的“定价层”。The Usage section in the Overview blade has Redis Server Load, Memory Usage, Network Bandwidth, and CPU Usage charts, and also displays the Pricing tier for the cache instance.

图表使用情况

“定价层”显示缓存定价层,并可用于将缓存缩放到不同的定价层。The Pricing tier displays the cache pricing tier, and can be used to scale the cache to a different pricing tier.

通过 Azure Monitor 查看指标View metrics with Azure monitor

若要使用 Azure Monitor 查看 Redis 指标和创建自定义图表,从“资源菜单”单击“指标”,并使用所需的指标、报告间隔、图表类型等对图表进行自定义。To view Redis metrics and create custom charts using Azure Monitor, click Metrics from the Resource menu, and customize your chart using the desired metrics, reporting interval, chart type, and more.

Redis 指标

有关使用 Azure Monitor 处理指标的详细信息,请参阅 Microsoft Azure 中的指标概述For more information on working with metrics using Azure Monitor, see Overview of metrics in Microsoft Azure.

导出缓存指标Export cache metrics

默认情况下,Azure Monitor 中的缓存指标将被存储 30 天,然后将被删除。By default, cache metrics in Azure Monitor are stored for 30 days and then deleted. 若要延长缓存指标的保存时间,使其超过 30 天,可以为缓存指标指定存储帐户,并指定“保留期(天)”策略。To persist your cache metrics for longer than 30 days, you can designate a storage account and specify a Retention (days) policy for your cache metrics.

若要配置缓存指标的存储帐户:To configure a storage account for your cache metrics:

  1. 从“Redis 缓存”边栏选项卡中的“资源菜单”单击“诊断”。Click Diagnostics from the Resource menu in the Redis Cache blade.
  2. 单击“打开”。Click On.
  3. 选中“存档到存储帐户”。Check Archive to a storage account.
  4. 选择要在其中存储缓存指标的存储帐户。Select the storage account in which to store the cache metrics.
  5. 选中“1 分钟”复选框,并指定“保留期(天)”策略。Check the 1 minute checkbox and specify a Retention (days) policy. 如果不想应用任何保留期策略也不想永久保留数据,可将“保留期(天)”设置为“0”。If you do not want to apply any retention policy and retain data forever, set Retention (days) to 0.
  6. 单击“ 保存”。Click Save.

Redis 诊断

备注

除了将缓存指标存档至存储区外,还可以将其流式传输到事件中心或将其发送到 Log AnalyticsIn addition to archiving your cache metrics to storage, you can also stream them to an Event hub or send them to Log Analytics.

若要访问指标,可按前文所述在 Azure 门户中查看它们,还可以使用 Azure Monitor 指标 REST API 对其进行访问。To access your metrics, you can view them in the Azure portal as previously described in this article, and you can also access them using the Azure Monitor Metrics REST API.

备注

如果更改存储帐户,以前配置的存储帐户中的数据仍可供下载,但并不会显示在 Azure 门户中。If you change storage accounts, the data in the previously configured storage account remains available for download, but it is not displayed in the Azure portal.

可用度量值和报告间隔Available metrics and reporting intervals

将使用多个报告间隔报告缓存指标,其中包括“前一小时”、“今天”、“前一周”和“自定义”。Cache metrics are reported using several reporting intervals, including Past hour, Today, Past week, and Custom. 每个指标图表的“指标”边栏选项卡会在图表中显示每个指标的平均值、最小值和最大值,并且一些指标会显示总报告间隔。The Metric blade for each metrics chart displays the average, minimum, and maximum values for each metric in the chart, and some metrics display a total for the reporting interval.

每个度量值均包含两个版本。Each metric includes two versions. 一个指标测量整个缓存的性能以及使用群集的缓存的性能,名称中包含 (Shard 0-9) 的另一指标版本则测量缓存中单个分片的性能。One metric measures performance for the entire cache, and for caches that use clustering, a second version of the metric that includes (Shard 0-9) in the name measures performance for a single shard in a cache. 例如,如果缓存有 4 个分片,Cache Hits 就是整个缓存的命中总数,而 Cache Hits (Shard 3) 就只是该缓存分片的命中数。For example if a cache has 4 shards, Cache Hits is the total amount of hits for the entire cache, and Cache Hits (Shard 3) is just the hits for that shard of the cache.

备注

即使在缓存处于空闲状态,且没有连接的活动客户端应用程序时,也可能会看到一些缓存活动,例如,连接的客户端、内存使用率以及正在执行的操作。Even when the cache is idle with no connected active client applications, you may see some cache activity, such as connected clients, memory usage, and operations being performed. Azure Redis 缓存实例的操作期间,此活动是正常情况。This activity is normal during the operation of an Azure Redis Cache instance.

指标Metric DescriptionDescription
缓存命中数Cache Hits 在指定的报告间隔期间,成功的键查找次数。The number of successful key lookups during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 keyspace_hitsThis maps to keyspace_hits from the Redis INFO command.
缓存延迟(预览)Cache Latency (Preview) 基于缓存的节点间延迟计算缓存的延迟。The latency of the cache calculated based off the internode latency of the cache. 该指标以微秒为单位,具有三个维度:“Avg”、“Min”和“Max”,分别表示指定的报告间隔期间缓存的平均延迟、最小延迟和最大延迟。This metric is measured in microseconds, and has three dimensions: "Avg", "Min", and "Max" which represent the average, minimum, and maximum latency of the cache respectively during the specified reporting interval.
缓存未命中数Cache Misses 在指定的报告间隔期间,失败的键查找次数。The number of failed key lookups during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 keyspace_missesThis maps to keyspace_misses from the Redis INFO command. 缓存未命中并不一定意味着缓存出现了问题。Cache misses do not necessarily mean there is an issue with the cache. 例如,在使用缓存端编程模式时,应用程序会首先查找缓存中的项。For example, when using the cache-aside programming pattern, an application looks first in the cache for an item. 如果该项不存在(缓存未命中),则将从数据库中检索该项并将其添加到下一次缓存中。If the item is not there (cache miss), the item is retrieved from the database and added to the cache for next time. 对于缓存端编程模式,缓存未命中是正常行为。Cache misses are normal behavior for the cache-aside programming pattern. 如果缓存未命中数大于预期值,请检查从缓存中填充并读取的应用程序逻辑。If the number of cache misses is higher than expected, examine the application logic that populates and reads from the cache. 如果由于内存压力而导致项目从缓存中逐出,则可能存在一些缓存未命中的情况,但度量值 Used MemoryEvicted Keys 可以更好的监视内存压力。If items are being evicted from the cache due to memory pressure then there may be some cache misses, but a better metric to monitor for memory pressure would be Used Memory or Evicted Keys.
缓存读取量Cache Read 指定报告间隔期间,从缓存中读取的数据量,以每秒兆字节数(MB/秒)为单位。The amount of data read from the cache in Megabytes per second (MB/s) during the specified reporting interval. 此值来源于支持虚拟机的网络接口卡,该虚拟机托管缓存,但并不特定于 Redis。This value is derived from the network interface cards that support the virtual machine that hosts the cache and is not Redis specific. 此值对应于该缓存使用的网络带宽。如果要针对服务器端网络带宽限制设置警报,则可使用此 Cache Read 计数器来创建警报。请参阅此表,了解各种缓存定价层和大小所遵循的带宽限制。This value corresponds to the network bandwidth used by this cache. If you want to set up alerts for server-side network bandwidth limits, then create it using this Cache Read counter. See this table for the observed bandwidth limits for various cache pricing tiers and sizes.
缓存写入量Cache Write 指定报告间隔期间,写入缓存中的数据量,以每秒兆字节数(MB/秒)为单位。The amount of data written to the cache in Megabytes per second (MB/s) during the specified reporting interval. 此值来源于支持虚拟机的网络接口卡,该虚拟机托管缓存,但并不特定于 Redis。This value is derived from the network interface cards that support the virtual machine that hosts the cache and is not Redis specific. 此值对应于从客户端发送到缓存的数据的网络带宽。This value corresponds to the network bandwidth of data sent to the cache from the client.
连接的客户端数Connected Clients 指定的报告间隔期间,客间户端与缓存的连接数。The number of client connections to the cache during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 connected_clientsThis maps to connected_clients from the Redis INFO command. 一旦达到了连接限制,则对缓存的后续连接尝试会失败。Once the connection limit is reached subsequent connection attempts to the cache will fail. 注意,即使没有任何活动的客户端应用程序,由于内部进程和连接,仍可能存在一些连接的客户端的实例。Note that even if there are no active client applications, there may still be a few instances of connected clients due to internal processes and connections.
CPUCPU 指定报告间隔期间,Azure Redis 缓存服务器的 CPU 使用率(以百分比表示)。The CPU utilization of the Azure Redis Cache server as a percentage during the specified reporting interval. 此值映射到操作系统 \Processor(_Total)\% Processor Time 性能计数器。This value maps to the operating system \Processor(_Total)\% Processor Time performance counter.
ErrorsErrors 在指定的报告间隔期间,缓存可能会出现的特定故障和性能问题。Specific failures and performance issues that the cache could be experiencing during a specified reporting interval. 该指标具有八个维度,表示不同的错误类型,但在将来可能会添加更多维度。This metric has eight dimensions representing different error types, but could have more added in the future. 现在所代表的错误类型如下所示:The error types represented now are as follows:
  • Failover - 缓存故障转移时(从属设备提升到主机)Failover – when a cache fails over (slave promotes to master)
  • Crash - 缓存在任一节点上意外故障时Crash – when the cache crashes unexpectedly on either of the nodes
  • Dataloss - 缓存上发生数据丢失时Dataloss – when there is dataloss on the cache
  • UnresponsiveClients - 客户端从服务器读取数据的速度不够快时UnresponsiveClients – when the clients are not reading data from the server fast enough
  • AOF - 存在与 AOF 持久化有关的问题时AOF – when there is an issue related to AOF persistence
  • RDB - 存在与 RDB 持久化有关的问题时RDB – when there is an issue related to RDB persistence
  • Import - 存在与导入 RDB 有关的问题时Import – when there is an issue related to Import RDB
  • Export - 存在与导出 RDB 有关的问题时Export – when there is an issue related to Export RDB
逐出的密钥数Evicted Keys 由于 maxmemory 限制,指定的报告间隔期间从缓存中逐出的项目数。The number of items evicted from the cache during the specified reporting interval due to the maxmemory limit. 此值映射到 Redis INFO 命令输出中的 evicted_keysThis maps to evicted_keys from the Redis INFO command.
过期的密钥数Expired Keys 指定的报告间隔期间,缓存中过期的项目数。The number of items expired from the cache during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 expired_keysThis value maps to expired_keys from the Redis INFO command.
获取数Gets 指定的报告间隔期间,缓存中的获取操作数。The number of get operations from the cache during the specified reporting interval. 此值是以下 Redis INFO 所有命令中的值的总和:cmdstat_getcmdstat_hgetcmdstat_hgetallcmdstat_hmgetcmdstat_mgetcmdstat_getbitcmdstat_getrange,并且等效于报告间隔期间缓存命中和未命中数的总和。This value is the sum of the following values from the Redis INFO all command: cmdstat_get, cmdstat_hget, cmdstat_hgetall, cmdstat_hmget, cmdstat_mget, cmdstat_getbit, and cmdstat_getrange, and is equivalent to the sum of cache hits and misses during the reporting interval.
每秒操作数Operations per Second 指定的报告间隔期间,由缓存服务器处理的每秒命令总数。The total number of commands processed per second by the cache server during the specified reporting interval. 此值映射到 Redis INFO 命令中的“instantaneous_ops_per_sec”。This value maps to "instantaneous_ops_per_sec" from the Redis INFO command.
Redis 服务器负载Redis Server Load Redis 服务器忙于处理消息并且非空闲等待消息的周期百分比。The percentage of cycles in which the Redis server is busy processing and not waiting idle for messages. 如果此计数器达到 100,则意味着 Redis 服务器已达到性能上限并且 CPU 无法更快地工作。If this counter reaches 100 it means the Redis server has hit a performance ceiling and the CPU can't process work any faster. 如果看到高 Redis 服务器负载,则会在客户端看到超时异常。If you are seeing high Redis Server Load then you will see timeout exceptions in the client. 在这种情况下,应该考虑将数据扩大或分区到多个缓存。In this case you should consider scaling up or partitioning your data into multiple caches.
设置数Sets 指定的报告间隔期间,对缓存的设置操作数。The number of set operations to the cache during the specified reporting interval. 此值是以下 Redis INFO 所有命令中的值的总和:cmdstat_setcmdstat_hsetcmdstat_hmsetcmdstat_hsetnxcmdstat_lsetcmdstat_msetcmdstat_msetnxcmdstat_setbitcmdstat_setexcmdstat_setrangecmdstat_setnxThis value is the sum of the following values from the Redis INFO all command: cmdstat_set, cmdstat_hset, cmdstat_hmset, cmdstat_hsetnx, cmdstat_lset, cmdstat_mset, cmdstat_msetnx, cmdstat_setbit, cmdstat_setex, cmdstat_setrange, and cmdstat_setnx.
总密钥数Total Keys 上一个报表时期中,缓存中的最大密钥数。The maximum number of keys in the cache during the past reporting time period. 此值映射到 Redis INFO 命令输出中的 keyspaceThis maps to keyspace from the Redis INFO command. 由于基本指标系统的限制,对于启用了群集的缓存,“总密钥数”返回报告间隔期间具有最大密钥数的分片的最大密钥数。Due to a limitation of the underlying metrics system, for caches with clustering enabled, Total Keys returns the maximum number of keys of the shard that had the maximum number of keys during the reporting interval.
总操作数Total Operations 指定的报告间隔期间,由缓存服务器处理的命令总数。The total number of commands processed by the cache server during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 total_commands_processedThis value maps to total_commands_processed from the Redis INFO command. 注意,当 Azure Redis 缓存纯粹用于发布/订阅时,将不存在 Cache HitsCache MissesGetsSets 的度量值,但存在 Total Operations 度量值,该度量值反映发布/订阅操作的缓存使用情况。Note that when Azure Redis Cache is used purely for pub/sub there will be no metrics for Cache Hits, Cache Misses, Gets, or Sets, but there will be Total Operations metrics that reflect the cache usage for pub/sub operations.
已用内存Used Memory 在指定报告间隔期间,缓存中的键/值对所用的缓存内存量(以 MB 为单位)。The amount of cache memory used for key/value pairs in the cache in MB during the specified reporting interval. 此值映射到 Redis INFO 命令输出中的 used_memoryThis value maps to used_memory from the Redis INFO command. 这不包括元数据或碎片。This does not include metadata or fragmentation.
已用内存百分比Used Memory Percentage 指定报告间隔期间使用的总内存的百分比。The % of total memory that is being used during the specified reporting interval. 这引用 Redis INFO 命令中的“used_memory”值计算百分比。This references the "used_memory" value from the Redis INFO command to calculate the percentage.
已用内存 RSSUsed Memory RSS 指定报告间隔期间所用的缓存内存量(以 MB 为单位),包括碎片和元数据。The amount of cache memory used in MB during the specified reporting interval, including fragmentation and metadata. 此值映射到 Redis INFO 命令输出中的 used_memory_rssThis value maps to used_memory_rss from the Redis INFO command.

警报Alerts

可配置为基于指标和活动日志接收警报。You can configure to receive alerts based on metrics and activity logs. 通过 Azure Monitor 可配置警报,使警报触发时执行以下操作:Azure Monitor allows you to configure an alert to do the following when it triggers:

  • 发送电子邮件通知Send an email notification
  • 调用 WebhookCall a webhook
  • 调用 Azure 逻辑应用Invoke an Azure Logic App

若要配置缓存的预警规则,从“资源菜单”单击“预警规则”。To configure Alert rules for your cache, click Alert rules from the Resource menu.

监视

有关配置和使用警报的详细信息,请参阅警报概述For more information about configuring and using Alerts, see Overview of Alerts.

活动日志Activity Logs

活动日志提供针对 Azure Redis 缓存实例执行的操作的详细信息。Activity logs provide insight into the operations that were performed on your Azure Redis Cache instances. 活动日志以前称为“审核日志”或“操作日志”。It was previously known as "audit logs" or "operational logs". 通过活动日志,可确定对 Azure Redis 缓存实例执行的任何写入操作 (PUT、POST、DELETE) 的“操作内容、操作人员和操作时间”。Using activity logs, you can determine the "what, who, and when" for any write operations (PUT, POST, DELETE) taken on your Azure Redis Cache instances.

备注

活动日志不包括读取 (GET) 操作。Activity logs do not include read (GET) operations.

若要查看缓存的活动日志,从“资源菜单”单击“活动日志”。To view activity logs for your cache, click Activity logs from the Resource menu.

有关活动日志的详细信息,请参阅 Azure 活动日志概述For more information about Activity logs, see Overview of the Azure Activity Log.