Add pv_name/request_name label split to metrics
Extract real PV name (pvc-UUID) from directory name using regex. Metrics now expose pv_name (actual PV) and request_name (full dir). Bump image to v1.1.0, chart to 1.2.0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0d47a9c357
commit
4f635718f5
18
app.py
18
app.py
|
|
@ -3,12 +3,19 @@ from prometheus_client import Gauge, generate_latest, CONTENT_TYPE_LATEST
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
pv_usage_bytes = Gauge('nfs_pv_usage_bytes', 'PV usage in bytes', ['pv_name'])
|
pv_usage_bytes = Gauge('nfs_pv_usage_bytes', 'PV usage in bytes', ['pv_name', 'request_name'])
|
||||||
pv_last_check = Gauge('nfs_pv_last_check_timestamp', 'Last check timestamp', ['pv_name'])
|
pv_last_check = Gauge('nfs_pv_last_check_timestamp', 'Last check timestamp', ['pv_name', 'request_name'])
|
||||||
|
|
||||||
|
PVC_UUID_RE = re.compile(r'(pvc-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$')
|
||||||
|
|
||||||
|
def extract_pv_name(dir_name):
|
||||||
|
m = PVC_UUID_RE.search(dir_name)
|
||||||
|
return m.group(1) if m else dir_name
|
||||||
|
|
||||||
cache = {}
|
cache = {}
|
||||||
CACHE_TTL = 300
|
CACHE_TTL = 300
|
||||||
|
|
@ -40,9 +47,10 @@ def get_pv_usage(pv_name):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
usage = int(result.stdout.split()[0])
|
usage = int(result.stdout.split()[0])
|
||||||
|
real_pv = extract_pv_name(pv_name)
|
||||||
cache[pv_name] = {'bytes': usage, 'time': time.time()}
|
cache[pv_name] = {'bytes': usage, 'time': time.time()}
|
||||||
pv_usage_bytes.labels(pv_name=pv_name).set(usage)
|
pv_usage_bytes.labels(pv_name=real_pv, request_name=pv_name).set(usage)
|
||||||
pv_last_check.labels(pv_name=pv_name).set(time.time())
|
pv_last_check.labels(pv_name=real_pv, request_name=pv_name).set(time.time())
|
||||||
|
|
||||||
return usage
|
return usage
|
||||||
|
|
||||||
|
|
@ -51,7 +59,7 @@ def usage(pv_name):
|
||||||
result = get_pv_usage(pv_name)
|
result = get_pv_usage(pv_name)
|
||||||
if result is None:
|
if result is None:
|
||||||
return {'error': 'PV not found or timeout'}, 404
|
return {'error': 'PV not found or timeout'}, 404
|
||||||
return {'pv_name': pv_name, 'bytes': result}
|
return {'pv_name': extract_pv_name(pv_name), 'request_name': pv_name, 'bytes': result}
|
||||||
|
|
||||||
@app.route('/metrics')
|
@app.route('/metrics')
|
||||||
def metrics():
|
def metrics():
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@ apiVersion: v2
|
||||||
name: nfs-usage-exporter
|
name: nfs-usage-exporter
|
||||||
description: NFS PV usage metrics exporter for Prometheus
|
description: NFS PV usage metrics exporter for Prometheus
|
||||||
type: application
|
type: application
|
||||||
version: 1.1.0
|
version: 1.2.0
|
||||||
appVersion: "1.0.0"
|
appVersion: "1.0.0"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ replicaCount: 1
|
||||||
|
|
||||||
image:
|
image:
|
||||||
repository: harbor.inje-private.com/infra/nfs-usage-exporter
|
repository: harbor.inje-private.com/infra/nfs-usage-exporter
|
||||||
tag: "v1.0.0"
|
tag: "v1.1.0"
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
|
|
||||||
service:
|
service:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue