diff --git a/.BENCHMARKING b/.BENCHMARKING new file mode 100644 index 0000000..acab24d --- /dev/null +++ b/.BENCHMARKING @@ -0,0 +1,6 @@ ++exec 3>&2 2> >(tee /tmp/sample-time.$$.log | ++ sed -u 's/^.*$/now/' | ++ date -f - +%s.%N >/tmp/sample-time.$$.tim) ++set -x ++ + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bd29a3f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,308 @@ +name: CI - Test prometheus-cvmfs-exporter + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + +jobs: + test-debian-ubuntu: + name: Test DEB Package on Ubuntu + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup CernVM-FS + uses: cvmfs-contrib/github-action-cvmfs@v4 + with: + cvmfs_repositories: 'sft.cern.ch,sw.hsf.org' + cvmfs_http_proxy: 'DIRECT' + + - name: Verify CVMFS is working + run: | + echo "Testing CVMFS access..." + ls -la /cvmfs/ + timeout 30 ls /cvmfs/sft.cern.ch/ || echo "CVMFS access test completed" + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + debhelper \ + devscripts \ + dpkg-dev \ + systemd \ + curl \ + attr \ + bc + + - name: Build DEB package + run: | + echo "Building DEB package..." + make clean + make deb + + - name: Verify DEB package contents + run: | + echo "Checking DEB package contents..." + dpkg -c build/prometheus-cvmfs-exporter_*.deb + dpkg -I build/prometheus-cvmfs-exporter_*.deb + + - name: Install DEB package + run: | + echo "Installing DEB package..." + sudo dpkg -i build/prometheus-cvmfs-exporter_*.deb || true + sudo apt-get install -f -y + + - name: Verify installation + run: | + echo "Verifying installation..." + ls -la /usr/libexec/cvmfs/cvmfs-prometheus.sh + ls -la /usr/lib/systemd/system/cvmfs-client-prometheus* + + - name: Test script functionality + run: | + echo "Testing script functionality..." + # Test script help + /usr/libexec/cvmfs/cvmfs-prometheus.sh --help || true + + # Test script execution (may fail without proper CVMFS setup, but should not crash) + timeout 10 /usr/libexec/cvmfs/cvmfs-prometheus.sh || echo "Script execution test completed" + + - name: Start systemd services + run: | + echo "Starting systemd services..." + sudo systemctl daemon-reload + sudo systemctl enable cvmfs-client-prometheus.socket + sudo systemctl start cvmfs-client-prometheus.socket + sudo systemctl status cvmfs-client-prometheus.socket --no-pager + + - name: Test metrics endpoint + run: | + echo "Testing metrics endpoint..." + # Wait for socket to be ready + sleep 5 + + # Test the metrics endpoint with timeout and timing + echo "Attempting to connect to localhost:9868..." + start_time=$(date +%s.%N) + + # Use curl with timeout and proper error handling + if timeout 30 curl -f -s http://localhost:9868 > metrics_output.txt; then + end_time=$(date +%s.%N) + response_time=$(echo "$end_time - $start_time" | bc) + echo "✅ Metrics endpoint responded successfully in ${response_time} seconds" + + # Verify Prometheus metrics format + if grep -q "^# HELP" metrics_output.txt && grep -q "^# TYPE" metrics_output.txt; then + echo "✅ Response contains valid Prometheus metrics format" + echo "Sample metrics:" + head -20 metrics_output.txt + else + echo "❌ Response does not contain valid Prometheus metrics" + echo "Response content:" + cat metrics_output.txt + exit 1 + fi + else + echo "❌ Failed to connect to metrics endpoint" + echo "Checking service status..." + sudo systemctl status cvmfs-client-prometheus.socket --no-pager || true + sudo journalctl -u cvmfs-client-prometheus.socket --no-pager -n 20 || true + exit 1 + fi + + - name: Upload DEB package artifact + uses: actions/upload-artifact@v4 + if: always() + with: + name: deb-package + path: build/prometheus-cvmfs-exporter_*.deb + retention-days: 7 + + test-rpm-almalinux: + name: Test RPM Package on AlmaLinux + runs-on: ubuntu-latest + + services: + almalinux: + image: almalinux:9 + options: >- + --privileged + --cgroupns=host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup AlmaLinux container with systemd + run: | + # Create a container with systemd support + docker run -d \ + --name almalinux-test \ + --privileged \ + --cgroupns=host \ + -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ + -v $PWD:/workspace \ + -w /workspace \ + almalinux:9 \ + /usr/sbin/init + + # Wait for container to be ready + sleep 5 + + # Verify container is running + docker ps + + - name: Install dependencies in container + run: | + docker exec almalinux-test bash -c " + # Install EPEL and basic tools + dnf install -y epel-release + dnf update -y + + # Install CVMFS + dnf install -y https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm + dnf install -y cvmfs cvmfs-config-default + + # Install build tools and dependencies + dnf install -y --allowerasing \ + rpm-build \ + make \ + systemd \ + curl \ + attr \ + bc \ + findutils \ + grep \ + coreutils \ + util-linux + " + + - name: Setup CVMFS in container + run: | + docker exec almalinux-test bash -c " + # Configure CVMFS + echo 'CVMFS_REPOSITORIES=sft.cern.ch,sw.hsf.org' > /etc/cvmfs/default.local + echo 'CVMFS_HTTP_PROXY=DIRECT' >> /etc/cvmfs/default.local + echo 'CVMFS_CLIENT_PROFILE=single' >> /etc/cvmfs/default.local + echo 'CVMFS_USE_CDN=yes' >> /etc/cvmfs/default.local + + # Setup CVMFS + cvmfs_config setup + + # Test CVMFS access + timeout 30 ls /cvmfs/sft.cern.ch/ || echo 'CVMFS access test completed' + " + + - name: Build RPM package in container + run: | + docker exec almalinux-test bash -c " + cd /workspace + echo 'Building RPM package...' + make clean + make rpm + " + + - name: Verify RPM package contents + run: | + docker exec almalinux-test bash -c " + cd /workspace + echo 'Checking RPM package contents...' + rpm -qlp build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm + rpm -qip build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm + " + + - name: Install RPM package in container + run: | + docker exec almalinux-test bash -c " + cd /workspace + echo 'Installing RPM package...' + rpm -ivh build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm + " + + - name: Verify installation in container + run: | + docker exec almalinux-test bash -c " + echo 'Verifying installation...' + ls -la /usr/libexec/cvmfs/cvmfs-prometheus.sh + ls -la /usr/lib/systemd/system/cvmfs-client-prometheus* + " + + - name: Test script functionality in container + run: | + docker exec almalinux-test bash -c " + echo 'Testing script functionality...' + # Test script help + /usr/libexec/cvmfs/cvmfs-prometheus.sh --help || true + + # Test script execution (may fail without proper CVMFS setup, but should not crash) + timeout 10 /usr/libexec/cvmfs/cvmfs-prometheus.sh || echo 'Script execution test completed' + " + + - name: Start systemd services in container + run: | + docker exec almalinux-test bash -c " + echo 'Starting systemd services...' + systemctl daemon-reload + systemctl enable cvmfs-client-prometheus.socket + systemctl start cvmfs-client-prometheus.socket + systemctl status cvmfs-client-prometheus.socket --no-pager + " + + - name: Test metrics endpoint in container + run: | + docker exec almalinux-test bash -c " + echo 'Testing metrics endpoint...' + # Wait for socket to be ready + sleep 5 + + # Test the metrics endpoint with timeout and timing + echo 'Attempting to connect to localhost:9868...' + start_time=\$(date +%s.%N) + + # Use curl with timeout and proper error handling + if timeout 30 curl -f -s http://localhost:9868 > metrics_output.txt; then + end_time=\$(date +%s.%N) + response_time=\$(echo \"\$end_time - \$start_time\" | bc) + echo \"✅ Metrics endpoint responded successfully in \${response_time} seconds\" + + # Verify Prometheus metrics format + if grep -q \"^# HELP\" metrics_output.txt && grep -q \"^# TYPE\" metrics_output.txt; then + echo \"✅ Response contains valid Prometheus metrics format\" + echo \"Sample metrics:\" + head -20 metrics_output.txt + else + echo \"❌ Response does not contain valid Prometheus metrics\" + echo \"Response content:\" + cat metrics_output.txt + exit 1 + fi + else + echo \"❌ Failed to connect to metrics endpoint\" + echo \"Checking service status...\" + systemctl status cvmfs-client-prometheus.socket --no-pager || true + journalctl -u cvmfs-client-prometheus.socket --no-pager -n 20 || true + exit 1 + fi + " + + - name: Cleanup container + if: always() + run: | + docker stop almalinux-test || true + docker rm almalinux-test || true + + - name: Upload RPM package artifact + uses: actions/upload-artifact@v4 + if: always() + with: + name: rpm-package + path: build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm + retention-days: 7 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3df2fdc --- /dev/null +++ b/Makefile @@ -0,0 +1,112 @@ +# Makefile for prometheus-cvmfs-exporter +# Package for monitoring CVMFS clients with Prometheus + +# Package information +PACKAGE_NAME = prometheus-cvmfs-exporter +VERSION = 1.0.0 +RELEASE = 1 + +# Installation paths +PREFIX = /usr +BINDIR = $(PREFIX)/bin +LIBEXECDIR = $(PREFIX)/libexec/cvmfs +SYSTEMDDIR = /usr/lib/systemd/system +DOCDIR = $(PREFIX)/share/doc/$(PACKAGE_NAME) + +# Source files +SCRIPT_SRC = cvmfs-client-prometheus.sh +SYSTEMD_SERVICE = systemd/cvmfs-client-prometheus@.service +SYSTEMD_SOCKET = systemd/cvmfs-client-prometheus.socket +LICENSE_FILE = LICENSE + +# Build directory for packaging +BUILDDIR = build +RPMDIR = $(BUILDDIR)/rpm +DEBDIR = $(BUILDDIR)/deb + +# RPM build directories +RPMBUILD_DIRS = BUILD BUILDROOT RPMS SOURCES SPECS SRPMS + +.PHONY: all install uninstall package rpm deb clean help + +all: help + +help: + @echo "Available targets:" + @echo " install - Install the script to $(LIBEXECDIR), and systemd files" + @echo " uninstall - Remove installed files" + @echo " package - Build both RPM and DEB packages" + @echo " rpm - Build RPM package" + @echo " deb - Build DEB package" + @echo " clean - Remove build artifacts" + @echo " help - Show this help message" + @echo "" + @echo "Variables:" + @echo " PREFIX=$(PREFIX)" + @echo " LIBEXECDIR=$(LIBEXECDIR)" + @echo " SYSTEMDDIR=$(SYSTEMDDIR)" + +install: + @echo "Installing $(SCRIPT_SRC) to $(DESTDIR)$(LIBEXECDIR)/" + install -d $(DESTDIR)$(LIBEXECDIR) + install -m 755 $(SCRIPT_SRC) $(DESTDIR)$(LIBEXECDIR)/cvmfs-prometheus.sh + @echo "Installing documentation to $(DESTDIR)$(DOCDIR)/" + install -d $(DESTDIR)$(DOCDIR) + install -m 644 $(LICENSE_FILE) $(DESTDIR)$(DOCDIR)/ +install-systemd: + @echo "Installing systemd files to $(DESTDIR)$(SYSTEMDDIR)/" + install -d $(DESTDIR)$(SYSTEMDDIR) + install -m 644 $(SYSTEMD_SERVICE) $(DESTDIR)$(SYSTEMDDIR)/ + install -m 644 $(SYSTEMD_SOCKET) $(DESTDIR)$(SYSTEMDDIR)/ + +uninstall: + @echo "Removing installed files..." + rm -f $(DESTDIR)$(LIBEXECDIR)/cvmfs-prometheus.sh + rm -f $(DESTDIR)$(SYSTEMDDIR)/cvmfs-client-prometheus@.service + rm -f $(DESTDIR)$(SYSTEMDDIR)/cvmfs-client-prometheus.socket + rm -rf $(DESTDIR)$(DOCDIR) + @echo "Uninstall complete" + +# Package building targets +package: rpm deb + +rpm: $(BUILDDIR)/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-$(RELEASE).noarch.rpm + +$(BUILDDIR)/RPMS/noarch/$(PACKAGE_NAME)-$(VERSION)-$(RELEASE).noarch.rpm: $(PACKAGE_NAME).spec $(SCRIPT_SRC) $(SYSTEMD_SERVICE) $(SYSTEMD_SOCKET) + @echo "Building RPM package..." + mkdir -p $(RPMDIR)/BUILD $(RPMDIR)/BUILDROOT $(RPMDIR)/RPMS $(RPMDIR)/SOURCES $(RPMDIR)/SPECS $(RPMDIR)/SRPMS + cp $(PACKAGE_NAME).spec $(RPMDIR)/SPECS/ + tar -czf $(RPMDIR)/SOURCES/$(PACKAGE_NAME)-$(VERSION).tar.gz \ + --transform 's,^,$(PACKAGE_NAME)-$(VERSION)/,' \ + $(SCRIPT_SRC) $(SYSTEMD_SERVICE) $(SYSTEMD_SOCKET) $(LICENSE_FILE) Makefile + rpmbuild --define "_topdir $(PWD)/$(RPMDIR)" \ + --define "version $(VERSION)" \ + --define "release $(RELEASE)" \ + -ba $(RPMDIR)/SPECS/$(PACKAGE_NAME).spec + +deb: $(BUILDDIR)/$(PACKAGE_NAME)_$(VERSION)-$(RELEASE)_all.deb + +$(BUILDDIR)/$(PACKAGE_NAME)_$(VERSION)-$(RELEASE)_all.deb: debian/control debian/rules debian/install debian/changelog + @echo "Building DEB package..." + mkdir -p $(DEBDIR) + cp -r debian $(DEBDIR)/ + cp -r systemd $(DEBDIR)/ + cp $(SCRIPT_SRC) $(LICENSE_FILE) Makefile $(DEBDIR)/ + cd $(DEBDIR) && dpkg-buildpackage -us -uc -b + if [ -f $(BUILDDIR)/$(PACKAGE_NAME)_$(VERSION)-$(RELEASE)_all.deb ]; then \ + echo "DEB package already in correct location"; \ + else \ + mv $(BUILDDIR)/$(PACKAGE_NAME)_$(VERSION)-$(RELEASE)_all.deb $(BUILDDIR)/; \ + fi + +clean: + @echo "Cleaning build artifacts..." + rm -rf $(BUILDDIR) + @echo "Clean complete" + +# Development targets +check-deps: + @echo "Checking for required build dependencies..." + @which rpmbuild >/dev/null 2>&1 || echo "WARNING: rpmbuild not found (needed for RPM packaging)" + @which dpkg-buildpackage >/dev/null 2>&1 || echo "WARNING: dpkg-buildpackage not found (needed for DEB packaging)" + @which systemctl >/dev/null 2>&1 || echo "WARNING: systemctl not found (systemd not available)" diff --git a/README.md b/README.md new file mode 100644 index 0000000..17765dc --- /dev/null +++ b/README.md @@ -0,0 +1,214 @@ +# Prometheus CVMFS Exporter + +A Prometheus exporter for monitoring CernVM File System (CVMFS) clients. This tool collects comprehensive metrics from CVMFS repositories and exposes them in Prometheus format for monitoring and alerting. + +Other exporters for CVMFS exist - this one was written to have a lightweight package without dependencies (in particular python). If you don't mind python, you could also take a look at https://github.com/guilbaults/cvmfs-exporter. Thanks to Simon Guilbaults for inspiration of this exporter, and having reserved port 9868 for CVMFS! + +## Overview + +The prometheus-cvmfs-exporter provides detailed insights into CVMFS client performance, cache utilization, network activity, and system resource usage. It supports both standalone execution and systemd service deployment with socket activation. + +### Features + +- **Comprehensive Metrics**: Collects 20+ different CVMFS metrics per repository +- **Multi-Repository Support**: Automatically discovers and monitors all mounted CVMFS repositories + +## Installation + +### Package Installation + +**RPM-based systems (RHEL, CentOS, AlmaLinux, Fedora):** +```bash +sudo rpm -ivh prometheus-cvmfs-exporter-1.0.0-1.el9.noarch.rpm +sudo systemctl enable --now cvmfs-client-prometheus.socket +``` + +**DEB-based systems (Debian, Ubuntu):** +```bash +sudo dpkg -i prometheus-cvmfs-exporter_1.0.0-1_all.deb +sudo systemctl enable --now cvmfs-client-prometheus.socket +``` + +### Manual Installation + +```bash +# Install script and systemd files +make install install-systemd + +# Enable and start the service +sudo systemctl daemon-reload +sudo systemctl enable --now cvmfs-client-prometheus.socket +``` + +## Usage + +### Command Line Options + +```bash +/usr/libexec/cvmfs/cvmfs-prometheus.sh [OPTIONS] + +Options: + -h, --help Show help message + --http Add HTTP protocol header to output + --non-standard-mountpoints Use cvmfs_config status instead of findmnt + for repository discovery +``` + +### Usage Examples + +**Direct execution (one-time metrics collection):** +```bash +/usr/libexec/cvmfs/cvmfs-prometheus.sh +``` + +**HTTP server mode (for web scraping):** +```bash +/usr/libexec/cvmfs/cvmfs-prometheus.sh --http +``` + +**Non-standard mountpoints:** +```bash +/usr/libexec/cvmfs/cvmfs-prometheus.sh --non-standard-mountpoints +``` + +### Systemd Service + +The exporter runs as a systemd socket-activated service: + +```bash +# Check service status +sudo systemctl status cvmfs-client-prometheus.socket + +# View service logs +sudo journalctl -u cvmfs-client-prometheus@.service + +# Test metrics endpoint +curl http://localhost:9868 +``` + +## Metrics Summary + +The exporter collects the following categories of metrics: + +### Cache Metrics +- `cvmfs_cached_bytes` - Currently cached data size +- `cvmfs_pinned_bytes` - Pinned cache data size +- `cvmfs_total_cache_size_bytes` - Configured cache limit +- `cvmfs_physical_cache_size_bytes` - Physical cache volume size +- `cvmfs_physical_cache_avail_bytes` - Available cache space +- `cvmfs_hitrate` - Cache hit rate percentage +- `cvmfs_ncleanup24` - Cache cleanups in last 24 hours + +### Network & Download Metrics +- `cvmfs_rx_total` - Total bytes downloaded since mount +- `cvmfs_ndownload_total` - Total files downloaded since mount +- `cvmfs_speed` - Average download speed +- `cvmfs_proxy` - Available proxy servers +- `cvmfs_active_proxy` - Currently active proxy +- `cvmfs_timeout` - Proxy connection timeout +- `cvmfs_timeout_direct` - Direct connection timeout + +### Repository Status Metrics +- `cvmfs_repo` - Repository version and revision information +- `cvmfs_uptime_seconds` - Time since repository mount +- `cvmfs_mount_epoch_timestamp` - Repository mount timestamp +- `cvmfs_repo_expires_seconds` - Root catalog expiration time + +### System Resource Metrics +- `cvmfs_cpu_user_total` - CPU time in userspace +- `cvmfs_cpu_system_total` - CPU time in kernel space +- `cvmfs_maxfd` - Maximum file descriptors available +- `cvmfs_usedfd` - Currently used file descriptors +- `cvmfs_ndiropen` - Number of open directories +- `cvmfs_pid` - CVMFS process ID + +### Error & Monitoring Metrics +- `cvmfs_nioerr_total` - Total I/O errors encountered +- `cvmfs_timestamp_last_ioerr` - Timestamp of last I/O error +- `cvmfs_nclg` - Number of loaded nested catalogs +- `cvmfs_inode_max` - Highest possible inode number + +## Configuration + +### Repository Discovery + +By default, the exporter uses `findmnt` to discover CVMFS repositories mounted under `/cvmfs`. For non-standard setups, use the `--non-standard-mountpoints` flag to use `cvmfs_config status` instead. + +### Systemd Configuration + +The systemd service includes security hardening and resource limits: +- Runs as `cvmfs` user/group +- Restricted system call access +- Memory limit: 32MB +- CPU weight: 30 (low priority) +- I/O scheduling: best-effort, priority 7 + +### Prometheus Configuration + +Add the following to your Prometheus configuration: + +```yaml +scrape_configs: + - job_name: 'cvmfs-exporter' + static_configs: + - targets: ['localhost:9868'] + scrape_interval: 30s + scrape_timeout: 10s +``` + +## Requirements + +- **CVMFS**: CernVM File System client installed and configured +- **System Tools**: `attr`, `bc`, `findmnt`, `grep`, `cut`, `tr` +- **Permissions**: Read access to CVMFS cache files and extended attributes +- **Network**: Port 9868 for HTTP metrics endpoint (when using systemd socket) + +## Building from Source + +```bash +# Build packages +make package # Build both RPM and DEB +make rpm # Build RPM only +make deb # Build DEB only (requires Debian/Ubuntu) + +# Install from source +make install install-systemd +``` + +## Troubleshooting + +### Common Issues + +1. **Permission Denied**: Ensure the user has read access to CVMFS cache files +2. **No Metrics**: Verify CVMFS repositories are mounted and accessible +3. **Socket Connection Failed**: Check if systemd socket is active and port 9868 is available + +### Debug Commands + +```bash +# Test script manually +/usr/libexec/cvmfs/cvmfs-prometheus.sh --help + +# Check CVMFS status +cvmfs_config status + +# Verify repository mounts +findmnt -t fuse.cvmfs + +# Check systemd service +systemctl status cvmfs-client-prometheus.socket +journalctl -u cvmfs-client-prometheus@.service +``` + +## License + +This project is licensed under the BSD 3-Clause License. See the [LICENSE](LICENSE) file for details. + +## Contributing + +Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests. + +## Related Projects + +- [CernVM-FS](https://github.com/cvmfs/cvmfs) - The CernVM File System +- [Prometheus](https://prometheus.io/) - Monitoring and alerting toolkit diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..f3b5ec2 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +prometheus-cvmfs-exporter (1.0.0-1) unstable; urgency=medium + + * Initial release of prometheus-cvmfs-exporter + + -- Valentin Volkl Tue, 12 Aug 2025 12:00:00 +0000 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9173d06 --- /dev/null +++ b/debian/control @@ -0,0 +1,37 @@ +Source: prometheus-cvmfs-exporter +Section: admin +Priority: optional +Maintainer: Valentin Volkl +Build-Depends: debhelper-compat (= 13) +Standards-Version: 4.6.0 +Homepage: https://github.com/cvmfs-contrib/prometheus-cvmfs +Vcs-Git: https://github.com/cvmfs-contrib/prometheus-cvmfs.git +Vcs-Browser: https://github.com/cvmfs-contrib/prometheus-cvmfs + +Package: prometheus-cvmfs-exporter +Architecture: all +Depends: ${misc:Depends}, + bash, + attr, + bc, + cvmfs, + findutils, + grep, + coreutils, + util-linux, + systemd +Description: Prometheus exporter for CVMFS client monitoring + A Prometheus exporter for monitoring CVMFS (CernVM File System) clients. + This package provides a script that collects metrics from CVMFS repositories + and exposes them in Prometheus format, along with systemd service files + for running the exporter as a service. + . + The exporter collects various metrics including: + - Cache hit rates and sizes + - Download statistics + - Repository status and configuration + - Proxy usage and performance + - System resource usage by CVMFS processes + . + The package supports both legacy and modern CVMFS versions (>= 2.13.2) + and provides configurable repository discovery methods. diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..a1ea1e9 --- /dev/null +++ b/debian/install @@ -0,0 +1,2 @@ +systemd/cvmfs-client-prometheus@.service usr/lib/systemd/system/ +systemd/cvmfs-client-prometheus.socket usr/lib/systemd/system/ diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..d31f177 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +case "$1" in + configure) + # Reload systemd daemon to pick up new service files + if [ -d /run/systemd/system ]; then + systemctl daemon-reload >/dev/null 2>&1 || true + fi + ;; + abort-upgrade|abort-remove|abort-deconfigure) + ;; + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..385ed10 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + # Reload systemd daemon after file removal + if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then + if [ -d /run/systemd/system ]; then + systemctl daemon-reload >/dev/null 2>&1 || true + fi + fi + ;; + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/prerm b/debian/prerm new file mode 100755 index 0000000..25b1eee --- /dev/null +++ b/debian/prerm @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +case "$1" in + remove|upgrade|deconfigure) + # Stop and disable services before removal + if [ -d /run/systemd/system ]; then + systemctl stop cvmfs-client-prometheus@*.service >/dev/null 2>&1 || true + systemctl stop cvmfs-client-prometheus.socket >/dev/null 2>&1 || true + systemctl disable cvmfs-client-prometheus@.service >/dev/null 2>&1 || true + systemctl disable cvmfs-client-prometheus.socket >/dev/null 2>&1 || true + fi + ;; + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..cd8b79f --- /dev/null +++ b/debian/rules @@ -0,0 +1,19 @@ +#!/usr/bin/make -f + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ + +override_dh_auto_install: + $(MAKE) install DESTDIR=$(CURDIR)/debian/prometheus-cvmfs-exporter + +override_dh_auto_build: + # Nothing to build - this is a shell script package + +override_dh_auto_test: + # Skip tests for now + +override_dh_install: + dh_install diff --git a/prometheus-cvmfs-exporter.spec b/prometheus-cvmfs-exporter.spec new file mode 100644 index 0000000..2df6baa --- /dev/null +++ b/prometheus-cvmfs-exporter.spec @@ -0,0 +1,74 @@ +Name: prometheus-cvmfs-exporter +Version: %{version} +Release: %{release}%{?dist} +Summary: Prometheus exporter for CVMFS client monitoring + +License: BSD-3-Clause +URL: https://github.com/cvmfs-contrib/prometheus-cvmfs +Source0: %{name}-%{version}.tar.gz + +BuildArch: noarch +BuildRequires: systemd-rpm-macros + +# Runtime dependencies for the script +Requires: bash +Requires: attr +Requires: bc +Requires: cvmfs +Requires: findutils +Requires: grep +Requires: coreutils +Requires: util-linux + +# Systemd dependencies +Requires(post): systemd +Requires(preun): systemd +Requires(postun): systemd + +%description +A Prometheus exporter for monitoring CVMFS (CernVM File System) clients. +This package provides a script that collects metrics from CVMFS repositories +and exposes them in Prometheus format, along with systemd service files +for running the exporter as a service. + +The exporter collects various metrics including: +- Cache hit rates and sizes +- Download statistics +- Repository status and configuration +- Proxy usage and performance +- System resource usage by CVMFS processes + +%prep +%setup -q + +%build +# Nothing to build - this is a shell script package + +%install +# Install using the Makefile +make install DESTDIR=%{buildroot} +make install-systemd DESTDIR=%{buildroot} +# Remove duplicate LICENSE file from doc directory since %license handles it +rm -f %{buildroot}%{_docdir}/%{name}/LICENSE + +%post +%systemd_post cvmfs-client-prometheus@.service +%systemd_post cvmfs-client-prometheus.socket + +%preun +%systemd_preun cvmfs-client-prometheus@.service +%systemd_preun cvmfs-client-prometheus.socket + +%postun +%systemd_postun_with_restart cvmfs-client-prometheus@.service +%systemd_postun_with_restart cvmfs-client-prometheus.socket + +%files +%license LICENSE +%{_libexecdir}/cvmfs/cvmfs-prometheus.sh +%{_unitdir}/cvmfs-client-prometheus@.service +%{_unitdir}/cvmfs-client-prometheus.socket + +%changelog +* Tue Aug 12 2025 Valentin Volkl - 1.0.0-1 +- Initial package release