Git Product home page Git Product logo

metrics-exporter-cli's Introduction

metrics-exporter-cli

A work-in-progress exporter for the metrics crate which display a table on CLI.

  group1    |
val_a val_b | iterations
    4     4            1
    5     6            2
    8     9            3
    9    15            4

This is a simple exporter build on top of metrics_util::debugging::DebuggingRecorder. It should be used for debugging purposes and as a simpler (and much more limited) solution compared to a full blown metrics setup using prometheus.

WARNING: this is a work in progress prototype. Expect bugs, missing features, crappy API and breaking changes. You're more than welcome to open issues with feedback and feature requests.

Simple automatic usage

The table above can be created with this code:

use std::time::Duration;

use metrics::{counter, increment_counter};
use metrics_exporter_cli::CliRegister;

use rand::prelude::*;

fn main() {
    let mut register = CliRegister::install().expect("Error installing register");
    std::thread::spawn(move || {
        std::thread::sleep(Duration::from_millis(500));
        register.print_loop();
    });

    let mut rng = thread_rng();
    loop {
        increment_counter!("iterations");
        counter!("group1.val_a", rng.gen_range(0..5));
        counter!("group1.val_b", rng.gen_range(0..10));
        std::thread::sleep(Duration::from_secs(1));
    }
}

After installing the CliRegister we spawn the table printing loop, which just prints to stdout the header and a new line every 1s. We could also do this manually by printing the output of register.header() and register.status().

In this example there is no table configuration. The columns will be grouped by splitting dots in key names. Every column will be aligned and keep as little space as possible to include the value and header field.

When a value is too big for its cell, its column will be enlarged from that moment on. This will cause an unalignment with the lines before, but should be readable and quite minimal.

Descriptive usage

The description exapmle uses metrics labels and units of measure to configure the table. In particular, all *PerSecond metrics will cause the cells to display a difference with the previous value (this assumes 1 display per second, or the results will be wrong).

let absolute = register_counter!("absolute");                         
let difference = register_counter!("difference");                     
describe_counter!("difference", Unit::CountPerSecond, "");            
let histogram = register_counter!("histogram", "view" => "histogram");

The same monothonically increasing counter will result in this table:

absolute difference histogram
       1          1 #        
       2          1 ##       
       3          1 ###      
       4          1 ####     
       5          1 #####    

TODO

  • Ideally, I'd like to add a builder API to configure the table as an alternative to the "descriptive usage".
  • The histogram feature needs to be improved
  • API needs to be improved

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.