ソースを参照

container image stuff & reqs

Grega Bremec 2 年 前
コミット
fac42944e7

+ 7 - 0
.gitignore

@@ -0,0 +1,7 @@
+.DS_Store
+.*.sw?
+*.vim
+*.code-workspace
+.vscode
+target
+tmp*

+ 42 - 0
README.adoc

@@ -0,0 +1,42 @@
+= Linux Metrics Exporter for OpenShift Nodes =
+
+== Components ==
+
+. Container Image for SAR
+. Container Image for PSACCT
+. Container Image for Exporter
+
+== Deployment ==
+
+TBD
+
+== Images ==
+
+=== SAR ===
+
+Sar image is based on ubi-micro and includes just the `sysstat` package.
+
+It expects a volume to be attached at `/var/log/sa`.
+
+Entrypoint takes care of initialising the volume and rotating any old `sar` files out of the way.
+
+It *requires* to be executed under `root` UID.
+
+It also *requires* access to host's network namespace if you want to measure network statistics.
+
+=== PSACCT ===
+
+Sar image is based on ubi-micro and includes just the `psacct` package.
+
+It expects a volume to be attached at `/var/account`.
+
+Entrypoint takes care of initialising the volume and rotating any old `pacct` files out of the way.
+
+In addition to *requiring* execution under `root` UID, it also *requires* the `SYS_PACCT` capability.
+
+It also *requires* access to host's PID namespace (`--pid=host` podman option).
+
+=== Exporter ===
+
+TBD
+

+ 17 - 0
images/Containerfile-psacct

@@ -0,0 +1,17 @@
+FROM registry.access.redhat.io/ubi9/ubi-minimal:latest
+
+USER 0
+
+COPY entrypoint-psacct.sh /usr/local/bin/entrypoint.sh
+
+RUN microdnf install psacct && \
+    rm -rf /var/lib/dnf /var/cache/dnf /var/cache/cups /var/cache/PackageKit && \
+    chmod 755 /usr/local/bin/entrypoint.sh
+
+VOLUME /var/account
+
+ARG STARTUP_SCRATCH
+ARG CUMULATIVE
+
+ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
+

+ 17 - 0
images/Containerfile-sysstat

@@ -0,0 +1,17 @@
+FROM registry.access.redhat.io/ubi9/ubi-minimal:latest
+
+USER 0
+
+COPY entrypoint-sysstat.sh /usr/local/bin/entrypoint.sh
+
+RUN microdnf install sysstat && \
+    rm -rf /var/lib/dnf /var/cache/dnf /var/cache/cups /var/cache/PackageKit && \
+    chmod 755 /usr/local/bin/entrypoint.sh
+
+VOLUME /var/log/sa
+
+ARG STARTUP_SCRATCH
+ARG STARTUP_ROTATE
+
+ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
+

+ 69 - 0
images/entrypoint-psacct.sh

@@ -0,0 +1,69 @@
+#!/bin/bash
+
+# Just die if not root.
+if [ ${UID} -ne 0 ]; then
+    echo "FATAL: Need to run as root."
+    exit 1
+fi
+
+# Die if not running with CAP_SYS_PACCT
+if [ -z "$(capsh --decode=$(cat /proc/self/status | grep ^CapEff | cut -f2) | grep sys_pacct)" ]; then
+    echo "FATAL: Need CAP_SYS_PACCT to run."
+    exit 1
+fi
+
+# Announce collection period.
+PERIOD=10
+if [ -n "$1" ]; then
+    PERIOD=$1
+fi
+echo "Reporting on process activity every ${PERIOD} seconds."
+
+# Did someone ask for cumulative stats?
+case ${CUMULATIVE:-0} in
+    1|yes|true)
+	echo "Gathering cumulative accounting data since container start."
+	CUMULATIVE=1
+	;;
+    *)
+	echo "Clearing accounting data between snapshots."
+	CUMULATIVE=0
+	;;
+esac
+
+# Clean up /var/account/pacct on startup if so requested.
+case ${STARTUP_SCRATCH:-0} in
+    1|yes|true)
+	echo "Removing existing accounting data due to scratch-on-startup being ${STARTUP_SCRATCH}..."
+	rm -rf /var/account
+	;;
+    *)
+	echo "Skipping scratch-on-startup..."
+	;;
+esac
+
+# Make sure we have everything
+echo "Making sure /var/account/pacct is ready..."
+/usr/libexec/psacct/accton-create
+
+# Start accounting
+/usr/sbin/accton /var/account/pacct
+
+# Do the loop
+while [ 1  ]; do
+    sleep ${PERIOD}
+
+    # Report after waking up.
+    /usr/sbin/sa -ajlp > /var/account/dump-all
+    /usr/sbin/dump-acct /var/account/pacct > /var/account/dump-raw
+
+    # Could make a CSV out of the above "sa":
+    #   | tr -s' ' | sed 's/^ //; s/ /,/g'
+
+    # Did we say NOT cumulative data?
+    if [ ${CUMULATIVE} -eq 0 ]; then
+	echo -n > /var/account/pacct
+    fi
+done
+
+# End of entrypoint-psacct.sh

+ 66 - 0
images/entrypoint-sysstat.sh

@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Just die if not root.
+if [ ${UID} -ne 0 ]; then
+    echo "FATAL: Need to run as root."
+    exit 1
+fi
+
+# Announce collection period.
+PERIOD=10
+if [ -n "$1" ]; then
+    PERIOD=$1
+fi
+REPORT_LENGTH=$((2 * PERIOD - 1))
+echo "Collecting and reporting system activity statistics every ${PERIOD} seconds..."
+
+# Clean up /var/log/sa on startup if so requested.
+case ${STARTUP_SCRATCH:-0} in
+    1|yes|true)
+	echo "Removing existing SA1 data due to scratch-on-startup being ${STARTUP_SCRATCH}..."
+	rm -rf /var/log/sa
+	;;
+    *)
+	echo "Skipping scratch-on-startup..."
+	;;
+esac
+
+# Add a record of rotation to existing logs if so requested.
+case ${STARTUP_ROTATE:-0} in
+    1|yes|true)
+	echo "Marking existing SA1 data as rotated due to rotate-on-startup being ${STARTUP_ROTATE}..."
+	/usr/lib64/sa/sa1 --rotate
+	;;
+    *)
+	echo "Skipping rotate-on-startup..."
+	;;
+esac
+
+# Mark a reboot.
+/usr/lib64/sa/sa1 --boot
+
+# Remember the hour-of-day.
+PREV_HOUR="$(date +%H)"
+
+# Do the loop.
+while [ 1 ]; do
+    # Start sa1.
+    /usr/lib64/sa/sa1 ${PERIOD} 1
+
+    # Produce the report.
+    REPORT_FROM=$(date +%H:%M:%S -d "${REPORT_LENGTH} seconds ago")
+    REPORT_UNTIL=$(date +%H:%M:%S)
+    /usr/bin/sadf -s ${REPORT_FROM} -e ${REPORT_UNTIL} -j -- -A > /var/log/sa/dump.json
+
+    # Have we awoken in a new day? Rotation record, please!
+    NEW_HOUR="$(date +%H)"
+    if [ ${NEW_HOUR} -lt ${PREV_HOUR} ]; then
+	echo "Marking last saXX as rotated..."
+	/usr/lib64/sa/sa1 --rotate
+    fi
+    PREV_HOUR=${NEW_HOUR}
+
+    sleep ${PERIOD}
+done
+
+# End of entrypoint-sysstat.sh