• The forums are being shutdown, and applicable content is being moved to the new blog located at https://xtremeownage.com/ For the time being, these forums are still available for reading purposes. However, user registrations have been disabled.

Splunk Splunk - RGB Value Based on Percentage


Staff member
So- I had a need to calculate a RGB value based on the percentage total progress. Here is how I accomplished it.

First, we need to calculate the percentage complete. Your implementation may vary.

| eventstats count as total 
| streamstats count as pos 
| eval pct = ROUND(pos/total*100,0)
Next, I needed to calculate the RGB value. My implementation goes from red(0%) to green(100%).

| eval r=IF(pct<50, 255, 510-5.10*pct), g=IF(pct<50, 5.1*pct, 255), b=0
Next, is this ugly block of commands, to convert the RGB values, into a single hex value.

## Round the values. Cannot convert decimals to hex.
| eval r=ROUND(r,0), g=ROUND(g,0), b=ROUND(b,0)
## Replace the 0x with empty.
| eval rH=REPLACE(tostring(r,"hex"), "0x", ""),gH=REPLACE(tostring(g,"hex"), "0x", ""), bH=REPLACE(tostring(b,"hex"), "0x", "")
## Ensure each "grouping" is two characters long.
| eval rH=substr("00", 0, max(2-len(rH), 0)).rH, gH=substr("00", 0, max(2-len(gH), 0)).gH, bH=substr("00", 0, max(2-len(bH), 0)).bH 
## Combine the hex segments
| eval circleColor="#".rH.gH.bH
That's it! Here is the color curve visualized.