Skip to Content
监控运维实践:原则与策略
book

监控运维实践:原则与策略

by Mike Julian
November 2020
Intermediate to advanced
142 pages
3h 12m
Chinese
Posts & Telecom Press
Content preview from 监控运维实践:原则与策略
应用程序监控
|
71
人们经常会问,该端点到底应该是应用程序中的另一个路径,还是一个完全独立的应用程
序。你希望是前者,因为这样监控就会和应用程序一起发布了,否则,就破坏了这种模式
的意义。
在使用这种模式时,我发现了一件很容易忽略的重要事情:使用适当的
HTTP
返回码。如果
一切正常,就返回
HTTP 200
。如果情况不太好,则返回除
HTTP 200
以外的内容(这里使用
的
HTTP 503 Service Unavailable
就是一个很好的选择)。使用正确的
HTTP
响应码可以很
容易地确定一切正常,而不必解析返回的任何文本。
说到返回文本,根据使用此模式的目的,在响应中返回一些数据可能很有用。我非常喜欢
返回
JSON
格式的数据。你可以随意使用任何其他结构化格式,但我不推荐使用非结构化
格式,因为它们更难被机器解析。如果端点实现相对简单,那么你实际上不需要返回数
据,只需返回一个
HTTP
码并调用它即可。
安全怎么办
?
我听过有人出于安全考虑反对这种模式。毕竟,你不希望用户能够访问这个
端点。通常可以通过在
Web
服务器上使用访问限制,并只允许某些源地址访
问该端点,以及将所有其他地址重新定向到其他地方来解决这个问题。
这种模式也有缺点。最大的问题是,相较于使用一个简单的基于指标的方法(即基于推
送),实现它需要更多的工程工作。你还需要能够一致地检查端点的工具。如果你处于基
于指标的环境中,那么可能没有这种可用的基础设施。
这就是
/health
端点模式。我很喜欢这个模式,但是它也有挑战和障碍。在我看来,即使不
在微服务环境中,这个模式也仍然很有用,因为它能够轻松地对应用程序进行一个完整的 ...
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

Java数据科学实战

Java数据科学实战

Michael R. Brzustowicz, PhD
可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115550750