Skip to main content

Usage examples

Use Focus to guide you to frequently used commands and other use cases. This will be helpful to development and operation by allowing you to check the data in time series.

Checking the project access key and collection server IP

In Management > Agent Installation for the selected project, check the project code, collection server IP, and project access key.

export WHATAP_LICENSE=xxxx-xxxxxx-xxxxxx
export WHATAP_HOST=xxxx.xxxx.xxxx
export WHATAP_PCODE=xxx

Adding specific tags for filtering

Referring to the following example, you can filter the data collected from the WhaTap monitoring service screen by the name and value for the tag.

SH
# -tag.[User tag key name][Blank][User tag value]

./focus -license $WHATAP_LICENSE \
-pcode $WHATAP_PCODE -server.host $WHATAP_HOST \
-tag.CustomTagName CustomTagValue \
-tag.MyServer1 server_01 \
...

Collecting the CPU and memory for each Top command PID

The following example executes the top command to continuously collect the CPU and memory usage of a specific process.

Linux Shell
#Metric category
CATEGORY="my_category"

export PID=PID of the process to collect
top -b -p $PID | awk '/'$PID'/{ printf "{\"pid\": %s, \"cpuPercent\": %s, \"memoryPercent\": %s, \"cmd\": \"%s\"}\n",$1, $9, $10, $12}; system("")' | \
./focus -license $WHATAP_LICENSE \
-pcode $WHATAP_PCODE -server.host $WHATAP_HOST \
-category $CATEGORY

Using NETSTAT

The following example executes the netstat command to collect the number of TCP connections by status.

Linux Shell
#Metric category
CATEGORY="my_category"

netstat -nat| tail -n+3 | awk '{print $6}' | sort | uniq -c | awk 'BEGIN { printf "{" } {if (NR!=1) {printf ", "}}{printf "\"%s\":%s",$2,$1} END { print "}" }' | \
./focus -license $WHATAP_LICENSE \
-pcode $WHATAP_PCODE -server.host $WHATAP_HOST \
-category $CATEGORY -onetime

Using VMSTAT

The following example executes the vmstat command to collect itemized metrics.

Linux Shell
#Metric category
CATEGORY="my_category"

vmstat -n 5 | awk ' NR>2 {printf "{ \"r\":%s,\"b\":%s, \"swpd\" :%s, \"free\" :%s, \"buff\" :%s, \"cache\" :%s, \"si\" :%s, \"so\":%s, \"bi\" :%s, \"bo\" :%s, \"in\" :%s, \"cs\":%s, \"us\":%s, \"sy\":%s, \"id\":%s, \"wa\":%s, \"st\" :%s }\n", $1,$2, $3,$4, $5,$6, $7,$8, $9,$10, $11,$12, $13,$14, $15,$16,$17}\n' | \
./focus -license $WHATAP_LICENSE \
-pcode $WHATAP_PCODE -server.host $WHATAP_HOST \
-category $CATEGORY

Using DU

The following example executes the du command to collect the capacity of a directory.

Linux Shell
#Metric category
CATEGORY="my_category"
TARGET=Directory to collect capacity in

du -sb $TARGET --max-depth=0 | awk 'BEGIN { printf "{" } {if (NR!=1) {printf ", "}}{printf "\"%s\":%s",$2,$1} END { print "}" }' | \
./focus -license $WHATAP_LICENSE \
-pcode $WHATAP_PCODE -server.host $WHATAP_HOST \
-category $CATEGORY -onetime