Skip to Content
《使用 Kubernetes 实现云原生 DevOps(第二版)》
book

《使用 Kubernetes 实现云原生 DevOps(第二版)》

by Justin Domingus, John Arundel
May 2025
Intermediate to advanced
356 pages
3h 47m
Chinese
O'Reilly Media, Inc.
Content preview from 《使用 Kubernetes 实现云原生 DevOps(第二版)》

第 16 章 Kubernetes 中的度量 Kubernetes 中的度量指标

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

你有可能对某一主题知之甚少,以至于完全无知。

弗兰克-赫伯特,《章屋》:沙丘

在本章中,我们将从第 15 章中介绍的指标概念出发,深入研究 Kubernetes 的细节:有哪些指标,哪些指标对云原生服务很重要,如何选择要关注的指标,如何分析指标数据以获得可操作的信息,以及如何将原始指标数据转化为有用的仪表盘和警报?最后,我们将概述一些度量工具和平台选项。

衡量标准究竟是什么?

正如我们在"度量介绍 "中所看到的,度量是对特定事物的数字测量。传统服务器世界中的一个熟悉例子是特定机器的内存使用率。如果当前只有 10% 的物理内存分配给了用户进程,那么这台机器就有剩余容量。但是,如果 90% 的内存都在使用,那么这台机器就可能非常繁忙。

因此,度量指标能为我们提供的一种有价值的信息是某一特定时刻正在发生的事情的快照。但我们可以做得更多。随着工作负载的启动和停止,内存使用率一直在上升和下降,但有时我们感兴趣的是内存使用率随时间的变化

时间序列数据

如果定期对内存使用情况进行采样,就可以创建该数据的时间序列图 16-1显示了谷歌 Kubernetes 引擎节点一周内存使用情况的时间序列数据图。这比少量的瞬时值更能让人明白发生了什么。

Graph showing fluctuating memory usage
图 16-1. GKE 节点内存使用时间序列图

我们对云原生可观测性感兴趣的大多数指标都是以时间序列表示的。它们也都是数值型的。与日志数据等不同,指标是可以进行数学计算和统计的数值。

计数器和量规

它们是什么类型的数字?虽然有些量可以用整数表示(例如机器中物理 CPU 的数量),但大多数都需要小数部分,为了省去处理两种不同类型数字的麻烦,度量值几乎总是用浮点十进制表示。

因此,度量值主要有两种类型:计数器仪表。计数器只能上升(或重置为零),适用于测量服务请求数和接收到的错误数。而仪表则可以上下浮动,适用于持续变化的数量(如内存使用量)或表示其他数量的比率。

有些问题的答案只是 "是 "或 "否":例如,某个特定端点是否对 HTTP 连接做出响应。在这种情况下,合适的度量标准将是一个取值范围有限的量表:比如 0 和 1。

例如,端点的 HTTP 检查可以命名为http.can_connect ,当端点响应时,其值为 1,否则为 0。

指标能告诉我们什么?

指标有什么用?正如我们在本章前面所看到的,指标可以告诉你什么时候出现了问题。例如,如果您的错误率突然上升(或对支持页面的请求突然激增),这可能表明出现了问题。您可以根据阈值为某些指标自动生成警报。

但衡量标准也能告诉你事情的进展情况,例如,你的应用程序目前能同时支持多少用户。这些数字的长期趋势有助于运营决策和商业智能

选择好的衡量标准

起初,你可能会想:"如果衡量标准是好的,那么大量的衡量标准一定会更好!"但事实并非如此。你不可能监控一切。例如,Google Cloud 的运营套件可以捕获数百个有关云资源的内置指标数据,其中包括

instance/network/sent_packets_count

每个计算实例发送的网络数据包数量

storage/object_count ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

在 Kubernetes 上管理云原生数据

在 Kubernetes 上管理云原生数据

Jeff Carpenter, Patrick McFadin
《Kubernetes 最佳实践》第二版

《Kubernetes 最佳实践》第二版

Brendan Burns, Eddie Villalba, Dave Strebel, Lachlan Evenson
生产 Kubernetes

生产 Kubernetes

Josh Rosso, Rich Lander, Alex Brand, John Harris
Cloud Native DevOps mit Kubernetes

Cloud Native DevOps mit Kubernetes

John Arundel, Justin Domingus

Publisher Resources

ISBN: 9798341659179