New Composite Metrics Language Functions — Librato Blog

New Composite Metrics Language Functions

Earlier this year we announced the Composite Metrics feature, introducing a new way for users to build dynamic metrics using a composition of aggregate functions, statistical primitives and mapping constructs. These have been hugely popular, adding an exciting dimension to Librato instruments and dashboards.

We’re pleased to announce our latest batch of functions to the Composite Metrics language: timeshift(), window(), integrate(), and multiply().


One of my favorite new functions, timeshift() allows you to shift one or more series “back in time”. Given a single interval definition, it returns each series offset by that amount. But the real power of this function is revealed when you pass it multiple offsets.

Say we wanted to trend one of your CPU metrics for the last 24-hours over each of the past four weeks. In this example I've aggregated all of our sources into a single stream with mean() and passed it with our series of offsets to the timeshift() function.


timeshift("0,1,2,3w", mean(s("AWS.ElastiCache.CPUUtilization", "%")))

Someone deployed some nice code a week ago!


The window() function is handy for calculating the moving average of one or more series over time. It accepts size and an aggregation function inside the options map.

For this next example I wanted to compare the week-over-week outliers for one of our 99th percentile metrics. I want to see how the "worst of the worst" are trending over time, but we also want to smooth it out just a bit so we can more easily compare the series.

We take the original p99 metric and grab the max() values before smoothing them out with window(), setting our window size to 10 datapoints. Lastly we'll pass them into timeshift() again to see how we're trending.


timeshift("0,1,2,3w", window(max(s("api.auth.time.p99", "*")), {size: "10"}))

Not bad for outliers, our moms would be proud.


The integrate() function accepts one or more series and performs a cumulative sum over the series. In layman's terms, it transforms a rate into a counter value. This can be handy for tracking those really important metrics, like the total number of times someone mentions Librato on Twitter (:wink:).


integrate(sum(s("twitter.mentions", "*")))

I can feel the love.


Our multiply() function does what the name implies; it returns a single series where each value is the product of multiplying the values at that point in time for each of the input series.

We can use multiply() to find a rough estimate for the amount of time spent on cache misses. First we calculate the percentage of misses among all get requests, and then multiply the result against the amount of time spent processing all get requests. Of course, this assumes the amount of time it takes to process both hits and misses is roughly equal (a bad assumption but acceptable for our example).


  sum(s("api.cache.collectd.get.misses", "*")), 
  sum(s("api.cache.collectd.get.hits", "*"))
  sum(s("api.cache.collectd.get.time", "*"))

Time spent caching is time well spent.

I hope you find these new functions as useful as we have. We're continuing to roll out enhancements to our composite metrics language, so we welcome your ideas and suggestions on our Support site.

For more information on composite metrics and our other features, check out our Knowledge Base articles. And as always, if you still have questions about this or any of our services, you can find us online in our support chat or email us at