Giter VIP home page Giter VIP logo

terminal-heatmap's Introduction

terminal-heatmap

An experiment in terminal-based heat maps. For example, witness the majesty of this mpstat(1) display of a 16-CPU zone in the JPC:

awesome heatmap

This version accepts input on stdin of the form ...

10 8 6 6 3 3 4 4 3 4 2 3 4 5 3 5
46 2 6 6 4 1 57 2 10 0 3 2 3 8 3 12
97 3 6 8 5 1 2 4 0 11 1 1 4 2 11 4

... where each line is some number whitespace-separated integers between 0 and 100. The integers will be split up into buckets and the count of integers in each bucket determines that bucket's intensity in the heatmap.

The most natural usage is to take input from mpstat(1) and spit out CPU Usage figures for all CPUs, once per second, using the provided formatters/mpstat script. For example:

ssh someserver mpstat 1 | ./formatters/mpstat | ./heatmap

Bucket Distributions

You can decide the Y-axis for the heat map with a few options.

Linear (-l)

The default distribution of values between buckets is linear, with a minimum value of 0 and a maximum of 100. This is equivalent to:

someprogram | ./heatmap -l -m 0 -M 100

Log-Linear (-L)

In a similar fashion to DTrace's llquantize() you can specify a log distribution with linear buckets within each order of magnitude. For instance: if I/O Latency is expressed in microseconds, it may be useful to draw a heatmap with a base of 10, from the second up to the sixth order of magnitude. i.e.

iolatency.d | ./someformatter | ./heatmap -L -b 10 -m 2 -M 6

Example output from iolatency.d during a ZFS pool scrub:

zfs scrub heatmap

Colouring

In the most recent C-based version I have used a Rank-based Colouring, as described in this blog post by Dave Pacheco.

If the darkest shades are not visible in your terminal, you can skip some number of shades from the dark end of the spectrum with the -G flag.

terminal-heatmap's People

Contributors

jclulow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

terminal-heatmap's Issues

heatmap.c SEGV's when stdin is closed (upstream exits 0)

Take my patch. You know you'll love it:

diff --git a/heatmap.c b/heatmap.c
index 601a240..6f0fc49 100644
--- a/heatmap.c
+++ b/heatmap.c
@@ -1,5 +1,4 @@

-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -32,7 +31,7 @@ typedef enum { B_FALSE, B_TRUE } boolean_t;

 #define    LEGEND_WIDTH    10

-#define    BUFFER_SIZE 4096
+#define    BUFFER_SIZE 65535

 #define    TITLE   "T E R M I N A L   H E A T M A P"

@@ -79,6 +78,20 @@ print_title(char *title)
 }

 void
+init_canvas()
+{
+   int i;
+   int j;
+
+   for (i = 0; i < w; i++) {
+       for (j = 0; j< h ; j++) {
+           fprintf(stdout, CSI "%d;4H", j); /* move afore the line */
+           fprintf(stdout, CSI "1P"); /* truncate on the left */
+       }
+   }
+}
+
+void
 print_time_markers(void)
 {
    int offs;
@@ -560,6 +573,7 @@ main(int argc, char **argv)
     * Set up the screen:
     */
    fprintf(stdout, CLRSCR NOCURS);
+   init_canvas();
    print_title(opt_title != NULL ? opt_title : TITLE);
    print_time_markers();

@@ -569,8 +583,13 @@ main(int argc, char **argv)
     * where each integer value will increment the bucket it fits in.
     */
    for (;;) {
-       char *buf = fgets(line_buffer, BUFFER_SIZE, stdin);
-       int *row = line_to_row(buf);
+       char *buf;
+       int *row;
+
+       if ((buf = fgets(line_buffer, BUFFER_SIZE, stdin)) == NULL)
+           exit(0);
+
+       row = line_to_row(buf);

        if (row == NULL) {
            fprintf(stdout, CLRSCR CURS);

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.