Metric Expression Functions

Metric expressions support the functions listed in the following table. A function can return a time series or a scalar computed from a time series. Functions that return scalars must be used for heatmap charts.

Function Returns Scalar? Description
avg(metric expression) N Computes a simple average for a time series.
count_service_roles() Y Returns the number of roles. There are three variants of this function:
  • count_service_roles(roleType, roleState) - Returns the number of roles of the specified roleType and roleState . For example, count_service_roles(datanode, running) returns the number of running DataNodes.
  • count_service_roles(roleType) - Returns the number of roles with the specified roleType.
  • count_service_roles() - Return the number of roles. For example, select events_critical where count_service_roles() > 100 returns the event_critical metric when the number of roles is greater than 100.
dt(metric expression) N Derivative with negative values. The change of the underlying metric expression per second. For example: dt(jvm_gc_count).
dt0(metric expression) N Derivative where negative values are skipped (useful for dealing with counter resets). The change of the underlying metric expression per second. For example: dt0(jvm_gc_time_ms) / 10.
getClusterFact(string factName, double defaultValue) Y Retrieves a fact about a cluster. Currently supports one fact: numCores. If the number of cores cannot be determined, defaultValue is returned.
getHostFact(string factName, double defaultValue) Y Retrieves a fact about a host. Currently supports one fact: numCores. If the number of cores cannot be determined, defaultValue is returned.

For example, select dt(total_cpu_user) / getHostFact(numCores, 2) where category=HOST divides the results of dt(total_cpu_user) by the current number of cores for each host.

The following query computes the percentage of total user and system CPU usage each role is using on the host. It first computes the CPU seconds per second for the number of cores used by taking the derivative of the total user and system CPU times. It normalizes the result to the number of cores on the host by using the getHostFact function and multiplies the result by 100 to get the percentage.
select dt0(total_cpu_user)/getHostFact(numCores,1)*100,
dt0(total_cpu_system)/getHostFact(numCores,1)*100 
where category=ROLE and clusterId=1
greatest(metric expression, scalar metric expression) N Compares two metric expressions, one of which one is a scalar metric expression. Returns a time series where each point is the result of evaluating max(point, scalar metric expression).
integral(metric expression) N Computes the integral value for a stream and returns a time-series stream within which each data point is the integral value of the corresponding data point from the original stream. For example, select integral(maps_failed_rate) will return the count of the failed number of maps.
counter_delta(metric expression) N Computes the difference in counter value for a stream and returns a time-series stream within which each data point is the difference in counter value of the corresponding data point from the counter value of previous data point in the original stream. For example: select counter_delta(maps_failed_rate) returns the count of the failed number of maps. This method is more accurate than the integral() function. However there are a few caveats:
  • This function is only implemented for single time-series streams. For streams of cross-entity aggregates, continue to use the integral() function.
  • If you apply this method for time-series streams which was created using a version of Cloudera Manager older than 5.7, Cloudera Manager fills in the older data points using the integral() function.
last(metric expression) Y Returns the last point of a time series. For example, to use the last point of the cpu_percent metric time series, use the expression select last(cpu_percent).
least(metric expression, scalar metric expression) N Compares two metric expressions, of which one is a scalar metric expression. Returns a time series where each point is the result of evaluating min(point, scalar metric expression).
max(metric expression) Y Computes the maximum value of the time series. For example, select max(cpu_percent).
min(metric expression) Y Computes the minimum value of the time series.
moving_avg(metric expression, time_window_sec) N Computes the moving average for a time series over a time window time_window_sec specified in seconds (2, 0.1, and so on)
stats(metric expression, stats name) N Some time-series streams have additional statistics for each data point. These include rollup time-series streams, cross-entity aggregates, and rate metrics. The following statistics are available for rollup and cross-entity aggregates: max, min, avg, std_dev, and sample. For rate metrics, the underlying counter value is available using the "counter" statistics. For example, stats(fd_open_across_datanodes, max) or stats(swap_out_rate, counter).
sum(metric expression) Y Computes the sum value of the time-series.