Skip to content

Instantly share code, notes, and snippets.

@demmer
Created November 18, 2014 04:07
Show Gist options
  • Save demmer/27ac085dfe284e670d54 to your computer and use it in GitHub Desktop.
Save demmer/27ac085dfe284e670d54 to your computer and use it in GitHub Desktop.
Split and join flowgraphs

Split and Join Flowgraphs

Juttle programs enable you to answer questions in dynamic, changing environments by letting you split a stream of data, run different computations on each stream, and then join the two streams together again. These dynamic programs continually update their results, allowing you to follow hotspots around your environment or use one program output as a key for others.

This example finds the slowest host in the "search" service based on response time, every 10 seconds, and then gets a count of user requests running on that particular host.

Your Turn:

  • Try changing the service from "search" to "index".
  • Let's make sure we are in fact getting showing the slowest host:
    • Uncomment line 21
    • Add a ")" before the semicolon on line 22
export sub demo_metrics(from) {
demo cdn -every :1 second: -period :1 second:
-nhosts 5 -dos 0.7 -dos_router markov
metrics "response_ms" -from from
}
export sub demo_events(from) {
demo cdn -nhosts 5 -dos .7 -dos_router markov
events -from from
}
reducer slowest_host(value, host) {
var slowest_host_name = "";
var slowest_host_value = 0;
function update() {
if (*value > slowest_host_value) {
slowest_host_value = *value;
slowest_host_name = *host;
}
}
function result() {
return slowest_host_name;
}
}
import "data.juttle" as data;
( data.demo_metrics -from :1 minute ago: |
filter service = "search" |
batch 3 |
reduce p90 = percentile(value, .9) by host |
//(@timechart -column p90 -by host ;
reduce the_slowest_host = slowest_host(p90, host) ;
data.demo_events -from :1 minute ago: |
filter name = "server_error" && service = "search" |
batch 3 |
reduce error_count = count() by cust_id |
sort error_count -desc
) |
join |
(@barchart -value error_count -category cust_id -title "Count of server errors on the slowest host by customer ID";
reduce total_errors = sum(error_count) by the_slowest_host | @table
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment