Skip to content

Instantly share code, notes, and snippets.

@demmer
Last active August 29, 2015 14:09
Show Gist options
  • Save demmer/b95dee7e2fc52102192b to your computer and use it in GitHub Desktop.
Save demmer/b95dee7e2fc52102192b to your computer and use it in GitHub Desktop.
Live Joins

Live Joins

Juttle's powerful join functionality allows you to join your local data with data stored anywhere else. What's more, you can do streaming joins where points are joined as they come in.

Here we're counting the number of server errors triggered by each user_id and joining that data to an external customer data file.

Your Turn:

  • Try changing "first_name" to "last_name" on lines 11 and 12
  • Check out the raw data from the two data sources by commenting out line 18 and adding "@table" on line 19
export sub demo_events(from) {
demo cdn -every :1 second: -period :1 second:
-nhosts 2 -dos .9 -dos_dur 30 -dos_router markov -statusp {500:.3}
events -from from
}
import "data.juttle" as data;
// Calculate the number of errors per customer in 5 second intervals
sub server_errors_by_customer() {
data.demo_events -from :1 minute ago: |
filter name = "server_error" |
batch :5 seconds: |
reduce error_count = count() by cust_id
}
// Fetch the list of customer data mapping cust_id to real names
sub customer_info() {
source "https://gist.githubusercontent.com/davidbcook/56fea53b33120e2cd265/raw/462180c468c2533a00d2c22ca68e6c2e1e729f96/customer_data.json"
}
// Merge the two sources of data, attaching the customer info to each event count
(server_errors_by_customer ; customer_info) |
join on cust_id |
(@barchart -value error_count -category first_name -title "Errors by user";
@timechart -column error_count -by first_name -title "Errors by user over time")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment