diff --git a/README.md b/README.md index 2d61a18..f59acbf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -monitools -== +# monitools Gather resource consumption data around a CodeReady Containers instance @@ -10,23 +9,20 @@ The following diagram represent the interaction of monitools container with a ho ![Overview](docs/overview.jpg?raw=true) The container will be configured with ENVs: - -#### target host configuration -**TARGET_HOST**(*mandatory*): Target host address +**TARGET_HOST**(*mandatory*): Target host address **TARGET_HOST_USERNAME**(*mandatory*): username - Chose one of following depending on the target auth mechanism: - **TARGET_HOST_KEY_PATH**(*optional*): key path **TARGET_HOST_PASSWORD**(*optional*): pasword - -#### monictl configuration - **MONICTL_REPETITIONS**(*optional, default 5*) **MONICTL_INTERVAL**(*optional, default 1*) +**MONITOOL_PERIOD**(*optional, in case we want to loop the monitool execution for a period of time. Period is a number (hours) If not set it will run only once*) +**MONITOOL_PERIOD**(*optional, in case we define MONITOOL_PERIOD. We can set the interval, default is 30m, interval is defined according linux sleep command time syntax*) +**RESULTS_PATH**(*optional, define the target path on the container to copy back results, default is /output*) Sample container execution + ```bash podman run -it --rm \ -e TARGET_HOST_USERNAME=XXXX \ @@ -50,11 +46,13 @@ make install 1. Create directory where you want `monictl` to deposit the data. 2. Have a running instance of CRC (`crc status` returns `Running` for both VM and the cluster) 3. Run - ```bash + +```bash monictl -d= -n= -s= - ``` -4. Look into your data folder to inspect the files. - +``` + +4. Look into your data folder to inspect the files. + ### Flags/arguments - `-d`: data directory (relative to current directory) @@ -95,12 +93,12 @@ Then use as any other package, e.g. by importing as: ``` bash import github.com/code-ready/monitools/tools ``` + ### Example In `monitools/examples` you will find a short program that imports this module and the `tools` package and runs one of its functions. It assumes an existing CRC VM and probes for CPU usage of the `qemu` process 5 times with 1s sleep inbetween probes. Resulting %CPU is recorded in `cpu.csv` in the same `monitools/examples` folder. Run the example script `example.go` by ``` bash -$ cd monitools/examples -$ go run example.go +cd monitools/examples +go run example.go ``` - diff --git a/images/build/entrypoint.sh b/images/build/entrypoint.sh index c236bf3..f373e18 100755 --- a/images/build/entrypoint.sh +++ b/images/build/entrypoint.sh @@ -5,6 +5,7 @@ MONICTL_PATH=/usr/local/bin/monictl RESULTS_PATH="${RESULTS_PATH:-/output}" MONICTL_REPETITIONS="${MONICTL_REPETITIONS:-5}" MONICTL_INTERVAL="${MONICTL_INTERVAL:-1}" +MONITOOL_INTERVAL="${MONITOOL_INTERVAL:-30m}" if [ "${DEBUG:-}" = "true" ]; then set -xuo @@ -23,6 +24,7 @@ validate=true [[ -z "${TARGET_HOST_KEY_PATH}" && -z "${TARGET_HOST_PASSWORD}" ]] \ && echo "TARGET_HOST_KEY_PATH or TARGET_HOST_PASSWORD required" \ && validate=false + [[ $validate == false ]] && exit 1 # Set SCP / SSH command @@ -41,9 +43,24 @@ $SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "mkdir -p ${EXECUTION_FOLDER} && m # Copy monictl to target host $SCP "${MONICTL_PATH}" "${TARGET_HOST_USERNAME}@${TARGET_HOST}:${EXECUTION_FOLDER}" -# Run (one shot) monictl -MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}" -$SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}" +if [[ -z "${MONITOOL_PERIOD}" ]]; then + # Run (one shot) monictl + MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}" + $SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}" +else + START=$(date +%s) + TOTAL_TIME=$((60 * 60 * ${MONITOOL_PERIOD})) + UPTIME=$(($(date +%s) - $START)) + ITERATION=0 + while [[ $UPTIME -lt $TOTAL_TIME ]]; do + DATA_FOLDER="${EXECUTION_FOLDER}/data-${ITERATION}" + MONITOOL_EXEC="${EXECUTION_FOLDER}/monictl -d ${DATA_FOLDER} -n ${MONICTL_REPETITIONS} -s ${MONICTL_INTERVAL}" + $SSH "${TARGET_HOST_USERNAME}@${TARGET_HOST}" "${MONITOOL_EXEC}" + UPTIME=$(($(date +%s) - $START)) + ((ITERATION++)) + sleep ${MONITOOL_INTERVAL} + done +fi # Get results mkdir -p "${RESULTS_PATH}"