Metrics

FlexLogs Docs Image

Metrics are a powerful feature that helps you gain insights into your application's behavior, especially early-stage startup metrics. By using Metric tags in your logs, you can track key data points over time. These tags can be set as "counter" or "gauge" type metrics for flexible and detailed monitoring.

Counters are for tracking things that increment, like the number of requests your app handles or errors encountered.
Gauges, on the other hand, measure values that can go up and down, like the length of a job queue, or cpu-load.

By embedding these metric annotations in your logs, you can gather historical data about anything you need to know regarding your application. Whether it's keeping tabs on resource usage, monitoring user activity, or tracking specific events, FlexLogs Metrics are simple and efficient.

Setting up Metrics is quick and easy - just add the appropriate tags to your logs and let the system do the rest. You'll have access to valuable historical data that helps you understand and optimize your application.

Getting Started with Metrics

The most basic metric is a counter, which increments each time it's logged. The default value is 1. The following example shows how to create a couple simple metrics.

    
      
    // Create a basic (counter) metric
    logger.info("flexlogs{metric: 'page-load'}");

    // The same metric using the html-like format
    logger.info("<flexlogs metric=page-load />");

    // Create a basic (gauge) metric
    logger.info("flexlogs{metric: 'cpu-usage', type: 'gauge', value: 0.75}");
  
    
  

Options

Key Description Type / Options Default
metric A name for your metric String
type The type of metric counter or gauge counter
value Metric value Number 1
tags List of tags Array []

Examples

    
      
    // add some tags
    logger.info("flexlogs{metric: 'order.new', tags: ['order', 'checkout']}");

    // gauge metric for monitoring queue length
    logger.info(`flexlogs{metric: 'queue.length', value: ${ Queue.length() }, type: 'gauge'}`);

    // explicitly set type and value
    logger.info("flexlogs{metric: 'user.signup', type: 'counter', value: 1}")

    // build from json object
    logger.info("flexlogs" + JSON.stringify({metric: "new-feature.enabled"}));
    // same as -> logger.info("flexlogs{metric: 'new-feature.enabled'}")

    // add multiple tags
    logger.info("flexlogs{metric: 'beta_feature.error', tags: ['error', 'beta']}");

    // interested in other examples? let us know!