Commit initial

This commit is contained in:
Breizh 2022-11-12 02:42:52 +01:00
commit 938679217b

171
charts.d/radeon.chart.sh Normal file
View file

@ -0,0 +1,171 @@
# shellcheck shell=bash
# no need for shebang - this file is loaded from charts.d.plugin
# _update_every is a special variable - it holds the number of seconds
# between the calls of the _update() function
radeon_update_every=
# the priority is used to sort the charts on the dashboard
# 1 = the first chart
radeon_priority=150000
# global variables to store our collected data
# remember: they need to start with the module name radeon_
# Pecentage
declare -i radeon_perc_{gpu,ee,vgt,ta,sx,sh,spi,sc,pa,db,cb,vram,gtt,mclk,sclk}=0
# Fréquences
declare -i radeon_freq_{mclk,sclk}=0
declare -i radeon_freqmax_{mclk=2100,sclk=1560}
# Mio
declare -i radeon_mb_{vram,gtt}=0
declare -i radeon_mbmax_{vram=8162,gtt=8184}
radeon_get() {
# do all the work to collect / calculate the values
# for each dimension
#
# Remember:
# 1. KEEP IT SIMPLE AND SHORT
# 2. AVOID FORKS (avoid piping commands)
# 3. AVOID CALLING TOO MANY EXTERNAL PROGRAMS
# 4. USE LOCAL VARIABLES (global variables may overlap with other modules)
declare output key value i
output="$(radeontop -d- -l1 | tail -n1)"
output="${output//./}"
oldIFS="$IFS"
IFS=","
for i in ${output}
do
# Skip first line
[[ ${i:0:1} != " " ]] && continue
# Remove whitespace at the start of the line
i="${i:1}"
# Set the key
key="${i%% *}"
# For freq
if [[ "${i: -3}" == "ghz" ]]
then
value="${i##* }"
value="${value:0:-3}"
declare -ig "radeon_freq_$key=10#$value"
i="${i% *}"
# For mb
elif [[ "${i: -2}" == "mb" ]]
then
value="${i##* }"
value="${value:0:-2}"
declare -ig "radeon_mb_$key=10#$value"
i="${i% *}"
fi
# Percentages
value="${i##* }"
value="${value:0:-1}"
declare -ig "radeon_perc_$key=10#$value"
done
IFS="$oldIFS"
# this should return:
# - 0 to send the data to netdata
# - 1 to report a failure to collect the data
return 0
}
# _check is called once, to find out if this chart should be enabled or not
radeon_check() {
# this should return:
# - 0 to enable the chart
# - 1 to disable the chart
# check radeontop command
require_cmd radeontop || return 1
# check that we can collect data
# radeon_get || return 1
return 0
}
# _create is called once, to create the charts
radeon_create() {
# create the chart
cat << EOF
CHART radeon.percent '' "GPU Utilization" "percentage" gpu0 percentage line $radeon_priority $radeon_update_every
DIMENSION gpu 'graphics pipe' absolute 1 100
DIMENSION ee 'event engine' absolute 1 100
DIMENSION vgt 'vertex grouper + tesselator' absolute 1 100
DIMENSION ta 'texture addresser' absolute 1 100
DIMENSION sx 'shader export' absolute 1 100
DIMENSION sh 'sequencer instruction cache' absolute 1 100
DIMENSION spi 'shader interpolator' absolute 1 100
DIMENSION sc 'scan converter' absolute 1 100
DIMENSION pa 'primitive assembly' absolute 1 100
DIMENSION db 'depth block' absolute 1 100
DIMENSION cb 'color block' absolute 1 100
DIMENSION vram 'vram' absolute 1 100
DIMENSION gtt 'graphic translation table' absolute 1 100
DIMENSION mclk 'memory clock' absolute 1 100
DIMENSION sclk 'shader clock' absolute 1 100
CHART radeon.freq '' "GPU Frequencies" "MHz" gpu0 freq line $((radeon_priority + 2)) $radeon_update_every
DIMENSION mclk 'memory clock' absolute 1 1
DIMENSION sclk 'shader clock' absolute 1 1
VARIABLE CHART maxmclk = $radeon_freqmax_mclk
VARIABLE CHART maxsclk = $radeon_freqmax_sclk
CHART radeon.mb '' "GPU MB Utilization" "MB" gpu0 mb line $((radeon_priority + 1)) $radeon_update_every
DIMENSION vram 'vram' absolute 1 100
DIMENSION gtt 'graphic translation table' absolute 1 100
VARIABLE CHART maxvram = $radeon_mbmax_vram
VARIABLE CHART maxgtt = $radeon_mbmax_gtt
EOF
return 0
}
# _update is called continuously, to collect the values
radeon_update() {
# the first argument to this function is the microseconds since last update
# pass this parameter to the BEGIN statement (see bellow).
radeon_get || return 1
# write the result of the work.
cat << VALUESEOF
BEGIN radeon.percent
SET gpu = $radeon_perc_gpu
SET ee = $radeon_perc_ee
SET vgt = $radeon_perc_vgt
SET ta = $radeon_perc_ta
SET sx = $radeon_perc_sx
SET sh = $radeon_perc_sh
SET spi = $radeon_perc_spi
SET sc = $radeon_perc_sc
SET pa = $radeon_perc_pa
SET db = $radeon_perc_db
SET cb = $radeon_perc_cb
SET vram = $radeon_perc_vram
SET gtt = $radeon_perc_gtt
SET mclk = $radeon_perc_mclk
SET sclk = $radeon_perc_sclk
END
BEGIN radeon.freq
SET mclk = $radeon_freq_mclk
SET sclk = $radeon_freq_sclk
END
BEGIN radeon.mb
SET vram = $radeon_mb_vram
SET gtt = $radeon_mb_gtt
END
VALUESEOF
return 0
}