InfluxDB Installation/Collectors
From r00tedvw.com wiki
(Difference between revisions)
| Line 41: | Line 41: | ||
#loop that brings everything together and outputs to db via http post | #loop that brings everything together and outputs to db via http post | ||
| − | for ((i=0;i<=(${#vmstatvalues[@]}-1);i++)) | + | function influx_post { |
| − | do | + | for ((i=0;i<=(${#vmstatvalues[@]}-1);i++)) |
| − | + | do | |
| − | + | curl -i \ | |
| − | + | -H "Accept: application/json" \ | |
| − | + | -H "Content-Type:application/json" \ | |
| + | -X POST "http://""$dbhostname"":""$dbport""/write?db=""$dbtable" -u "$dbuser":"$dbpassword" --data-binary "${vmstatdef[i]}"",host=""$HOSTNAME"",domain=""$DOMAIN"" value=""${vmstatvalues[i]}" | ||
| − | done | + | done |
| + | } | ||
| + | |||
| + | influx_post | ||
</nowiki> | </nowiki> | ||
Revision as of 17:35, 30 September 2016
InfluxDB Installation | Collector Scripts
vmstat collector
script
#!/bin/bash
#define variables
HOSTNAME=$(hostname)
DOMAIN=$(hostname | awk -F "." '/1/ { printf $2"."$3"."$4};')
dbhostname=('dbhostname')
dbport=('8086')
dbtable=('dbtablename')
dbuser=('dbuser')
dbpassword=('dbpassword')
#vmstat 10 sec avg, output and create variables matching each
vmstatout=$(vmstat 10 2 -S k | awk 'NR==4')
r_process_normal=$(printf "$vmstatout" | awk '{ printf $1 }')
b_process_uninterruptible=$(printf "$vmstatout" | awk '{ printf $2 }')
swapd_virtual_mem_used=$(printf "$vmstatout" | awk '{ printf $3 }')
free_idle_mem=$(printf "$vmstatout" | awk '{ printf $4 }')
buf_mem_kernel=$(printf "$vmstatout" | awk '{ printf $5 }')
cache_mem_kernel=$(printf "$vmstatout" | awk '{ printf $6 }')
si_mem_from_swap=$(printf "$vmstatout" | awk '{ printf $7 }')
so_mem_to_swap=$(printf "$vmstatout" | awk '{ printf $8 }')
bi_io_from=$(printf "$vmstatout" | awk '{ printf $9 }')
bo_io_to=$(printf "$vmstatout" | awk '{ printf $10 }')
in_interrupts=$(printf "$vmstatout" | awk '{ printf $11 }')
cs_context_switch=$(printf "$vmstatout" | awk '{ printf $12 }')
us_cpu_non_kernel_code=$(printf "$vmstatout" | awk '{ printf $13 }')
sy_cpu_kernel_code=$(printf "$vmstatout" | awk '{ printf $14 }')
id_cpu_idle=$(printf "$vmstatout" | awk '{ printf $15 }')
wa_cpu_wait=$(printf "$vmstatout" | awk '{ printf $16 }')
st_cpu_stolen=$(printf "$vmstatout" | awk '{ printf $17 }')
#array of vmstat variable values
vmstatvalues=("$r_process_normal" "$b_process_uninterruptible" "$swapd_virtual_mem_used" "$free_idle_mem" "$buf_mem_kernel" "$cache_mem_kernel" "$si_mem_from_swap" "$so_mem_to_swap" "$bi_io_from" "$bo_io_to" "$in_interrupts" "$cs_context_switch" "$us_cpu_non_kernel_code" "$sy_cpu_kernel_code" "$id_cpu_idle" "$wa_cpu_wait" "$st_cpu_stolen")
#array of vmstat variable names
vmstatdef=('r_process_normal' 'b_process_uninterruptible' 'swapd_virtual_mem_used' 'free_idle_mem' 'buf_mem_kernel' 'cache_mem_kernel' 'si_mem_from_swap' 'so_mem_to_swap' 'bi_io_from' 'bo_io_to' 'in_interrupts' 'cs_context_switch' 'us_cpu_non_kernel_code' 'sy_cpu_kernel_code' 'id_cpu_idle' 'wa_cpu_wait' 'st_cpu_stolen')
#loop that brings everything together and outputs to db via http post
function influx_post {
for ((i=0;i<=(${#vmstatvalues[@]}-1);i++))
do
curl -i \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST "http://""$dbhostname"":""$dbport""/write?db=""$dbtable" -u "$dbuser":"$dbpassword" --data-binary "${vmstatdef[i]}"",host=""$HOSTNAME"",domain=""$DOMAIN"" value=""${vmstatvalues[i]}"
done
}
influx_post