You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This script samples how many users are running applications of interest, ignores duplicates like how chrome spawns multiple processes.
this data aids are department to see what programs are used and where to spend money.
currently this script uses exec input plugin however this logic might be good to translate to a native input plugin like: telegraf/plugins/inputs/system/processes_count.go
#!/bin/bash
# USAGE:
# ./count_usage.sh "count_usage,host=$(hostname),group=mfcf" 'app_alias:app_exe_regex$'
# ./count_usage.sh "count_usage,host=$(hostname)" 'chromium:chromium$' 'firefox:firefox$' 'browsers:(chromium|firefox)$'
# OUTPUT:
# count_usage,host=mbp chromium=2,firefox=1,browsers=3
# DEV NOTES:
# because of comm 15char limit using `ps args`
# ps args can cause issues if it has spaces because cut truncates on them.
# might need sed -r , bsd uses -E however newer GNU seems to allow -E even tho undocumented
out="$1 "
ps=`ps -eo user,args --sort user | tr -s ' ' | cut -d ' ' -f 1-2 | sort | uniq`
for a in "${@:2}" ; do
key=`cut -d ':' -f 1 <<< "$a"`
regex=`cut -d ':' -f 2 <<< "$a"`
value=`echo "$ps" | sed -n -E "\!$regex!p" | wc -l`
out="${out}${key}=${value},"
done
# remove the extra ',' from the end of the string
out=`echo "$out" | sed 's/.$//'`
# output the measurement line
echo $out
The text was updated successfully, but these errors were encountered:
most of the input plugins could be created as good examples for exec... The issue here is when the next person is looking to accomplish the same objective they wont have to reinvent the wheel.
Perhaps there should be a git repo of user created exec scripts..
This script samples how many users are running applications of interest, ignores duplicates like how chrome spawns multiple processes.
this data aids are department to see what programs are used and where to spend money.
currently this script uses exec input plugin however this logic might be good to translate to a native input plugin like:
telegraf/plugins/inputs/system/processes_count.go
The text was updated successfully, but these errors were encountered: