Skip to content

Commit

Permalink
tools: add healthcheck tool and config.mk
Browse files Browse the repository at this point in the history
Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Jul 13, 2023
1 parent 0dd5120 commit 7f5b69e
Show file tree
Hide file tree
Showing 33 changed files with 2,859 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
- name: make
run: make -j

build-debug:
build-all:
runs-on: self-hosted
env:
PKG_CONFIG_PATH: /data/dpdk/dpdklib/lib64/pkgconfig
steps:
- uses: actions/checkout@v2
- name: config
run: sed -i 's/#CFLAGS +=/CFLAGS +=/' src/config.mk && sed -i 's/^#DEBUG := 1/DEBUG := 1/' src/Makefile
run: sed -i 's/=n$/=y/' config.mk
- name: make
run: make -j
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
MAKE = make
CC = gcc
LD = ld
RM = rm

SUBDIRS = src tools

Expand All @@ -29,6 +30,8 @@ export INSDIR

export KERNEL = $(shell /bin/uname -r)

include $(CURDIR)/config.mk

all:
for i in $(SUBDIRS); do $(MAKE) -C $$i || exit 1; done

Expand All @@ -43,3 +46,6 @@ distclean:
install:all
-mkdir -p $(INSDIR)
for i in $(SUBDIRS); do $(MAKE) -C $$i install || exit 1; done

uninstall:
-$(RM) -f $(TARGET) $(INSDIR)/*
33 changes: 33 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# configs
export CONFIG_DPVS_MAX_SOCKET=2
export CONFIG_DPVS_MAX_LCORE=64

## modules
export CONFIG_DPVS_AGENT=n
export CONFIG_IXGEB_PMD=y
export CONFIG_DPVS_LOG=y
export CONFIG_PDUMP=y
export CONFIG_ICMP_REDIRECT_CORE=n

# debugging and logging
export CONFIG_DEBUG=n
export CONFIG_DPVS_NEIGH_DEBUG=n
export CONFIG_RECORD_BIG_LOOP=n
export CONFIG_DPVS_SAPOOL_DEBUG=n
export CONFIG_DPVS_IPVS_DEBUG=n
export CONFIG_DPVS_SERVICE_DEBUG=n
export CONFIG_SYNPROXY_DEBUG=n
export CONFIG_TIMER_MEASURE=n
export CONFIG_TIMER_DEBUG=n
export DPVS_CFG_PARSER_DEBUG=n
export NETIF_BONDING_DEBUG=n
export CONFIG_TC_DEBUG=n
export CONFIG_DPVS_IPVS_STATS_DEBUG=n
export CONFIG_DPVS_IP_HEADER_DEBUG=n
export CONFIG_DPVS_MBUF_DEBUG=n
export CONFIG_DPVS_IPSET_DEBUG=n
export CONFIG_NDISC_DEBUG=n
export CONFIG_MSG_DEBUG=n
export CONFIG_DPVS_MP_DEBUG=n
export CONFIG_DPVS_NETIF_DEBUG=n
export CONFIG_DPVS_ICMP_DEBUG=n
2 changes: 1 addition & 1 deletion doc/Worker-Performance-Tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In case of the following situations, you should consider this performance tuning
* There exists big worker loops.

> To observe worker loop time, you should uncomment the macro "CONFIG_RECORD_BIG_LOOP" in src/config.mk,recompile DPVS program and run it.
> To observe worker loop time, you should set "CONFIG_RECORD_BIG_LOOP=y" in `config.mk`,recompile DPVS program and run it.
>
> Besides, macros "BIG_LOOP_THRESH_SLAVE" and "BIG_LOOP_THRESH_MASTER" define the threshold time of worker loop. Modify them if needed.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ Firstly, DPVS runs with `WARNING` log level by default. You can change it in `/e
Use low level log such as "INFO" or "DEBUG" may help find more clues to your problem.
Secondly, some modules support more detailed debug log only if you enable it when compile DPVS. The supported flags are defined but commented in [src/config.mk](../src/config.mk), some of which are listed below. Uncomment it and recompile DPVS if you need to debug the corresponding module.
Secondly, some modules support more detailed debug log only if you enable it when compile DPVS. The modular debug options are available in [config.mk](../config.mk), some of which are listed below. Change the value to "y" and recompile DPVS if you want to debug a module.
```
- CONFIG_DPVS_IPVS_DEBUG # for ipvs forwarding debug
Expand Down
138 changes: 138 additions & 0 deletions scripts/dpvs_log_rotate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/env bash

# Set target directory for cleaning
TARGET_DIR="/var/log/healthcheck"

# Set log file name pattern
LOG_FILENAME_PATTERN="*\.log\.*"

# Set the maximum usage percentage and the target usage percentage
MAX_USAGE=80
TARGET_USAGE=40

# Set the minimum number of log files to keep
MIN_FILES=12

# Set the maximum number of files to delete in one run
MAX_DELETE=10000

OPTS=`getopt -o d:p:u:l:K:D:h --long \
log-directory:,filename-pattern:,disk-usage-high:,\
disk-usage-low:,min-files-kept:,max-deletions:,help,\
-n "$0" -- "$@"`
eval set -- "$OPTS"
while true
do
case "$1" in
-d|--log-directory)
TARGET_DIR="$2"
shift 2
;;
-p|--filename-pattern)
LOG_FILENAME_PATTERN="$2"
shift 2
;;
-u|--disk-usage-high)
MAX_USAGE="$2"
shift 2
;;
-l|--disk-usage-low)
TARGET_USAGE="$2"
shift 2
;;
-K|--min-files-kept)
MIN_FILES="$2"
shift 2
;;
-D|--max-deletions)
MAX_DELETE="$2"
shift 2
;;
-h|--help)
echo "[usage] $0 [ OPTS ]"
echo "OPTS:"
echo " -d|--log-directory DIRECTORY"
echo " -p|--filename-pattern REGEXPR"
echo " -u|--disk-usage-high 0-100"
echo " -l|--disk-usage-low 0-100"
echo " -K|--min-files-kept NUM"
echo " -D|--max-deletions NUM"
echo " -h|--help"
exit 0
;;
--)
shift
break
;;
*)
echo "Param Error!"
exit 1
;;
esac
done

NotRecognized=$(for arg do printf "$arg " ; done)
[ ! -z "$NotRecognized" ] && echo "Unrecognized Opts: ${NotRecognized}" && exit 1

echo "CONFIGS:"
echo " log-directory: ${TARGET_DIR}"
echo " filename-pattern: ${LOG_FILENAME_PATTERN}"
echo " disk-usage-high: ${MAX_USAGE}"
echo " disk-usage-low: ${TARGET_USAGE}"
echo " min-files-kept: ${MIN_FILES}"
echo " max-deletions: ${MAX_DELETE}"

[ ! -d ${TARGET_DIR} ] && echo "invalid --log-directory \"${TARGET_DIR}\", not found!" && exit 1
echo ${MAX_USAGE} | egrep ^[0-9]+$ >/dev/null; [ $? -ne 0 ] && echo "invalid --disk-usage-high" && exit 1
echo ${TARGET_USAGE} | egrep ^[0-9]+$ >/dev/null; [ $? -ne 0 ] && echo "invalid --disk-usage-low" && exit 1
echo ${MIN_FILES} | egrep ^[0-9]+$ >/dev/null; [ $? -ne 0 ] && echo "invalid --min-files-kept" && exit 1
echo ${MAX_DELETE} | egrep ^[0-9]+$ >/dev/null; [ $? -ne 0 ] && echo "invalid --max-deletions" && exit 1
res=$(echo "${MAX_USAGE} < 100" | bc); [ "$res" -ne 1 ] && echo "--disk-usage-high must less than 100" && exit 1
res=$(echo "${MAX_USAGE} > ${TARGET_USAGE}" | bc); [ "$res" -ne 1 ] && echo "--disk-usage-high must greater than --disk-usage-low" && exit 1

# Get the current disk usage
CURRENT_USAGE=$(df -P ${TARGET_DIR} | awk 'NR==2 {printf "%d", $5}')

# Initialize a counter for deleted files
DELETED_FILES=0

# Start the cleaning process if the disk usage is higher than the defined MAX_USAGE
if [ "${CURRENT_USAGE}" -gt "${MAX_USAGE}" ]; then
echo "Disk usage is ${CURRENT_USAGE}%, starting cleaning process."

# Find and delete logs until disk usage reaches TARGET_USAGE or MAX_DELETE files are deleted
while [ "${CURRENT_USAGE}" -gt "${TARGET_USAGE}" ] && [ "${DELETED_FILES}" -lt "${MAX_DELETE}" ]; do
# Check the number of log files
NUM_FILES=$(find ${TARGET_DIR} -type f -name ${LOG_FILENAME_PATTERN} | wc -l)

# Ensure that at least MIN_FILES log files remain
if [ "${NUM_FILES}" -le "${MIN_FILES}" ]; then
echo "Reached minimum number of log files (${MIN_FILES}), aborting."
exit 1
fi

# Find the oldest log file
OLDEST_LOG=$(find ${TARGET_DIR} -type f -name ${LOG_FILENAME_PATTERN} -printf '%T+ %p\n' | sort | head -n1 | cut -d' ' -f2)

echo "Deleting ${OLDEST_LOG}..."
rm -f "${OLDEST_LOG}"
DELETED_FILES=$((DELETED_FILES+1))

# Update current disk usage
CURRENT_USAGE=$(df -P ${TARGET_DIR} | awk 'NR==2 {printf "%d", $5}')
done

if [ "${DELETED_FILES}" -eq "${MAX_DELETE}" ]; then
echo "Reached the maximum number of deletions (${MAX_DELETE}), aborting."
else
echo "Cleaning process completed. Disk usage is now ${CURRENT_USAGE}%."
fi

else
echo "Disk usage is ${CURRENT_USAGE}%, no cleaning needed."
fi

echo "Remaining Files in ${TARGET_DIR} (only show 30 entries):"
ls -lh ${TARGET_DIR} | head -n 30

exit 0
4 changes: 1 addition & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# Makefile for dpvs (DPVS main program).
#

#DEBUG := 1 # enable for debug

TARGET := dpvs

ifneq ("$(wildcard VERSION)","")
Expand Down Expand Up @@ -59,7 +57,7 @@ ifeq ($(shell test $(GCC_VERSION) -ge 70 && echo 1), 1)
CFLAGS += -Wstringop-overflow=0
endif

ifeq ($(DEBUG),)
ifneq ($(CONFIG_DEBUG), y)
CFLAGS += -O3
else
CFLAGS += -g -O0 -D DEBUG
Expand Down
128 changes: 93 additions & 35 deletions src/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,110 @@
# GNU General Public License for more details.
#

#
# enable as needed.
#
# TODO: use standard way to define compile flags.
#

CONFIG_IXGEB_PMD=y
CONFIG_PDUMP=y
CFLAGS += -D DPVS_MAX_SOCKET=$(CONFIG_DPVS_MAX_SOCKET)
CFLAGS += -D DPVS_MAX_LCORE=$(CONFIG_DPVS_MAX_LCORE)

CFLAGS += -D DPVS_MAX_SOCKET=2
CFLAGS += -D DPVS_MAX_LCORE=64

CFLAGS += -D CONFIG_DPVS_LOG
#CFLAGS += -D CONFIG_ICMP_REDIRECT_CORE
#CFLAGS += -D CONFIG_DPVS_AGENT

#CFLAGS += -D CONFIG_DPVS_NEIGH_DEBUG
#CFLAGS += -D CONFIG_RECORD_BIG_LOOP
#CFLAGS += -D CONFIG_DPVS_SAPOOL_DEBUG
#CFLAGS += -D CONFIG_DPVS_IPVS_DEBUG
#CFLAGS += -D CONFIG_DPVS_SERVICE_DEBUG
#CFLAGS += -D CONFIG_SYNPROXY_DEBUG
#CFLAGS += -D CONFIG_TIMER_MEASURE
#CFLAGS += -D CONFIG_TIMER_DEBUG
#CFLAGS += -D DPVS_CFG_PARSER_DEBUG
#CFLAGS += -D NETIF_BONDING_DEBUG
#CFLAGS += -D CONFIG_TC_DEBUG
#CFLAGS += -D CONFIG_DPVS_IPVS_STATS_DEBUG
#CFLAGS += -D CONFIG_DPVS_IP_HEADER_DEBUG
#CFLAGS += -D CONFIG_DPVS_MBUF_DEBUG
#CFLAGS += -D CONFIG_DPVS_IPSET_DEBUG
#CFLAGS += -D CONFIG_NDISC_DEBUG
#CFLAGS += -D CONFIG_MSG_DEBUG
#CFLAGS += -D CONFIG_DPVS_MP_DEBUG
#CFLAGS += -D CONFIG_DPVS_NETIF_DEBUG
#CFLAGS += -D CONFIG_DPVS_ICMP_DEBUG
ifeq ($(CONFIG_DPVS_AGENT), y)
CFLAGS += -D CONFIG_DPVS_AGENT
endif

# for ixgbe nic
ifeq ($(CONFIG_IXGEB_PMD), y)
CFLAGS += -D CONFIG_DPVS_FDIR
endif

ifeq ($(CONFIG_DPVS_LOG), y)
CFLAGS += -D CONFIG_DPVS_LOG
endif

ifeq ($(CONFIG_PDUMP), y)
CFLAGS += -D CONFIG_DPVS_PDUMP
endif

ifeq ($(CONFIG_ICMP_REDIRECT_CORE), y)
CFLAGS += -D CONFIG_ICMP_REDIRECT_CORE
endif

ifeq ($(CONFIG_DPVS_NEIGH_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_NEIGH_DEBUG
endif

ifeq ($(CONFIG_RECORD_BIG_LOOP), y)
CFLAGS += -D CONFIG_RECORD_BIG_LOOP
endif

ifeq ($(CONFIG_DPVS_SAPOOL_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_SAPOOL_DEBUG
endif

ifeq ($(CONFIG_DPVS_IPVS_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_IPVS_DEBUG
endif

ifeq ($(CONFIG_DPVS_SERVICE_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_SERVICE_DEBUG
endif

ifeq ($(CONFIG_SYNPROXY_DEBUG), y)
CFLAGS += -D CONFIG_SYNPROXY_DEBUG
endif

ifeq ($(CONFIG_TIMER_MEASURE), y)
CFLAGS += -D CONFIG_TIMER_MEASURE
endif

ifeq ($(CONFIG_TIMER_DEBUG), y)
CFLAGS += -D CONFIG_TIMER_DEBUG
endif

ifeq ($(DPVS_CFG_PARSER_DEBUG), y)
CFLAGS += -D DPVS_CFG_PARSER_DEBUG
endif

ifeq ($(NETIF_BONDING_DEBUG), y)
CFLAGS += -D NETIF_BONDING_DEBUG
endif

ifeq ($(CONFIG_TC_DEBUG), y)
CFLAGS += -D CONFIG_TC_DEBUG
endif

ifeq ($(CONFIG_DPVS_IPVS_STATS_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_IPVS_STATS_DEBUG
endif

ifeq ($(CONFIG_DPVS_IP_HEADER_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_IP_HEADER_DEBUG
endif

ifeq ($(CONFIG_DPVS_MBUF_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_MBUF_DEBUG
endif

ifeq ($(CONFIG_DPVS_IPSET_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_IPSET_DEBUG
endif

ifeq ($(CONFIG_NDISC_DEBUG), y)
CFLAGS += -D CONFIG_NDISC_DEBUG
endif

ifeq ($(CONFIG_MSG_DEBUG), y)
CFLAGS += -D CONFIG_MSG_DEBUG
endif

ifeq ($(CONFIG_DPVS_MP_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_MP_DEBUG
endif

ifeq ($(CONFIG_DPVS_NETIF_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_NETIF_DEBUG
endif

ifeq ($(CONFIG_DPVS_ICMP_DEBUG), y)
CFLAGS += -D CONFIG_DPVS_ICMP_DEBUG
endif

GCC_MAJOR = $(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR = $(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)
GCC_VERSION = $(GCC_MAJOR)$(GCC_MINOR)
Expand Down
Loading

0 comments on commit 7f5b69e

Please sign in to comment.