ติดตั้งและลอง プロメテウスサーバを起動する


วันนี้ลองทำตาม 書類ของ プロメテウスกันต่อ ที่หัวข้อ First steps with Prometheus
ผมก็เลือกติดตั้งแบบที่ใน 書類บอกเลยคือโหลด タール.GZของผมใช้บน MacOSก็เป็นไฟล์ prometheus-2.24.1.darwin-amd64.tar.gzพอแตกออกมาในนั้นเราก็จะเห็นไฟล์เหล่านี้
$ ls -l
-rw-r--r--@ 1 john  staff     11357 Jan 20 09:08 LICENSE
-rw-r--r--@ 1 john  staff      3420 Jan 20 09:08 NOTICE
drwxr-xr-x@ 4 john  staff       128 Jan 20 09:08 console_libraries
drwxr-xr-x@ 9 john  staff       288 Jan 20 09:08 consoles
drwxr-xr-x  6 john  staff       192 Jan 28 07:21 data
-rwxr-xr-x@ 1 john  staff  89422064 Jan 20 07:20 prometheus
-rw-r--r--@ 1 john  staff       926 Jan 20 09:08 prometheus.yml
-rwxr-xr-x@ 1 john  staff  79455632 Jan 20 07:22 promtool
ตัวที่เป็นโปรแกรมที่ให้มาก็คือ prometheusกับ promtoolการจะรัน サーバขึ้นมาต้องกำหนดไฟล์ 設定ให้ด้วยซึ่งก็จะเห็นไฟล์ 設定มีมาให้แล้วคือ prometheus.ymlสิ่งที่อยู่ในไฟล์ 設定ที่ให้มาเป็นแบบนี้
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
ที่เข้าใจจากที่อ่านมาคือ scrape_intervalไว้กำหนดความถี่ว่าให้ プロメテウスเรียกไปอ่าน 計量จาก ターゲットถี่แค่ไหน ซึ่งตอนนี้กำหนดไว้ทุกๆ 15วินาที
ส่วนตรง ScreenCoreの設定ให้เรากำหนด ターゲットที่จะไปดึงค่า 計量ตอนนี้คือกำหนดให้ไปเรียกที่ตัว プロメテウスサーバーเองนั่นแหละ (คือตัว サーバมันเองก็พ่น 計量ออกเหมือนกัน) ที่ エンドポイントคือ localhost:9090ลองสั่ง スタートサーバーด้วยวิธีนี้
$ ./prometheus --config.file=prometheus.yml
...
level=info ts=2021-01-28T00:35:44.150Z caller=main.go:710 msg="Server is ready to receive web requests."
สุดท้ายเมื่อเห็น ログว่า サーバพร้อมแล้วก็ลองเปิด ブラウザเข้าไปที่ http://localhost:9090จะเจอหน้าเว็บแบบนี้

สำหรับตอนนี้ ターゲットคือตัวมันเอง ดังนั้นถ้าเราเข้าที่ http://localhost:9090/metricsจะเห็น テキストที่เป็น 計量ของตัวมันเองที่จะถูกมาอ่านทุกๆ 15วินาทีแบบนี้

จากนั้นสิ่งที่เราทำได้คือใส่ 表現คือดึงข้อมูล 計量มาโชว์นั่นเอง ผมยังไม่เข้าใจเรื่อง 表現ที่ใช้ แต่ก็ลองใส่ตาม ドキュメントファーストステップดู 4แบบจะแสดงข้อมูลและกราฟแบบนี้


ตอนต่อๆไปค่อยมาดูเรื่องวิธีการรวบรวม 計量กับการใช้ promqlในการ クエリข้อมูลกันอีกที