m
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
# Parses JSON access logs from NGINX fronting a Docker Registry.
|
# Parses JSON access logs from NGINX fronting a Docker Registry.
|
||||||
# Emits Prometheus counters for pull/push bytes and seconds, plus request counts.
|
# Emits Prometheus counters for pull/push bytes and seconds, plus request counts.
|
||||||
|
|
||||||
# -------- Metrics
|
# -------- Metrics (labels are space-separated, no commas)
|
||||||
counter registry_requests_total by method, path_class, status, repo, user, node
|
counter registry_requests_total by method path_class status repo user node
|
||||||
counter registry_pull_blob_bytes_total by repo, user, node
|
counter registry_pull_blob_bytes_total by repo user node
|
||||||
counter registry_pull_blob_seconds_total by repo, user, node
|
counter registry_pull_blob_seconds_total by repo user node
|
||||||
counter registry_push_upload_bytes_total by repo, user, node
|
counter registry_push_upload_bytes_total by repo user node
|
||||||
counter registry_push_upload_seconds_total by repo, user, node
|
counter registry_push_upload_seconds_total by repo user node
|
||||||
|
|
||||||
# -------- Field extraction (order-independent)
|
# -------- Field extraction (order-independent)
|
||||||
/"method":"([A-Z]+)"/ {
|
/"method":"([A-Z]+)"/ {
|
||||||
@@ -23,6 +23,7 @@ counter registry_push_upload_seconds_total by repo, user, node
|
|||||||
}
|
}
|
||||||
/"status":([0-9]{3})/ {
|
/"status":([0-9]{3})/ {
|
||||||
status = $1
|
status = $1
|
||||||
|
status_s = sprintf("%d", status) # use string label later
|
||||||
}
|
}
|
||||||
/"request_time":([0-9.]+)/ {
|
/"request_time":([0-9.]+)/ {
|
||||||
request_time = $1
|
request_time = $1
|
||||||
@@ -45,12 +46,11 @@ counter registry_push_upload_seconds_total by repo, user, node
|
|||||||
repo = $1
|
repo = $1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Defaults per line (and explicit init)
|
# Defaults per line
|
||||||
/$/ {
|
/$/ {
|
||||||
if repo == "" { repo = "unknown" }
|
if repo == "" { repo = "unknown" }
|
||||||
if user == "" { user = "anonymous" }
|
if user == "" { user = "anonymous" }
|
||||||
if node == "" { node = "unknown" }
|
if node == "" { node = "unknown" }
|
||||||
if uploaded_bytes == 0 { uploaded_bytes = 0 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Helper: parse upstream_range "a-b" => bytes = b+1
|
# Helper: parse upstream_range "a-b" => bytes = b+1
|
||||||
@@ -62,40 +62,40 @@ counter registry_push_upload_seconds_total by repo, user, node
|
|||||||
|
|
||||||
# Downloaded blob bytes/time: GET /v2/<repo>/blobs/sha256:...
|
# Downloaded blob bytes/time: GET /v2/<repo>/blobs/sha256:...
|
||||||
/"method":"GET".*"\/v2\/.+\/blobs\/sha256:[a-f0-9]+"/ {
|
/"method":"GET".*"\/v2\/.+\/blobs\/sha256:[a-f0-9]+"/ {
|
||||||
registry_pull_blob_bytes_total[repo=repo, user=user, node=node] += body_bytes_sent
|
registry_pull_blob_bytes_total[repo=repo user=user node=node] += body_bytes_sent
|
||||||
registry_pull_blob_seconds_total[repo=repo, user=user, node=node] += request_time
|
registry_pull_blob_seconds_total[repo=repo user=user node=node] += request_time
|
||||||
registry_requests_total[method=method, path_class="pull_blob", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="pull_blob" status=status_s repo=repo user=user node=node]++
|
||||||
}
|
}
|
||||||
|
|
||||||
# Upload data transfer: PATCH /v2/<repo>/blobs/uploads/<uuid> 202
|
# Upload data transfer: PATCH /v2/<repo>/blobs/uploads/<uuid> 202
|
||||||
/"method":"PATCH".*"\/v2\/.+\/blobs\/uploads\/[a-f0-9-]+"/ {
|
/"method":"PATCH".*"\/v2\/.+\/blobs\/uploads\/[a-f0-9-]+"/ {
|
||||||
if uploaded_bytes > 0 {
|
if uploaded_bytes > 0 {
|
||||||
registry_push_upload_bytes_total[repo=repo, user=user, node=node] += uploaded_bytes
|
registry_push_upload_bytes_total[repo=repo user=user node=node] += uploaded_bytes
|
||||||
}
|
}
|
||||||
registry_push_upload_seconds_total[repo=repo, user=user, node=node] += request_time
|
registry_push_upload_seconds_total[repo=repo user=user node=node] += request_time
|
||||||
registry_requests_total[method=method, path_class="push_upload", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="push_upload" status=status_s repo=repo user=user node=node]++
|
||||||
uploaded_bytes = 0
|
uploaded_bytes = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Upload session start/end (bookkeeping)
|
# Upload session start/end (bookkeeping)
|
||||||
/"method":"POST".*"\/v2\/.+\/blobs\/uploads\/"/ {
|
/"method":"POST".*"\/v2\/.+\/blobs\/uploads\/"/ {
|
||||||
registry_requests_total[method=method, path_class="push_start", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="push_start" status=status_s repo=repo user=user node=node]++
|
||||||
}
|
}
|
||||||
/"method":"PUT".*"\/v2\/.+\/blobs\/uploads\/[a-f0-9-]+"/ {
|
/"method":"PUT".*"\/v2\/.+\/blobs\/uploads\/[a-f0-9-]+"/ {
|
||||||
registry_requests_total[method=method, path_class="push_commit", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="push_commit" status=status_s repo=repo user=user node=node]++
|
||||||
}
|
}
|
||||||
|
|
||||||
# Manifest pulls
|
# Manifest pulls
|
||||||
/"method":"GET".*"\/v2\/.+\/manifests\/[^"]+"/ {
|
/"method":"GET".*"\/v2\/.+\/manifests\/[^"]+"/ {
|
||||||
registry_requests_total[method=method, path_class="pull_manifest", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="pull_manifest" status=status_s repo=repo user=user node=node]++
|
||||||
}
|
}
|
||||||
|
|
||||||
# Manifest writes
|
# Manifest writes
|
||||||
/"method":"PUT".*"\/v2\/.+\/manifests\/[^"]+"/ {
|
/"method":"PUT".*"\/v2\/.+\/manifests\/[^"]+"/ {
|
||||||
registry_requests_total[method=method, path_class="push_manifest", status=string(status), repo=repo, user=user, node=node]++
|
registry_requests_total[method=method path_class="push_manifest" status=status_s repo=repo user=user node=node]++
|
||||||
}
|
}
|
||||||
|
|
||||||
# Root auth probe
|
# Root auth probe
|
||||||
/"path":"\/v2\/"/ {
|
/"path":"\/v2\/"/ {
|
||||||
registry_requests_total[method=method, path_class="v2_root", status=string(status), repo="none", user=user, node=node]++
|
registry_requests_total[method=method path_class="v2_root" status=status_s repo="none" user=user node=node]++
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user