Update 2018:
- the source code has been removed from github
- the app has been removed from splunkbase
I do not know of a good way of using Splunk in R outside of using the rest api.
Original post:
Yes ! There is a Splunk app for that exact purpose.
It is called R Project.
Using it is really easy.
| r "output = data.frame(Name=c('A','B','C'),Value=c(1,2,3))"
... or just the name of a R script file that is uploaded to the app:
| r myscript.r
Input comes in as input
and you need you direct your results to output
to get them back into Splunk.
- Download the App
- Add the path to your R bin in
$SPLUNK_HOME/etc/apps/r/default/r.conf
e.g. r=/usr/bin/R
- Pipe to R in your search command like this:
| r "exp(mean(log(data.matrix(input)))) -> output"
Here is a slightly more complicated example:
sourcetype=ps earliest=-4m
| multikv fields RSZ_KB
| search RSZ_KB > 0 AND VSZ_KB > 0
| table RSZ_KB VSZ_KB
| r "
gm_mean = function(x, na.rm=TRUE){
exp(sum(log(x[x > 0]), na.rm=na.rm) / length(x))
}
data <- data.matrix(input);
output <- apply(data, 2, gm_mean)"
provides
x
132.902175678696
34188.4285350717