Skip to content

Commit e421e52

Browse files
authored
add separate cvmfs_repo_version and cvmfs_repo_revision metrics (#9)
1 parent ab7874c commit e421e52

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

cvmfs-client-prometheus.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,32 @@ ${metric_name}{${metric_labels}} ${metric_value}
5454
EOF
5555
}
5656

57+
convert_version_to_numeric() {
58+
local version="$1"
59+
# Convert version string like "2.13.2.0" to numeric value
60+
# Format: major * 10000 + minor * 100 + patch
61+
# Example: 2.13.2 becomes 21302
62+
# Ignore the build number (last field)
63+
64+
# Remove any non-numeric characters except dots
65+
local clean_version
66+
clean_version=$(echo "$version" | sed 's/[^0-9.]//g')
67+
68+
# Split version into components
69+
IFS='.' read -ra version_parts <<< "$clean_version"
70+
71+
local major=${version_parts[0]:-0}
72+
local minor=${version_parts[1]:-0}
73+
local patch=${version_parts[2]:-0}
74+
# Ignore build number (version_parts[3])
75+
76+
# Calculate numeric value: major * 10000 + minor * 100 + patch
77+
local numeric_version
78+
numeric_version=$((major * 10000 + minor * 100 + patch))
79+
80+
echo "$numeric_version"
81+
}
82+
5783
list_mounted_cvmfs_repos() {
5884
cvmfs_config status | tr -s '[:space:]' | cut -d ' ' -f 1 | sort -u
5985
}
@@ -173,6 +199,13 @@ get_cvmfs_repo_metrics() {
173199
cvmfs_mount_revision=$(attr -g revision "${repomountpoint}" | tail -n +2)
174200
generate_metric 'cvmfs_repo' 'gauge' 'Shows the version of CVMFS used by this repository.' "repo=\"${fqrn}\",mountpoint=\"${repomountpoint}\",version=\"${cvmfs_mount_version}\",revision=\"${cvmfs_mount_revision}\"" 1
175201

202+
# Generate numeric version and revision metrics
203+
local cvmfs_numeric_version
204+
cvmfs_numeric_version=$(convert_version_to_numeric "${cvmfs_mount_version}")
205+
generate_metric 'cvmfs_repo_version' 'gauge' 'CVMFS repository version as a numeric value for easier querying.' "repo=\"${fqrn}\"" "${cvmfs_numeric_version}"
206+
207+
generate_metric 'cvmfs_repo_revision' 'gauge' 'CVMFS repository revision number.' "repo=\"${fqrn}\"" "${cvmfs_mount_revision}"
208+
176209
local cvmfs_mount_rx_kb
177210
cvmfs_mount_rx_kb=$(attr -g rx "${repomountpoint}" | tail -n +2)
178211
local cvmfs_mount_rx
@@ -272,6 +305,31 @@ get_cvmfs_repo_metrics_new() {
272305
maxfd_value=$(attr -g maxfd "${repomountpoint}" | tail -n +2)
273306
generate_metric 'cvmfs_maxfd' 'gauge' 'Shows the maximum number of file descriptors available to file system clients.' "repo=\"${reponame}\"" "${maxfd_value}"
274307

308+
# Extract version and revision from the cvmfs_repo metric in TMPFILE and generate numeric metrics
309+
local cvmfs_repo_line
310+
cvmfs_repo_line=$(grep "cvmfs_repo{repo=\"${reponame}\"" "${TMPFILE}" | tail -n 1)
311+
312+
if [[ -n "${cvmfs_repo_line}" ]]; then
313+
# Extract version from the metric line using regex
314+
local cvmfs_mount_version
315+
cvmfs_mount_version=$(echo "${cvmfs_repo_line}" | sed -n 's/.*version="\([^"]*\)".*/\1/p')
316+
317+
# Extract revision from the metric line using regex
318+
local cvmfs_mount_revision
319+
cvmfs_mount_revision=$(echo "${cvmfs_repo_line}" | sed -n 's/.*revision="\([^"]*\)".*/\1/p')
320+
321+
# Generate numeric version and revision metrics
322+
if [[ -n "${cvmfs_mount_version}" ]]; then
323+
local cvmfs_numeric_version
324+
cvmfs_numeric_version=$(convert_version_to_numeric "${cvmfs_mount_version}")
325+
generate_metric 'cvmfs_repo_version' 'gauge' 'CVMFS repository version as a numeric value for easier querying.' "repo=\"${reponame}\"" "${cvmfs_numeric_version}"
326+
fi
327+
328+
if [[ -n "${cvmfs_mount_revision}" ]]; then
329+
generate_metric 'cvmfs_repo_revision' 'gauge' 'CVMFS repository revision number.' "repo=\"${reponame}\"" "${cvmfs_mount_revision}"
330+
fi
331+
fi
332+
275333
# Extract PID from the metrics output and add memory usage metric
276334
local repo_pid
277335
repo_pid=$(grep "cvmfs_pid{repo=\"${reponame}\"}" "${TMPFILE}" | tail -n 1 | awk '{print $2}')

0 commit comments

Comments
 (0)