DEV Community

Cover image for NGINX Monitoring with Grafana
terngr
terngr

Posted on

1

NGINX Monitoring with Grafana

ความเดิมจากตอนที่แล้ว NGINX Monitoring with Prometheus เราได้ติดตั้งและ Configure ให้ NGINX ทำ Expose metrics ผ่าน Prometheus โดยใช้ Prometheus Exporter

ในตอนนี้ เราจะติดตั้ง Grafana และนำ Prometheus Datasource มาแสดงผลใน Dashboard ครับ

sudo docker run -d -p 3000:3000 grafana/grafana

จากนั้น Log in เข้า Grafana ที่ http://ip:3000
Image description

กดรูปเฟืองเกียร์ด้านซ้ายมือ เลือก Data sources, Add data sources
Image description

ใส่ชื่อ และระบุ URL ของ Prometheus ที่ได้ทำการติดตั้ังไว้แล้ว
Image description

เลือก Save & test จะได้ข้อความ Data source is working
Image description

สร้าง Dashboard โดยเลือกที่ Dashboards, +New dashboard
Image description

Add a new panel
Image description

ที่ Panel title, เลือก Edit
Image description

ใต้ Tab Query, ช่อง Metric browser, พิมพ์ nginx จะแสดง metrics ที่สามารถนำมาแสดงผลได้, ในตัวอย่างจะเป็น metrics จาก NGINX Plus, หากมีการใช้งานกับ NGINX OSS จะเห็น Metrics จาก NGINX OSS โดยจะมีน้อยกว่า Metric จาก NGINX Plus
Image description

กดปุ่ม Apply
สามารถทดลองเรียกใช้งานไปที่ NGINX Instance เพื่อให้เห็นค่าที่เปลี่ยนแปลงใน Dashboard
Image description

ใน Prometheus จะมี label คือ job และ instance ใช้ระบุที่มาของแต่ละ Metrics ได้

สามารถระบุชื่อ job และ instance ได้ที่เครื่อง prometheus
ในตัวอย่าง ระบุ
job_name: 'NGINX-Plus'
instance: 'NGINX-Plus-1' และ 'NGINX-Plus-2'
สามารถทำได้ทั้ง NGINX Plus และ NGINX OSS และเพิ่ม Label อื่นๆ ได้

global:
  scrape_interval: 5s

  external_labels:
    monitor: 'NGINX-Plus'

scrape_configs:
  - job_name: 'NGINX-Plus'
    static_configs:
      - targets: ['10.4.117.203:9113']
        labels:
          instance: 'NGINX-Plus-1'
      - targets: ['10.4.117.204:9113']
        labels:
          instance: 'NGINX-Plus-2'
Enter fullscreen mode Exit fullscreen mode

จาก Dashboard เป็นการแสดงจำนวน Connection ทั้งหมดที่เกิดขึ้น, และหากทำการ restart NGINX ก็จะเริ่มนับจาก 0 ใหม่ ฉะนั้นเราสามารถดู อัตราของจำนวน connection ในแต่ละช่วงเวลาได้ โดยใช้ function irate กำหนดช่วงเวลา 5m

irate(nginxplus_connections_accepted[5m])

จะได้จำนวน Connection ที่ Accepted
Image description

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up