DEV Community

Weerasak Chongnguluam
Weerasak Chongnguluam

Posted on

27

Prometheus คืออะไร

ตอนนี้กำลังหัดใช้ Prometheus อยู่ ก็เดี๋ยวจะบันทึกสิ่งที่ได้เรียนรู้ไปด้วย ซึ่งตอนนี้ก็อ่านจากเว็บทางการของ Prometheus เองคือลิ้งนี้ https://prometheus.io/docs/introduction/overview/

สำหรับวันนี้อ่านตรง Overview ซึ่งเล่าให้เราฟังก่อนว่า Prometheus นั้นคืออะไร

Prometheus คือระบบ monitoring และ alerting tookit ที่เริ่มพัฒนาโดยบริษัท SoundCloud ก่อน ซึ่งเขาก็ได้ opensource ตัวโปรเจ็คนี้ทำให้บริษัทอื่นๆก็ได้เอาไปประยุกต์ใช้งานด้วย ปัจจุบันตัวโปรเจ็คเองก็เป็นโครงการที่แยกตัวจาก SoundCloud ไม่ได้ขึ้นกับบริษัทใดๆโดยตรง

Features

ความสามารถหลักของ Prometheus ที่ทำได้คือ

  • เก็บข้อมูลในลักษณะ multi-dimensional ได้โดยจัดเก็บเป็น time series คือเรียกตามลำดับเวลาซึ่งแต่ละค่าที่ไหลเข้ามาก็จะเป็นแบบ key/value โดยคีย์คือ metric name นั่นเอง
  • มีภาษาในการ query ข้อมูลของตัวเองชื่อ PromQL เพื่อ query ข้อมูล, aggregate ข้อมูลของ metric ที่เก็บไว้นั่นเอง
  • storage ไม่จำเป็นต้องเป็นแบบ distributed แต่ละ server nodes ทำงานและเก็บข้อมูลได้ในตัวเอง
  • การเก็บข้อมูลนั้นใช้ pull model over HTTP คือตัว Prometheus เองจะไปดึงข้อมูลจากเป้าหมายที่ต้องการรวบรวมเอง ไม่ต้องให้เป้าหมายส่งมาให้ Prometheus
  • Prometheus จะหาเครื่องเป้าหมายผ่านทางระบบ service discovery หรือใช้วิธี config เองก็ได้
  • รองรับระบบ graph และ dashboard หลายๆแบบ

Alt Text

Components

architecture ของ Prometheus นั้นประกอบไปด้วย

  • Prometheus server ซึ่งจะทำหน้าที่ไปดึงข้อมูลแล้วก็เก็บข้อมูล time series
  • client libraries เป็น library ที่ช่วยให้ฝั่ง client เตรียมข้อมูลให้อยู่ในรูปแบบที่ Prometheus จะดึงมาเก็บได้
  • push gateway ในบางงานที่ทำงานใช้งานสั้นๆแล้วปิดตัวเองลงไป คงไม่เหมาะที่จะให้ไป pull ดังนั้นจึงมี push gateway เพื่อให้งานสั้นๆพวกนี้ส่งข้อมูลมาเก็บไว้ที่ gateway ก่อนแล้วค่อยให้ Prometheus มา pull ไปอีกที
  • exporters เป็นโปรแกรมที่จะช่วยแปลงข้อมูลของระบบอื่นๆที่มีอยู่แล้วให้มาอยู่ในรูปแบบของ metrics ที่ Prometheus เข้าใจได้ เช่น exporters ที่จะแปลงข้อมูลจากโปรแกรมพวก web server หรือ database ต่างๆ
  • alertmanager เอาไว้ push alerts ไปหาระบบอื่นๆเช่น ส่ง email ส่ง messaging เป็นต้น
  • Data visualization and export คือโปแกรมส่วนที่เป็น UI ที่มาดึงข้อมูลจาก Prometheus ไปแสดงผล ไม่ว่าจะเป็น Prometheus web UI เองหรือ Grafana เป็นต้น

When does it fit?

  • Prometheus ทำงานได้ดีกับข้อมูลที่เป็นตัวเองตามลำดับเวลา (purely numeric time series)
  • ทำงานได้ดีกับทั้งการ monitor การทำงานของเครื่องเป็นหลัก หรือของ service เป็นหลัก
  • ออกแบบให้ reliability แต่ละ node ของ Prometheus เป็นแบบ standalone ไม่จำเป็นต้องพึ่งพา network storage หรือ remote service อื่นๆในการทำงาน

When does it not fit?

สิ่งที่ Prometheus ไม่เหมาะคือถ้าเราต้องการวัดข้อมูลทาง statistics แบบถูกต้อง 100% เช่นจะวัด per-request billing เพราะมันไม่ได้ถูกออกแบบมาให้เก็บข้อมูลรายละเอียดได้สมบูรณ์ 100% ขนาดนั้น แบบนั้นควรใช้เครื่องมือสำหรับรวบรวมและวิเคราะห์ข้อมูลโดยตรงดีกว่า ถ้าเป็นเรื่อง monitoring ค่อยยกให้เป็นหน้าที่ Prometheus

คร่าวๆประมาณนี้ครับสำหรับวันนี้ที่อ่านได้ อาจจะสรุปตกหล่นไปบ้างคงต้องไปอ่านเก็บรายละเอียดกันต่อเองที่เว็บของ Prometheus ครับ

Buy Me A Coffee

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay