meventcollect
Description
Converts events generated by streaming search commands into metric data points and inserts the data into a metric index on the indexers.
You can use the meventcollect
command only if your role has the run_mcollect
capability. See Define roles on the Splunk platform with capabilities in Securing Splunk Enterprise.
Syntax
meventcollect index=<string> [split=<bool>] [spool=<bool>] [prefix_field=<string>]
[host=<string>] [source=<string>] [sourcetype=<string>] [<field-list>]
Required arguments
- index
- Syntax: index=<string>
- Description: Name of the metric index where the collected metric data is added.
- field-list
- Syntax: <field>, ...
- Description: A list of dimension fields. Required if
split=true
. Optional ifsplit=false
. If unspecified (which implies thatsplit=false
), all fields are treated as dimensions for the data point, except for themetric_name
,prefix_field
, and all internal fields. - Default: No default value
Optional arguments
- split
- Syntax: split=<bool>
- Description: If set to false, the results must include a
metric_name
field for the name of the metric and a_value
field for the numerical value of the metric. If set to true, then<field-list>
must be specified. - Default: false
- spool
- Syntax: spool=<bool>
- Description: If set to true, the metrics data file is written to the Splunk spool directory,
$SPLUNK_HOME/var/spool/splunk
, where the file is indexed automatically. If set to false, the file is written to the$SPLUNK_HOME/var/run/splunk
directory. The file remains in this directory unless further automation or administration is done. - Default: true
- prefix_field
- Syntax: prefix_field=<string>
- Description: Only applicable when
split=true
. If specified, any data point with that field missing is ignored. Otherwise, the field value is prefixed to the metric name. - Default: No default value
- host
- Syntax: host=<string>
- Description: The name of the host that you want to specify for the collected metrics data. Only applicable when
spool=true
. - Default: No default value
- source
- Syntax: source=<string>
- Description: The name of the source that you want to specify for the collected metrics data.
- Default: If the search is scheduled, the name of the search. If the search is ad-hoc, the name of the file that is written to the
var/spool/splunk
directory containing the search results.
- sourcetype
- Syntax: sourcetype=<string>
- Description: The name of the source type that you want to specify for the collected metrics data.
- Default: metrics_csv
Do not change this setting without assistance from Splunk Professional Services or Splunk Support. Changing the source type requires a change to the
props.conf
file.
Usage
You use the meventcollect
command to convert events into metric data to be stored in a metric index on the indexers. The metrics data uses a specific format for the metrics fields. See
Metrics data format in Metrics.
Only streaming commands can precede the meventcollect
command so that results can be ingested on the indexers. If you would like to run a search that uses transforming commands to generate metric data points, use mcollect
instead of meventcollect
.
The meventcollect
command causes new data to be written to a metric index for every run of the search.
Splitting
If each result contains only one metric_name
field and one numeric _value
field, then the result is a normalized metric data point. This result can be consumed directly and does not need to be split. Otherwise, each result is split into multiple metric data points based on the specified list of dimension fields.
field-list
If field-list
is not specified, all fields are treated as dimensions for the data point, except for the prefix_field
and internal fields (fields with an underscore '_' prefix). If field-list
is specified, the list must appear at the end of the meventcollect
command arguments. If field-list
is specified, all fields are treated as metric values, except for the fields in field-list
, the prefix-field
, and internal fields.
The name of each metric value is the field name prefixed with the prefix_field
value.
Effectively, one metric data point is returned for each qualifying field that contains a numerical value. If one search result contains multiple qualifying metric name/value pairs, the result is split into multiple metric data points.
Examples
1: Collect metrics.log data into a metrics index
The following example shows you how to collect metrics log data into a metric index called 'my_metric_index'.
index=_internal source=*/metrics.log | eval prefix = group + "." + name | meventcollect index=my_metric_index split=true prefix_field=prefix name group
See also
metasearch | mstats |
This documentation applies to the following versions of Splunk® Enterprise: 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.1.10, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.2.10, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.3.6, 7.3.7, 7.3.8, 7.3.9
Feedback submitted, thanks!