Skip to Content
Prometheus: Up & Running, 2nd Edition
book

Prometheus: Up & Running, 2nd Edition

by Julien Pivotto, Brian Brazil
May 2025
Beginner to intermediate
418 pages
6h 18m
Korean
O'Reilly Media, Inc.
Content preview from Prometheus: Up & Running, 2nd Edition

3장. 계측

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

Prometheus를 통해 얻을 수 있는 가장 큰 혜택은 직접 계 측과 클라이언트 라이브러리를 사용하여 자체 애플리케이션을 계측하는 것입니다. 클라이언트 라이브러리는 다양한 언어로 제공되며, 공식 클라이언트 라이브러리는 Go, Python, Java, Rust 및 Ruby로 제공됩니다.

여기서는 Python 3을 예로 사용했지만 구문과 유틸리티 방법은 다르지만 다른 언어와 런타임에도 동일한 일반 원칙이 적용됩니다.

대부분의 최신 OS에는 Python 3이 함께 제공됩니다. 아직 설치되어 있지 않다면 Python 3을 다운로드하여 설치하세요.

또한 최신 Python 클라이언트 라이브러리를 설치해야 합니다. 이 작업은 pip install prometheus_client. 계측 예제는 GitHub에서 찾을 수 있습니다.

간단한 프로그램

먼저예제 3-1에 표시된 간단한 HTTP 서버를 작성했습니다. Python 3으로 실행한 다음 브라우저에서http://localhost:8001/ 을 방문하면 Hello World 응답이 표시됩니다.

예 3-1. Prometheus 메트릭도 노출하는 간단한 Hello World 프로그램
import http.server
from prometheus_client import start_http_server

class MyHandler(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b"Hello World")

if __name__ == "__main__":
    start_http_server(8000)
    server = http.server.HTTPServer(('localhost', 8001), MyHandler)
    server.serve_forever()

start_http_server(8000) 은 포트 8000에서 HTTP 서버를 시작하여 Prometheus에 메트릭을 제공합니다. 이러한 메트릭은 그림 3-1과 같이 http://localhost:8000/ 에서 볼 수 있습니다. 기본적으로 반환되는 메트릭은 플랫폼에 따라 다르며, Linux 플랫폼에 가장 많은 메트릭이 있는 경향이 있습니다.

A basic /metrics for Python.
그림 3-1. 간단한 프로그램이 Linux에서 CPython으로 실행되는 경우의 /metrics 페이지

metrics 페이지를 수동으로 검토할 수도 있지만, 실제로 원하는 것은 메트릭을 Prometheus로 가져오는 것입니다. 이렇게 하려면 예제 3-2의 구성으로 Prometheus를 설정하고 실행하세요.

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

Prometheus: Up & Running, 2nd Edition

Prometheus: Up & Running, 2nd Edition

Julien Pivotto, Brian Brazil
Mastering Prometheus

Mastering Prometheus

William Hegedus
Argo CD: Up and Running

Argo CD: Up and Running

Andrew Block, Christian Hernandez
Kubernetes: Up and Running, 3rd Edition

Kubernetes: Up and Running, 3rd Edition

Brendan Burns, Joe Beda, Kelsey Hightower, Lachlan Evenson

Publisher Resources

ISBN: 9798341654181