Sumo Logic query editor
The Sumo Logic query editor lets you build and run metrics and logs queries against your Sumo Logic data. You can access the query editor from a dashboard panel by editing or adding a panel and selecting a Sumo Logic data source, or from the Explore page for ad-hoc queries. For metrics, the editor offers both a visual Builder mode and a raw Code mode. For logs, you write queries using the Sumo Logic Search Query Language.
Before you begin
- Configure the Sumo Logic data source.
- Verify your access credentials have permissions to query your Sumo Logic data.
Query types
The Sumo Logic query editor supports two query types, selectable using a radio button at the top of the editor:
- Metrics: Query time-series metrics data using the visual query builder or a raw query editor.
- Logs: Query log data using the Sumo Logic Search Query Language.
Metrics queries
Metrics queries return time-series data from the Sumo Logic Metrics API. When you select Metrics as the query type, the editor displays the following controls.
Query Mode
Use the Query Mode radio button to switch between Builder and Code mode:
- Builder: A visual interface for constructing metrics queries without writing raw query syntax.
- Code: A raw text editor for writing Sumo Logic metrics queries directly.
Rollup and quantization
The Rollup and Quantization settings appear on the same row and apply to both Builder and Code mode.
Builder mode
In Builder mode, you construct a query by selecting a metric, adding filters, and chaining operators.
Metric
Select a metric from the Metric drop-down. The drop-down is searchable and populates with available metrics from your Sumo Logic account based on the current dashboard time range.
Filters
Add filters to narrow your query to specific dimensions. Each filter has three components:
Click the + button to add a filter, or the x button to remove one. You can add multiple filters to a single query.
Operators
Add operators to transform, aggregate, or filter your metrics data. Click the + button to add an operator. Each operator type has different configuration options.
The following table describes the available operators and their options.
Code mode
In Code mode, the editor displays a raw text area where you write Sumo Logic metrics queries directly. The default query is * | count by metric.
Metrics queries use a pipe-delimited syntax where you specify a metric selector, then chain operators:
metric=cpu_idle department=sales | avg by hostFor more information about metrics query syntax, refer to the Sumo Logic metrics queries documentation.
Metrics query examples
The following examples demonstrate common query patterns. You can use these in either Builder or Code mode.
Basic aggregation
Average CPU idle time grouped by host:
metric=cpu_idle | avg by hostTotal request count across all services:
metric=http_requests | sum by serviceMaximum memory usage per host:
metric=mem_used_percent | max by hostStandard deviation of response times to detect variability:
metric=http_response_time | stddev by serviceFilter and aggregate
Filter by a specific department:
metric=cpu_idle department=sales | avg by hostFilter by multiple hosts using the in operator:
metric=cpu_idle host=(web-01,web-02,web-03) | avgTop-k and bottom-k
Return the top 5 hosts by memory usage:
metric=mem_used | topk(5, avg) by hostReturn the 3 least active services:
metric=http_requests | bottomk(3, sum) by serviceRates and deltas
Calculate the per-second rate of incoming bytes:
metric=net_bytes_recv | rate increasingCalculate the change in disk usage between consecutive data points:
metric=disk_used | deltaSmoothing and gap filling
Fill missing data points with the last known value:
metric=cpu_idle | avg by host | fillmissing lastApply exponentially weighted moving average to smooth noisy data:
metric=http_response_time | avg by service | ewma span 10Percentile and quantile
Calculate the 95th percentile of request latency:
metric=http_request_duration | pct(95) by serviceTime comparison and forecasting
Compare current values to the same time yesterday:
metric=cpu_idle | avg by host | timeshift 1dForecast future values using a linear model:
metric=disk_used_percent | avg by host | predict linear 24hFiltering results
Keep only time series where the average value exceeds a threshold:
metric=cpu_idle | filter avg > 90Filter using the current value:
metric=http_response_time | avg by service | where _value > 500Chaining operators
Chain multiple operators for complex analysis. Calculate the rate of errors, fill gaps, then smooth with EWMA:
metric=http_errors | rate increasing | fillmissing 0 | ewma span 5Aggregate by host, calculate the running cumulative sum:
metric=http_requests | sum by host | accumLogs queries
Logs queries use the Sumo Logic Search Query Language to search and analyze log data. The query editor provides a code editor for writing raw log queries. The default query is _index=*.
Fetch histogram data
Enable the Fetch histogram data toggle to retrieve histogram bucket data showing the distribution of log events over time. When this toggle is enabled, log messages and records aren’t returned – only the histogram data is included in the response.
Logs query examples
Basic searches
Search all logs in a specific index:
_index=my_indexSearch for error messages from a specific source:
_sourceCategory=prod/app "ERROR"Search across all sources for a specific error message:
"OutOfMemoryError" OR "heap space"Aggregation
Count errors by source host:
_sourceCategory=prod/app error | count by _sourceHostCount 5xx HTTP errors by status code and host:
_sourceCategory=prod/web status_code >= 500 | count by status_code, _sourceHostCalculate average response time from parsed fields:
_sourceCategory=prod/api | parse "duration=*ms" as duration | avg(duration) by _sourceHostFind the minimum and maximum response times:
_sourceCategory=prod/api | parse "duration=*ms" as duration | min(duration), max(duration) by endpointSum total bytes transferred:
_sourceCategory=prod/web | parse "bytes=*" as bytes | sum(bytes) by _sourceHostParsing and analysis
Parse structured log fields and count:
_sourceCategory=prod/api | parse "method=* url=* status=*" as method, url, status | count by method, statusFind the top 10 slowest API endpoints:
_sourceCategory=prod/api | parse "duration=*ms" as duration | top 10 url by avg(duration)Time-bucketed analysis
Use timeslice to create time-bucketed aggregations for time-series visualization:
_sourceCategory=prod/app error | timeslice 5m | count by _timesliceTrack error rate over time by severity:
_sourceCategory=prod/app | parse "level=*" as level | where level in ("ERROR", "FATAL") | timeslice 1m | count by _timeslice, levelSorting and limiting
Sort results by count in descending order:
_sourceCategory=prod/app error | count by _sourceHost | sort by _count descFor complete query syntax documentation, refer to the Sumo Logic Search Query Language.
Use Explore
You can use Explore to run ad-hoc metrics and logs queries without creating a dashboard. Explore is useful for debugging queries, investigating issues, and exploring your data.
For more information about working with logs in Explore, refer to Explore logs.



