KJH
Prometheus Client 본문
node exporter와 같은 서비스를 직접 만들 수 있는 SDK이고,
python, go 둘 다 지원을 하며 문서도 잘 되어있고 매우 간단하게 사용할 수 있다
https://github.com/prometheus/client_python
GitHub - prometheus/client_python: Prometheus instrumentation library for Python applications
Prometheus instrumentation library for Python applications - prometheus/client_python
github.com
https://prometheus.github.io/client_python/
client_python
client_pythonThis is the documentation for the Prometheus Python client library.
prometheus.github.io
특정 큐 컨슈머 숫자를 dashboard에서 보기 위해서 아래 처럼 응용을 할 수 있는데
Gauge를 추가할 때마다 /metrics에 데이터가 하나씩 추가되는 구조이고, 첫번째 파라미터로 쿼리를 할 수 있음
import os
import time
import requests
from prometheus_client import start_http_server, Gauge
queue_name = os.getenv('QUEUE_NAME', '***')
sleep_time = int(os.getenv('SLEEP_TIME', 10))
api_url = f"http://rabbitmq.***.com:15672/api/queues/%2F/{queue_name}"
credentials = ('***', '***')
# Prometheus gauge 설정
g = Gauge('rabbitmq_consumer_count', 'Number of consumers for the RabbitMQ queue')
def fetch_consumer_count():
response = requests.get(api_url, auth=credentials)
if response.status_code == 200:
queue_info = response.json()
consumer_count = queue_info['consumers']
g.set(consumer_count)
print(f"Consumer count: {consumer_count}")
else:
print(f"Failed to fetch queue information. Status code: {response.status_code}, Response: {response.text}")
if __name__ == '__main__':
start_http_server(8000)
while True:
fetch_consumer_count()
time.sleep(sleep_time)
prometheus 차트에 exporter 추가
prometheus:
prometheusSpec:
additionalScrapeConfigs:
- job_name: 'rabbitmq'
static_configs:
- targets: ['consumer-count-service.default.svc.cluster.local:8000']
완료
'DevOps' 카테고리의 다른 글
Jenkins Chain Job, Artifact (0) | 2024.09.08 |
---|---|
Jenkins Shared Library (w/ kaniko) (0) | 2024.09.08 |
Fortigate (0) | 2024.04.29 |
Thanos (0) | 2024.04.13 |
Prometheus Loki (0) | 2023.12.26 |