Splunk Search

Geographical distance calculation in Splunk Cloud (replacing haversine)

rcornett
New Member

Hi all,

 

We are currently migrating from Splunk on-premise to the Cloud. One of the apps we heavily use is haversine to calculate the distance between 2 locations.

 

I haven't been able to find a cloud-ready replacement for this. Just looking for recommendations on an app or solution to be able to do this in the cloud?

 

Cheers,

Ryan

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

I created a haversine macro (from macros.conf)

[haversine(4)]
args = source_lat, source_lon, dest_lat, dest_lon
definition = eval hv_rlat1 = pi()*$dest_lat$/180, hv_rlat2=pi()*$source_lat$/180, hv_rlat = pi()*($source_lat$-$dest_lat$)/180, hv_rlon= pi()*($source_lon$-$dest_lon$)/180 \
| eval hv_a = sin(hv_rlat/2) * sin(hv_rlat/2) + cos(hv_rlat1) * cos(hv_rlat2) * sin(hv_rlon/2) * sin(hv_rlon/2) \
| eval hv_c = 2 * atan2(sqrt(hv_a), sqrt(1-hv_a)) \
| eval distance = round(6371 * hv_c * 1000,0)\
| fields - hv_rlat, hv_rlat1, hv_rlat2, hv_rlon, hv_rlon1, hv_a, hv_c
iseval = 0

 Here's the distance from Sydney to San Francisco

| makeresults
| eval source_lat=-33.8688, source_lon=151.2093, dest_lat=37.7749, dest_lon=-122.4194
| `haversine(source_lat, source_lon, dest_lat, dest_lon)`
| eval distance_in_km=distance/1000
| table distance_in_km

Hope this helps

 

0 Karma

rcornett
New Member

@bowesmana awesome, thank you! I will give it ago and see if it works with our current application. Thank you 🙂

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

If it works for you, please remember to mark is as the solution, so others can make use of it

0 Karma
Get Updates on the Splunk Community!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...