logs-to-metrics

Practical Logs to Metrics Conversion With Cribl LogStream

Last edited: August 12, 2019

When monitoring your infrastructure, applications, users, devices, sensors etc. you’re likely to be using a variety of data sources and a number of monitoring tools to get the full picture. Oftentimes data is messy and chances are that you have instrumentation measurements embedded into log lines. That’s not necessarily a bad thing, but if you care principally about metrics those values can be extracted and send to a metrics store instead of a logging system. Metrics stores tend to be way leaner in terms of storage requirements and offer better analysis experience and vastly faster performance.

This is a no-frills, no-BS post on how you can use Cribl Logstream to visually author conversion of logs into metrics.

logs-to-metrics

Let’s define a metric

A metric at its core is a record/event that contains a name, a value, a timestamp and one or more dimensions. The name is the name of the metric of interest, the value is its value at the given timestamp and dimensions represent metadata about the metric (i.e. groups that will be used to aggregate the values by). Here’s a meta-example:

Code example
timestamp:1565558300 | name:net.bytes | value:1024 | dimensions:OU=BigCo,Location=US,Region:us-east-1,AZ=us-east-1d

Steps to convert logs to metrics

  1. Extract fields of interest using Regex Extract or Parser functions.

  2. Select fields that will become metrics and dimensions using the Publish Metrics function

Example with VPC Flow Logs

VPC Flow Logs capture information about the IP traffic going to and from network interfaces in your AWS VPC. Flow log data looks like this:

Code example
2 496698333333 eni-0538333333deafbeef 10.0.2.112 10.255.81.70 8000 41056 6 10 4133 1565552093 1565552110 ACCEPT OK

…and it has this format:

Code example
version account_id interface_id srcaddr dstaddr srcport dstport protocol packets bytes start end action log_status

Let’s assume that we have a requirement to extract bytes and packets as metrics at the time as indicated by value of start field (this is the field that Cribl LogStream uses to assign _time to these events) and across all other fields as dimensions, except for start and end. Let’s also assume that these metrics are then output to a Splunk metrics index.

  • Use the Parser function in Extract mode and select AWS VPC Flow Logs from the Library dropdown. This will automatically extract all fields above.

publish-metrics-parser-991x1024
  • Next, use the Publish Metrics function to select metrics and dimensions. Under Metrics map event name called bytes to  'net.bytes' and packets to  'net.packets'. Under Dimensions ensure you have the following Wildcarded List:  !_* !end !start *  – which basically means create dimensions out of all fields except for those start with _ (underscore), end and start.

publish-metrics-metrics-1024x850
  • Lastly, use the Eval function to set a field called index to  'metrics_test'. This is a metrics index in Splunk and may not be necessary for other destinations.

publish-metrics-eval-1024x896

To confirm in Preview toggle Show Internal Fields and navigate the __criblMetrics field hierarchy. Note that this field represents the necessary and sufficient information that the output uses to format the metric event depending on the type of destination. For example – a metric sent directly to Splunk has a different wire protocol representation than one sent via statsd or graphite.

publish-metrics-fields-1024x846

To confirm in Splunk, go to the Metrics Workspace and navigate on the left-hand side – you should see net > bytes and net > packets as available fields under Metrics.

publish-metrics-to-splunk-1024x344

That’s it!!

If you’d like more details on how to get started, head over to our documentation or join us in Slack #cribl, tweet at us @cribl_io, or contact us via hello@cribl.io. We’d love to help you!

Enjoy it!  — The Cribl Team

Cribl, the Data Engine for IT and Security, empowers organizations to transform their data strategy. Customers use Cribl’s suite of products to collect, process, route, and analyze all IT and security data, delivering the flexibility, choice, and control required to adapt to their ever-changing needs.

We offer free training, certifications, and a free tier across our products. Our community Slack features Cribl engineers, partners, and customers who can answer your questions as you get started and continue to build and evolve. We also offer a variety of hands-on Sandboxes for those interested in how companies globally leverage our products for their data challenges.

More from the blog

get started

Choose how to get started

See

Cribl

See demos by use case, by yourself or with one of our team.

Try

Cribl

Get hands-on with a Sandbox or guided Cloud Trial.

Free

Cribl

Process up to 1TB/day, no license required.