Sponsored Content
Top Forums Shell Programming and Scripting Fun with terminal plotting JSON data at the command line Post 303043053 by kbrazil on Thursday 16th of January 2020 12:33:22 PM
Old 01-16-2020
Fun with terminal plotting JSON data at the command line

One of the great thing about unix is the ability to pipe multiple programs together to manipulate data. Plain, unstructured text is the most common type of data that is passed between programs, but these days JSON is becoming more popular.

I thought it would be fun to pipe together some command line JSON tools to do some stupid terminal tricks, like plotting a graph of system statistics, like CPU or memory utilization.

We can use jc (disclosure: I wrote jc), jq, and jp to pull the output of uptime and display a line graph like this:

Image

In this post I'll show you how you can build a quick bar graph of the CPU utilization of the top processes right in the terminal. For more information on how to create the animated line graph above, see my blog post at blog.kellybrazil.com.

first, get jc, jq, and jp.

Then you can use this one-liner to graph the output of ps:
Code:
ps axu | jc --ps | jq '[.[] | select (.cpu_percent > 0.5)]' | jp -type bar -canvas full-escape -x ..pid -y ..cpu_percent

Image

Fun stuff! jq is an awesome JSON tool for the cli and is a bit like sed or awk for JSON. You'll find lots of uses for manipulating JSON as more and more programs start to output in the format.

Last edited by kbrazil; 01-16-2020 at 04:39 PM..
These 2 Users Gave Thanks to kbrazil For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

like to have fun in terminal

Hai Friends I have installed FreeBSD in my system... I have installed it to work in text mode don't have the GUI. The default text color is Black background with White Foreground. I want it to be with Black background with Green Foreground. How could i do that. Thanks in advance Collins (4 Replies)
Discussion started by: collins
4 Replies

2. UNIX for Advanced & Expert Users

Gnuplot question: plotting 3D data in map view

I have a simple gnuplot question. I have a set of points (list of x,y,z values; irregularly spaced, i.e. no grid) that I want to plot. I want the plot to look like this: - map view (no 3D view) - color of each point should depend on z-value. - I want to define my own color scale - plot should... (1 Reply)
Discussion started by: karman
1 Replies

3. UNIX for Dummies Questions & Answers

Plotting Data within UNIX

I have a set of data that looks similar to the following in UNIX: 0.12_0.008_fall_ff.out:bisect return: 0.08056640625 0.12_0.04_fall_ff.out:bisect return: 0.07470703125 0.12_0.12_fall_ff.out:bisect return: 0.06298828125 0.12_0.24_fall_ff.out:bisect return: 0.05126953125 Previously I have... (4 Replies)
Discussion started by: EDALBNUG
4 Replies

4. Shell Programming and Scripting

plotting a straight horizontal line

How can I plot a straight horizontal line using perl in unix solaris environment? Please suggest. Pooja (2 Replies)
Discussion started by: wadhwa.pooja
2 Replies

5. UNIX for Dummies Questions & Answers

Help with extracting data and plotting

I have attached a txt file, what I would like to be able to do is: 1. Extract Data from Columns labeled E/N and Ko into a new file 2. Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis. 3. Lastly I would like to be able to extract multiple data sets and... (6 Replies)
Discussion started by: gingburg
6 Replies

6. Shell Programming and Scripting

Is command line invocation of gnome-terminal to run more than one command possible?

Hello, I am trying to learn how to pass something more than a one-command startup for gnome-terminal. I will give an example of what I'm trying to do here: #! /bin/bash # #TODO write this for gnome and xterm USAGE=" ______________________________________________ ${0##*/} run... (0 Replies)
Discussion started by: Narnie
0 Replies

7. UNIX Desktop Questions & Answers

How do you reverse terminal command line to the top?

Hi All, I work on a Linux platform which runs Red Hat (forget which version) and use both korn and bash shells. Is there a way of making the command line appear at the top of the terminal window and any lists, commands or directory names etc to appear below the top, that is to say reverse the... (1 Reply)
Discussion started by: ray_m
1 Replies

8. OS X (Apple)

How to start a new terminal from command line?

Dear All, Anyone knows how to start a new bash terminal from command line? Another question: when I use "open" command (open test.pdf) to open a pdf file, the PDF reader will start up, but cannot associate with that file. Anyone knows why? (1 Reply)
Discussion started by: andrewust
1 Replies

9. OS X (Apple)

A new OSX 10.12.x terminal from the command line.

Hi guys and gals... After much searching on the good ol' internet I could find nothing, so this is the result. ALthough many people seem to have asked this question no-one seems to have a solution so here we go. I need for AudioScope.sh, 'xterm' to run a second program for some of its... (2 Replies)
Discussion started by: wisecracker
2 Replies

10. Shell Programming and Scripting

Split JSON to different data files

Hi Gurus, I have below JSON file, now I want to rewrite this file into a new file. I will appreciate if anyone can help me to provide the solution...I can't use jq. { "_id": "3ad893cb4cf1560add7b4caffd4b6126", "_rev": "1-1f0ce165e1d210319cf6e9f9c6ff654f", "name":... (4 Replies)
Discussion started by: manas_ranjan
4 Replies
RDF::Trine::Iterator::Graph(3pm)			User Contributed Perl Documentation			  RDF::Trine::Iterator::Graph(3pm)

NAME
RDF::Trine::Iterator::Graph - Iterator class for graph query results VERSION
This document describes RDF::Trine::Iterator::Graph version 1.000 SYNOPSIS
use RDF::Trine::Iterator::Graph; my $iterator = RDF::Trine::Iterator::Graph->new( &data ); while (my $st = $iterator->next) { # $st is a RDF::Trine::Statement object print $st->as_string; } METHODS
Beyond the methods documented below, this class inherits methods from the RDF::Trine::Iterator class. "new ( @results, %args )" "new ( &results, %args )" Returns a new SPARQL Result interator object. Results must be either an reference to an array containing results or a CODE reference that acts as an iterator, returning successive items when called, and returning undef when the iterator is exhausted. $type should be one of: bindings, boolean, graph. "as_bindings ( $s, $p, $o )" Returns the iterator as a Bindings iterator, using the supplied triple nodes to determine the variable bindings. "materialize" Returns a materialized version of the current graph iterator. The materialization process will leave this iterator empty. The materialized iterator that is returned should be used for any future need for the iterator's data. "unique" Returns a Graph iterator that ensures the returned statements are unique. While the underlying RDF graph is the same regardless of uniqueness, the iterator's serialization methods assume the results are unique, and so use this method before serialization. Uniqueness is opt-in for efficiency concerns -- this method requires O(n) memory, and so may have noticeable effects on large graphs. "is_graph" Returns true if the underlying result is an RDF graph. "as_string ( $max_size [, $count] )" Returns a string table serialization of the stream data. "as_xml ( $max_size )" Returns an XML serialization of the stream data. "print_xml ( $fh, $max_size )" Prints an XML serialization of the stream data to the filehandle $fh. "as_json ( $max_size )" Returns a JSON serialization of the stream data. "as_hashref" Returns a hashref representing the model in an RDF/JSON-like manner. See "as_hashref" at RDF::Trine::Model for full documentation of the hashref format. "construct_args" Returns the arguments necessary to pass to the stream constructor _new to re-create this stream (assuming the same closure as the first DEPENDENCIES
JSON Scalar::Util BUGS
Please report any bugs or feature requests to through the GitHub web interface at <https://github.com/kasei/perlrdf/issues>. AUTHOR
Gregory Todd Williams "<gwilliams@cpan.org>" COPYRIGHT
Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-29 RDF::Trine::Iterator::Graph(3pm)
All times are GMT -4. The time now is 07:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy