Skip to content
SPL // Splunk

Using the mstats Command

KGI Avatar
 

Written by: Carlos Diez | Last Updated:

 
October 17, 2025
 
Search Command Of The Week: mstats
 
 

Originally Published:

 
October 17, 2025

Introduction: From Events to Metrics

Metrics data in Splunk provides a structured and high-performance way to analyze numeric time-series information. Unlike traditional event data, which stores raw text and contextual fields, metric indexes store measurements—such as CPU utilization, latency, or throughput—in an optimized format. 

This difference makes metrics ideal for high-volume monitoring and operational intelligence use cases. They are faster to query, lighter in storage, and particularly effective for dashboards that track continuous performance over time. 

Event data, on the other hand, excels in unstructured contexts where raw logs and textual data matter—like troubleshooting errors or tracing security alerts. By combining both, organizations can achieve deep observability and operational awareness. 

Introducing the Splunk Search Processing Language (SPL)

Splunk’s Search Processing Language (SPL) is the foundation of its data analysis capabilities. It enables users to query, transform, and visualize data interactively across different data types, including metrics. 

When working with metric data, the primary command used is mstats. This command allows efficient aggregation and analysis of measurements stored in metric indexes, similar to how stats operates on event data. 

In practice, mstats helps analysts monitor system performance, detect anomalies, and visualize trends without processing the heavy event payloads. 

Understanding the Commands

The mstats command is the core tool for searching metrics indexes. It retrieves aggregated values, such as averages, sums, or maximums, from numeric measurements. Because metrics are indexed as numeric key-value pairs, the mstats command can calculate results quickly, even across massive datasets. 

Common aggregation functions include: 

  • avg() – returns the average value of a metric 
  • max() – identifies the highest value in a time range 
  • sum() – computes the total of all metric values 

You can also apply filters, group by dimensions (like host or index), and combine it with time-based commands like timechart. 

Benefits of Using the mstats Command

Regularly using mstats can improve your Splunk efficiency in many ways: 

  • Faster performance: Metric searches are optimized for numeric calculations, reducing search time compared to event-based queries. 
  • Improved scalability: Since metrics consume less storage and index space, you can retain longer data histories for trend analysis. 
  • Enhanced observability: With cleaner data models, metrics make it easier to correlate infrastructure and application performance. 

Basic Syntax

The basic syntax of the mstats command is straightforward: 

				
					| mstats [aggregations] WHERE [criteria] BY [dimensions]
				
			

For example:

				
					| mstats avg(cpu_usage) WHERE index=metrics AND host=* BY host
				
			

Here, avg(cpu_usage) defines the aggregation function, WHERE limits the search to specific data, and BY organizes results by a chosen field. 

Usage Examples

Example #1: Monitoring CPU Utilization Across Hosts

When monitoring system health, analysts often need to check CPU usage by host. 

				
					| mstats avg(cpu.utilization) WHERE index=os_metrics BY host
				
			

This query calculates the average CPU utilization per host from a metrics index. It’s useful for identifying systems under high load. 

Example #2: Querying CIM-Compliant Performance Data

You can align metrics searches with the Splunk Common Information Model (CIM) for consistency. 

For instance, the Performance data model includes metrics such as memory and CPU usage, so you can extract that data with the proper field names based on CIM compliance. 

				
					| mstats max(cpu.utilization) WHERE index=os_metrics BY host 
| rename cpu.utilization AS "CPU Utilization (%)"
				
			

This example retrieves the highest CPU usage per host and formats the field for dashboard presentation. 

Example #3: Visualizing Network Throughput Trends

To observe changes in network performance over time, use timechart with mstats: 

				
					| mstats sum(network.bytes) WHERE index=net_metrics BY interface 
| timechart span=5m sum(network.bytes) BY interface
				
			

This produces a time-based visualization of total network throughput by interface, helping identify spikes or degradations. 

Conclusion

Metric indexes and the mstats command bring precision and efficiency to Splunk analysis. They allow teams to focus on numeric trends rather than unstructured log data, supporting faster insights and better resource optimization. 

Key Takeaways: 

  • Metrics data enables faster and more efficient performance monitoring. 
  • The mstats command is the cornerstone of metric analysis in Splunk. 
  • Combining metrics and events enhances overall observability and operational intelligence. 

To access more Splunk searches, check out Atlas Search Library, which is part of the Atlas Platform. Specifically, Atlas Search Library offers a curated list of optimized searches. These searches empower Splunk users without requiring SPL knowledge. Furthermore, you can create, customize, and maintain your own search library. By doing so, you ensure your users get the most from using Splunk.

Helpful? Don't forget to share this post!
LinkedIn
Reddit
Email
Facebook