Skip to content

Instantly share code, notes, and snippets.

@alexeagle
Created April 28, 2020 20:53
Show Gist options
  • Save alexeagle/aca064754db56371792f02d6fbe61dcc to your computer and use it in GitHub Desktop.
Save alexeagle/aca064754db56371792f02d6fbe61dcc to your computer and use it in GitHub Desktop.
readonly STATS_URL="http://pushgateway.domain:9091/metrics/job/livegrep_query_stats"
get_query () {
query=$1
# max_matches: -1 means no limit on number of matches
# NB: the query will have spaces in it, and appear as multiple argv to lg command,
# however it joins the argv residual on space again
matches=$(/livegrep/bin/lg -server http://0.0.0.0:8000 'max_matches:-1' $query | wc -l)
# Produce output that we can pipe to the pushgateway
# see https://github.com/prometheus/pushgateway/blob/master/README.md#command-line
echo "livegrep_count{query=\"$query\"} $matches"
}
export -f get_query
(
# find non-commented non-blank lines in the config
# and replace newline with null char
grep -v '^#'| grep "\S" | tr \\n \\0
) < /conf/canned_queries.txt | xargs -0 -n1 bash -c 'get_query "$@"' _ | curl --data-binary @- $STATS_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment