Splunk 7.0.0 Metrics Metrics 2
Splunk 7.0.0 Metrics Metrics 2
0
Generated: 11/17/2017 3:57 pm
i
Introduction to metrics
Overview of metrics
Metrics is a feature for system administrators and IT tools engineers that focuses
on collecting, investigating, monitoring, and sharing metrics from your technology
infrastructure, security systems, and business applications in real time.
Metrics in the Splunk platform uses a custom index type that is optimized for
metric storage and retrieval. To work with metrics, the mstats search command is
included for you to apply numeric aggregations (such as avg, sum, percentile,
and so forth) to isolate and correlate problems from different data sources.
What is a metric?
timestamp
Indicates when a metric measurement was taken.
metric name
Uses a dotted hierarchy to refer to a namespace (for example,
nginx.upstream.responses.5xx). Any string can be used as metric name.
We recommend that metric names only include lowercase letters,
numbers, underscores, and dots. Dots are used to separate segments of
the namespace to create a hierarchy of metrics.
value
A numeric data point representing the value of a metric such as a count,
or calculated value for a specific time resolution such as a percentile for a
response time metric for the last minute.
dimensions
Provide metadata about the metric. For example:
Region: us-east-1, us-west-1, us-west-2, us-central1
InstanceTypes: t2.medium, t2.large, m3.large, n1-highcpu-2
Technology: nginx, redis, tomcat
You can think of a metric name as something that you are measuring, while
dimensions are categories by which you can filter or group the results.
1
IT infrastructure, such as hosts, networks, and devices
System components, such as web servers and databases
Application-specific metrics, such as timers that measure performance of
a function
SaaS
Sensors, such as IoT
For examples of metrics data in the Splunk platform, see Get metrics data in.
Both of these tools are light weight and easy to use, and they have a large
2
community of support. If you want to start gathering performance metrics from
your applications and systems, review these tools to determine whether either of
them suits your environment.
If you prefer to use a different metrics-gathering tool, you can still use the Splunk
platform to collect and analyze your data with manual configuration.
Writeable
Field Required or Description Example
Internal
metric_name X Writeable The metric name. os.cpu.user
The timestamp of the
2017-08-14
_time X Writeable metric in UNIX time
17:12:39.000
notation.
The numeric value of the
metric. This field is a
64-bit floating point
_value X Writeable 42.12345
number, which supports
precision between 15
and 17 decimal digits.
<dimension 0> An arbitrary number of
... X Writeable fields, indicating how ip
<dimension n> metrics can be split.
An auto-generated
internal field that
contains the names of
all of the dimensions in
_dims X Internal the metric event. The _dims::ip
purpose of this field is to
return a list of unique
dimension names in a
metrics index.
The type of metric. Only
metric_type Writeable g
"g" (gauge) is supported.
source Internal The source of the udp:8125
3
metrics data.
The origin host. A
host X Internal standard field in Splunk server007
software.
The metrics index name.
index X Internal A standard field in metricsindex
Splunk software.
The data structure of the
sourcetype X Internal metric. A standard field statsd
in Splunk software.
Supported line protocols
Metrics in the Splunk platform natively supports the following metric line
protocols:
For details about getting data in, see Get metrics in from StatsD and Get metrics
in from collectd.
To support other line metric protocols, you can use custom transformations to get
metrics data into Splunk platform from other tools. For details, see Get metrics
from other clients.
The Splunk platform includes the following pre-trained source types to support
the most widely-supported line metric protocols:
4
Source type
Description
name
Supports data using the metric line protocols for plain StatsD
statsd
and the StatsD extension with dimensions.
collectd_http Supports data using the metric line protocol for collectd.
Supports data in CSV format. For usage details, see Get
metrics_csv
metrics in from other sources.
Metrics index
There is no default metrics index. Summary indexing does not work with metrics.
To learn more, see Create metrics indexes in the Managing Indexers and
Clusters of Indexers manual.
For information about how metrics data is metered, see How Splunk Enterprise
licensing works in the Admin Manual.
To analyze data and enumerate items in a metrics index, use the mstats and
mcatalog search commands. Other search commands that work with events do
not work with metrics. For example, the delete command does not work with
metrics. For more about searching a metrics index, see Search and monitor
metrics.
Administrative CLI commands may not all work with metrics. You can use
commands such as add index and list index with metrics when using the
-datatype metric parameter. See Create metrics indexes in the Managing
Indexers and Clusters of Indexers manual.
5
Get metrics data in
<metric_name>:<_value>|<metric_type>
Example metric:
performance.os.disk:1099511627776|g
<metric_name>:<_value>|<metric_type>|#dim1:valueX,dim2:valueY
Example metric:
performance.os.disk:1099511627776|g|#region:us-west-1,datacenter:us-west-1a,rack:6
path:/dev/sdal,fstype:ext3
For more about formats for metric names and dimensions, see Best practices for
metrics.
If you use a StatsD implementation that uses a different format for dimensions
from the ones that the Splunk platform supports natively, for example one that
embeds dimensions within the metric name, you can still use metrics in the
Splunk platform. However, you'll need to customize Splunk configuration files to
specify how to extract dimensions from your format.
Another option is to use StatsD to gather metrics, but use collectd to send the
data to the Splunk platform over HTTP. The benefit of this method is that collectd
6
normalizes the dimension format in the metrics data. For more, see Get metrics
in from collectd.
After you configure your data source to send data in the StatsD protocol, create a
UDP or TCP data input in the Splunk platform to listen for StatsD data on an
open port.
When using UDP ports to ingest metric data, you cannot use parallel
ingestion or the multiple pipeline sets feature.
3. For Port, enter the number of the port you are using for StatsD.
4. Click Next.
5. Click Select Source Type, then select Metrics > statsd.
6. For Index, select an existing metrics index. Or, click Create a new index
to create one.
If you choose to create an index, in the New Index dialog box:
1. Enter an Index Name. User-defined index names must consist of
only numbers, lowercase letters, underscores, and hyphens. Index
names cannot begin with an underscore or hyphen.
2. For Index Data Type, click Metrics.
3. Configure additional index properties as needed.
4. Click Save.
7. Click Review, then click Submit.
Many StatsD clients embed dimension names in the metric name. For example,
let's say your StatsD client uses the following line metric protocol format, which is
not supported natively by the Splunk platform:
<dimension>.<metric_name>:<value>|<metric_type>
10.1.1.198.cpu.percent:75|g
7
metric_name=cpu.percent
_value=75
metric_type=g
ip=10.1.1.198
To create the correct results, you must edit Splunk configuration files or use the
REST API to create a custom source type that specifies how to extract
dimensions from this metrics data.
# props.conf
[<metrics_sourcetype_name>]
METRICS_PROTOCOL = statsd
STATSD-DIM-TRANSFORMS =
<statsd_dim_stanza_name1>,<statsd_dim_stanza_name2>...
metrics_sourcetype_name: The name of your custom
metrics source type.
statsd_dim_stanza_name: A comma-separated list of
transforms stanza names that specify how to extract
dimensions. If only one stanza is used for the source type,
and if the transforms stanza name is same as the
metrics_sourcetype_name, this
STATSD-DIM-TRANSFORMS setting can be omitted.
2. Define one or more regular expressions to extract the dimensions from
metric_name.
1. In a text editor, open the transforms.conf configuration file from the
local directory for the location you want to use, such as the Search
& Reporting app ($SPLUNK_HOME/etc/apps/search/local/) or from
the system ($SPLUNK_HOME/etc/system/local). If a
transforms.conf file does not exist in this location, create a text file
and save it to that location.
8
2. Append a stanza for each regular expression as follows:
# transforms.conf
[statsd-dims:<unique_transforms_stanza_name>]
REGEX = <regular expression>
REMOVE_DIMS_FROM_METRIC_NAME = <Boolean>
unique_transforms_stanza_name: A unique name for this
stanza.
REGEX = <regular expression>: A regular expression that
defines how to match and extract dimensions from StatsD
metrics data. The Splunk platform supports a named
capturing-group extraction format
(?<dim1>group)(?<dim2>group)... to provide dimension
names for the corresponding values that are extracted.
REMOVE_DIMS_FROM_METRIC_NAME = <Boolean>:
Specifies whether unmatched segments of the StatsD dotted
name segment are used as the metric_name.
For more about editing these configuration files, see About configuration files,
props.conf, and transforms.conf in the Admin Manual.
data=mem.percent.used.10.2.3.4.windows:33|g
9
If you defined two regular expressions, one for "ipv4" and one for "os", you would
append the following stanzas to your configuration files:
# props.conf.example
[my_custom_metrics_sourcetype]
METRICS_PROTOCOL = statsd
STATSD-DIM-TRANSFORMS = regex_stanza1, regex_stanza2
# transforms.conf.example
[statsd-dims:regex_stanza1]
REGEX = (?<ipv4>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})
REMOVE_DIMS_FROM_METRIC_NAME = true
[statsd-dims:regex_stanza2]
REGEX = \S+\.(?<os>\w+):
REMOVE_DIMS_FROM_METRIC_NAME = true
Now let's say you can accomplish this same extraction using a single regular
expression. In this case, you would append the following stanzas to your
configuration files:
# props.conf.example
[my_custom_metrics_sourcetype]
METRICS_PROTOCOL = statsd
# transforms.conf.example
[statsd-dims:my_custom_metrics_sourcetype]
REGEX = (?<ipv4>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\.(?<os>\w+):
REMOVE_DIMS_FROM_METRIC_NAME = true
Notice that the STATSD-DIM-TRANSFORMS setting in the props.conf
configuration file is not needed when only a single regular expression is used for
a source type.
1. Define a custom source type for your StatsD metrics data by using the
/services/saved/sourcetypes REST endpoint:
https://<host>:<mPort>/services/saved/sourcetypes \
-d
"name=<metrics_sourcetype_name>&METRICS_PROTOCOL=statsd&STATSD-DIM-TRANSFORMS=<sta
metrics_sourcetype_name: The name of your custom metrics
source type.
statsd_dim_stanza_name: A list of transforms stanza names that
specify how to extract dimensions. If only one stanza is used for the
10
source type, and if the transforms stanza name is same as the
metrics_sourcetype_name, this STATSD-DIM-TRANSFORMS
setting can be omitted.
For example, enter the following command:
curl -k -u admin:changeme
https://localhost:8089/services/saved/sourcetypes \
-d
"name=statsd_custom&METRICS_PROTOCOL=statsd&STATSD-DIM-TRANSFORMS=statsd-ex&SHOULD
2. Create one or more regular expressions to extract the dimensions from
metric_name by using the /data/transforms/statsdextractions REST
endpoint:
https://<host>:<mPort>/services/data/transforms/statsdextractions
\
-d "name=<unique_transforms_stanza_name>®EX=<regular
expression>&REMOVE_DIMS_FROM_METRIC_NAME=<Boolean>"
unique_transforms_stanza_name: A unique name for this stanza.
REGEX = <regular expression>: A regular expression that defines
how to match and extract dimensions from StatsD metrics data.
The Splunk platform supports a named capturing-group extraction
format (?<dim1>group)(?<dim2>group)... to provide dimension
names for the corresponding values that are extracted.
REMOVE_DIMS_FROM_METRIC_NAME = <Boolean>: Specifies
whether unmatched segments of the StatsD dotted name segment
are used as the metric_name.
curl -k -u admin:changeme
https://localhost:8089/services/data/transforms/statsdextractions
11
\
-d
"name=statsd-ex®EX=\.(?<hostname>\S%2B?)\.(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1
3. Reload the metrics processor to load the configuration changes by using
the /admin/metrics-reload/_reload REST endpoint:
https://<host>:<mPort>/services/admin/metrics-reload/_reload
For example, enter the following command:
curl -k -u admin:changeme \
https://localhost:8089/services/admin/metrics-reload/_reload
4. Create a data input for this source type as described in Set up a data input
for StatsD data, and select your custom source type.
For more about using the Splunk REST API, see Using the REST API reference,
/data/transforms/statsdextractions, and /admin/metrics-reload/_reload in the
REST API Reference Manual.
The HTTP Event Collector (HEC) is an endpoint that lets you send application
events to your deployment of the Splunk platform using the HTTP or Secure
HTTP (HTTPS) protocols. Configure this data input before setting up collectd
because you'll need to use data input details for the collectd configuration.
12
1. Click Global Settings.
2. For All Tokens, click Enabled if this button is not already selected.
3. Note the value for HTTP Port Number, which you'll need to
configure collectd.
4. Click Save.
4. Configure an HEC token for sending data by clicking New Token.
5. On the Select Source page, for Name, enter a token name, for example
"collectd token".
6. Leave the other options blank or unselected.
7. Click Next.
8. On the Input Settings page, for Source type, click Select.
9. Click Select Source Type, then select Metrics > collectd_http.
10. Next to Default Index, select your metrics index, or click Create a new
index to create one.
If you choose to create an index, in the New Index dialog box:
1. Enter an Index Name. User-defined index names must consist of
only numbers, lowercase letters, underscores, and hyphens. Index
names cannot begin with an underscore or hyphen.
2. For Index Data Type, click Metrics.
3. Configure additional index properties as needed.
4. Click Save.
11. Click Review, and then click Submit.
12. Copy the Token Value that is displayed, which you'll need to configure
collectd.
To test your data input, you can send collectd events directly to your metrics
index using the /collector/raw REST API endpoint, which accepts data in the
collectd JSON format. Your metrics index is assigned to an HEC data input that
has its unique HEC token, and "collectd_http" as its source type.
The following example shows a curl command that sends a collectd event to the
index associated with your HEC token:
curl -k
https://localhost:8088/services/collector/raw?sourcetype=collectd_http
\
-H "Authorization: Splunk <HEC_token>"
\
-d
'[{"values":[164.9196798931339196],"dstypes":["derive"],"dsnames":["value"],"time":15053
13
You can verify the HEC data input is working by running a search using mcatalog
to list all metric names, with the time range set to ?All Time?, for example:
Or, use the Metrics Catalog REST endpoint to list metric names:
curl -k -u <admin:passwd>
"https://localhost:8089/services/catalog/metricstore/metrics?earliest=0"
See Getting data in with HTTP Event Collector and Event formatting on the
Splunk Developer Portal. See mstats and mcatalog in the Search Reference
manual. See Metrics Catalog endpoint descriptions, /collector, /collector/raw in
the REST API Reference Manual.
Install collectd
Install the collectd agent on the computers in your system from which you want to
collect metrics.
Configure collectd
The collectd server is an optional daemon that can be used to aggregate metrics
from different inputs and one-to-many collectd clients.
The write_http plugin requires the following fields from your HEC data input:
Field
Description Syntax
name
URL URL to URL URL
which the "https://<Splunk_host>:<HTTP_port>/services/collector/raw" "https://10.66.
14
values are
submitted.
This URL
includes
your Splunk
host
machine (IP
address,
host name,
or load
balancer
name), and
the HTTP
port
number.
An HTTP
header to Header "Auth
Header Header "Authorization: Splunk <HEC_token>"
add to the b0221cd8-c4b
request.
The format
Format Format "JSON" Format "JSON
of the data.
Enable and configure plugins
You might need to install some plugins separately, depending on your installation
method and operating system. For details, see the collectd website.
15
ReportRelative true
</Plugin>
LoadPlugin logfile
<Plugin logfile>
LogLevel info
logfile File STDOUT
Timestamp true
PrintSeverity false
</Plugin>
LoadPlugin memory
<Plugin memory>
memory ValuesAbsolute true
ValuesPercentage true
</Plugin>
LoadPlugin network
network Enable this plugin only if the collectd client is not on the same
machine as the connectd server, then use the default configuration.
LoadPlugin syslog
syslog
Use the default configuration.
You need the values from your HEC data input to configure this
plugin. LoadPlugin write_http
<Plugin write_http>
<Node "node1">
URL
"https://<Splunk_host>:<HTTP_port>/services/collector/raw"
write_http Header "Authorization: Splunk <HEC_token>"
Format "JSON"
VerifyPeer false
VerifyHost false
Metrics true
StoreRates true
</Node>
</Plugin>
Start collectd
To start collectd, follow the instructions under "Starting the daemon" on the First
steps page on the collectd website.
Modules for all of the enabled plugins in your collectd.conf file must be installed.
Errors are displayed for any modules that are missing. For more about the
available collectd plugins, see Table of Plugins on the collectd Wiki website.
16
Install modules according to your operating system. For example, on Linux you
must install collectd-write_http.x86_64 to use the write_http plugin.
Tips:
For troubleshooting, refer to the collectd log file enabled by the logfile
plugin for details.
Use the File setting in the logfile plugin to write to a specified file rather
than to standard output. For example:
<Plugin logfile>
LogLevel info
File "/var/log/collectd.log"
Timestamp true
PrintSeverity false
</Plugin>
If you are installing collectd on Linux, you can use yum to list available
modules. For example, use this CLI command:
yum list | grep collectd
In the collectd.conf file, set the FQDNLookup setting to false to render a
friendly name for the domain name.
If your metrics data is in CSV format, use the metrics_csv pre-trained source
type. Your CSV data must contain the following fields.
17
To add CSV data to a metrics index, create a data input with the following:
See Monitor files and directories in the Getting Data In manual, and Create
metrics indexes in the Managing Indexers and Clusters of Indexers manual.
You can add metrics data from a client that is not natively supported to a metrics
index by manually configuring a source type for your data, then defining regular
expressions to specify how the Splunk software should extract the required
metrics fields. See Metrics data format.
For example, let's say you are using Graphite. The Graphite plaintext protocol
format is:
To index these metrics, edit Splunk configuration files to manually specify how to
extract fields.
# props.conf
[<metrics_sourcetype_name>]
TIME_PREFIX = <regular expression>
TIME_FORMAT = <strptime-style format>
18
TRANSFORMS-<class> = <transform_stanza_name>
NO_BINARY_CHECK = true
SHOULD_LINEMERGE = false
pulldown_type = 1
category = Metrics
metrics_sourcetype_name Name of your custom metrics
source type.
TIME_PREFIX = regular expression: A regular expression
that indicates where the timestamp is located.
TIME_FORMAT = strptime-style format: A strptime format
string used to extract the date. For more about strptime, see
Configure timestamp recognition in the Getting Data In
manual.
TRANSFORMS-<class> = <transform_stanza_name>: class
is a unique literal string that identifies the namespace of the
field to extract. transform_stanza_name is the name of the
name of your stanza in transforms.conf that indicates how to
extract the field.
2. Define a regular expression for each metrics field to extract.
1. In a text editor, open the transforms.conf configuration file from the
local directory for the location you want to use, such as the Search
& Reporting app ($SPLUNK_HOME/etc/apps/search/local/) or the
system ($SPLUNK_HOME/etc/system/local). If a transforms.conf
file does not exist in this location, create a text file and save it to
that location.
2. Append a stanza for each regular expression as follows:
# transforms.conf
[<transform_stanza_name>]
REGEX = <regular expression>
FORMAT = <string>
WRITE_META = true
transform_stanza_name: A unique name for this stanza.
REGEX = <regular expression>: A regular expression that
defines how to match and extract metrics fields from this
metrics data.
FORMAT = <string>: A string that specifies the format of the
metrics event.
3. Create a data input for this source type as described in Set up a data input
for StatsD data, and select your custom source type.
For more about editing these configuration files, see About configuration files,
props.conf, and transforms.conf in the Admin Manual.
19
Example of configuring field extraction
This example shows how to create a custom source type and regular
expressions to extract fields from Graphite metrics data.
# props.conf.example
[graphite_plaintext]
TIME_PREFIX = \s(\d{0,10})$
TIME_FORMAT = %s
NO_BINARY_CHECK = true
SHOULD_LINEMERGE = false
pulldown_type = 1
TRANSFORMS-graphite-host = graphite_host
TRANSFORMS-graphite-metricname = graphite_metric_name
TRANSFORMS-graphite-metricvalue = graphite_metric_value
category = Metrics
# transforms.conf.example
[graphite_host]
REGEX = ^(\S[^\.]+)
FORMAT = host::$1
DEST_KEY = MetaData:Host
[graphite_metric_name]
REGEX = \.(\S+)
FORMAT = metric_name::graphite.$1
WRITE_META = true
[graphite_metric_value]
REGEX = \w+\s+(\d+.?\d+)\s+
FORMAT = _value::$1
WRITE_META = true
Get metrics in from clients over HTTP or HTTPS
If you want to send metrics data in JSON format from a client that is not natively
supported to a metrics index over HTTP or HTTPS, use the HTTP Event
Collector (HEC) and the /collector REST API endpoint.
20
4. Configure an HEC token for sending data by clicking New Token.
5. On the Select Source page, for Name, enter a token name, for example
"Metrics token".
6. Leave the other options blank or unselected.
7. Click Next.
8. On the Input Settings page, for Source type, click New.
9. In Source Type, type a name for your new source type.
10. For Source Type Category, select Metrics.
11. Optionally, in Source Type Description type a description.
12. Next to Default Index, select your metrics index, or click Create a new
index to create one.
If you choose to create an index, in the New Index dialog box:
1. Enter an Index Name.
2. For Index Data Type, click Metrics.
3. Configure additional index properties as needed.
4. Click Save.
13. Click Review, and then click Submit.
14. Copy the Token Value that is displayed. This HEC token is required for
sending data.
See Getting data in with HTTP Event Collector on the Splunk Developer Portal.
Use the /collector REST API endpoint and your HEC token to send data
directly to a metrics index as follows:
http://<Splunk_host>:<HTTP_port>/services/collector \
-H "Authorization: Splunk <HEC_token>"
\
-d "<metrics_data>"
You need to provide the following values:
Splunk host machine (IP address, host name, or load balancer name)
HTTP port number
HEC token value
Metrics data, which requires an "event" field set to "metric".
For more about HEC, see Getting data in with HTTP Event Collector and Event
formatting on the Splunk Developer Portal.
21
For more about the /collector endpoint, see /collector in the REST API
Reference Manual.
curl -k https://localhost:8088/services/collector \
-H "Authorization: Splunk b0221cd8-c4b4-465a-9a3c-273e3a75aa29" \
-d '{"time":
1486683865.000,"event":"metric","source":"disk","host":"host_99","fields":{"region":"us-
22
Work with metrics
Search examples
23
| mstats avg(_value) WHERE index=mymetricdata AND
metric_name=aws.ec2.CPUUtilization span=30s
You can also display results in a chart. The following example uses a wildcard
search and group by:
This type of search can be used to stack different CPU metrics that add up to
100%.
| mcatalog values(metric_name)
| mcatalog values(_dims)
You can also use the Metrics Catalog REST API endpoints to enumerate metrics
data:
24
Use the GET
/services/catalog/metricstore/dimensions/{dimension-name}/values
endpoint to list values for given dimensions.
You can also use filters with these endpoints to limit results by index, dimension,
and dimension values.
See Metrics Catalog endpoint descriptions in the REST API Reference Manual.
Size on disk
Throughput
Using the collectd_http source type with an HTTP Event Collector (HEC)
input, testing reached a constant of around 55,000 events per second
maximum ingestion throughput, and around 58,000 events per second
without additional search load.
The default batch size was 5,000 events per batch. A significant
difference in ingestion performance was not observed between
batch sizes of 100 to 5,000 events.
The keep-alive setting was enabled for these tests.
A typical event size was about 214 bytes.
Using the statsd source type with a UDP input, throughput was highly
variable depending on other network activity. For UDP inputs we
recommend using a universal forwarder as close as possible to where
metrics are collected.
Speed
25
Consider the results from the following test for running metrics queries.
This test used metrics from 1,000 hosts, with a total event count of 6
billion events in the metrics index, where queries were representative and
did not use wildcards in metric_name.
For better performance, use the StatsD format with dimensions extension
(cpu.idle:0.5|g|#host:some-hostsplunk.com,app:some-app) rather than
the plain StatsD format that combines dimensions with the metric name
(cpu.idle.some-hostsplunk.com.some-app).
The _value field of a metric should be of type "Double", not type "String",
to avoid causing indexing inefficiencies.
For a faster response time for REST calls, provide a time window when
calling the Metrics Catalog endpoint. By default, only the last 24 hours of
data is searched because this endpoint searches metadata, which does
not typically change often. See Metrics Catalog endpoint descriptions in
the REST API Reference Manual.
26
Make sure dimension names do not start with underscore ( _ ), because
they will not be indexed.
27