Sampler - A Tool For Rhythm Out Commands Execution, Visualization Too Alerting (Configured Amongst A Unproblematic Yaml File)


Sampler is a tool for trounce commands execution, visualization as well as alerting. Configured amongst a elementary YAML file.

Installation

macOS
brew cask install sampler
or
curl -Lo /usr/local/bin/sampler https://github.com/sqshq/sampler/releases/download/v1.0.1/sampler-1.0.1-darwin-amd64 chmod +x /usr/local/bin/sampler

Linux
wget https://github.com/sqshq/sampler/releases/download/v1.0.1/sampler-1.0.1-linux-amd64 -O /usr/local/bin/sampler chmod +x /usr/local/bin/sampler
Note: libasound2-dev organization library is required to move installed for Sampler to play a trigger audio tone. Usually the library is inwards place, but if non - y'all tin laissez passer notice produce it amongst your favorite packet manager, e.g apt install libasound2-dev

Windows (experimental)
Recommended to purpose amongst advanced console emulators, e.g. Cmder
Download .exe

Usage
You specify trounce commands, Sampler executes them amongst a required rate. The output is used for visualization.
One tin laissez passer notice sample whatever dynamic procedure correct from the finally - discover changes inwards the database, monitor MQ in-flight messages, trigger deployment procedure as well as instruct notification when it's done.
Using Sampler is basically a 3-step process:
  • Define your configuration inwards a YAML file
  • Run sampler -c config.yml
  • Adjust components size as well as location on UI

Components
The next is a listing of configuration examples for each ingredient type, amongst macOS compatible sampling scripts.

Runchart


runcharts:   - title: Search engine answer fourth dimension     rate-ms: 500        # sampling rate, default = G     scale: 2            # discover of digits afterwards sample decimal point, default = 1     legend:       enabled: truthful     # enables item labels, default = truthful       details: fake    # enables item statistics: cur/min/max/dlt values, default = truthful     items:       - label: GOOGLE         sample: gyre -o /dev/null -s -w '%{time_total}'  https://www.google.com         color: 178      # 8-bit color number, default 1 is chosen from a pre-defined palette       - label: YAHOO         sample: gyre -o /dev/null -s -w '%{time_total}'  https://search.yahoo.com       - label: BING         sample: gyre -o /dev/null -s -w '%{time_total}'  https://www.bing.com

Sparkline


sparklines:   - title: CPU usage     rate-ms: 200     scale: 0     sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'   - title: Free memory pages     rate-ms: 200     scale: 0     sample: memory_pressure | grep 'Pages free' | awk '{print $3}'

Barchart


barcharts:   - title: Local network activity     rate-ms: 500        # sampling rate, default = G     scale: 0            # discover of digits afterwards sample decimal point, default = 1     items:       - label: UDP bytes inwards         sample: nettop -J bytes_in -l 1 -m udp | awk '{sum += $4} END {print sum}'       - label: UDP bytes out         sample: nettop -J bytes_out -l 1 -m udp | awk '{sum += $4} END {print sum}'       - label: TCP bytes inwards         sample: nettop -J bytes_in -l 1 -m tcp | awk '{sum += $4} END {print sum}'       - label: TCP bytes out         sample: nettop -J bytes_out -l 1 -m tcp | awk '{sum += $4} END {print sum}'

Gauge


gauges:   - title: Minute progress     rate-ms: 500        # sampling rate, default = G     scale: 2            # discover of digits afterwards sample decimal point, default = 1     percent-only: fake # toggle display of the electrical flow value, default = fake     color: 178          # 8-bit color number, default 1 is chosen from a pre-defined palette     cur:       sample: engagement +%S  # sample script for electrical flow value     max:       sample: echo lx   # sample script for max value     min:       sample: echo 0    # sample script for min value   - title: Year progress     cur:       sample: engagement +%j     max:       sample: echo 365     min:       sample: echo 0

Textbox


textboxes:   - title: Local atmospheric condition     rate-ms: 10000      # sampling rate, default = G     sample: gyre wttr.in?0ATQF     border: fake       # edge roughly the item, default = truthful     color: 178          # 8-bit color number, default is white   - title: Docker containers stats     rate-ms: 500     sample: docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.PIDs}}"

Asciibox


asciiboxes:   - title: UTC fourth dimension     rate-ms: 500        # sampling rate, default = G     font: 3d            # font type, default = 2d     border: fake       # edge roughly the item, default = truthful         color: 43           # 8-bit color number, default is white     sample: env TZ=UTC engagement +%r

Bells as well as whistles

Triggers
Triggers allow to perform conditional actions, similar visual/sound alerts or an arbitrary trounce command. The next examples illustrate the concept.

Clock gauge, which shows infinitesimal progress as well as announces electrical flow fourth dimension at the commencement of each minute
gauges:   - title: MINUTE PROGRESS     position: [[0, 18], [80, 0]]       cur:       sample: engagement +%S     max:       sample: echo lx     min:       sample: echo 0     triggers:       - title: CLOCK BELL EVERY MINUTE         condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'  # expects "1" equally TRUE indicator         actions:           terminal-bell: truthful  # touchstone finally bell, default = fake           sound: truthful    # NASA quindar tone, default = fake           visual: fake  # notification amongst electrical flow value on top of the ingredient area, default = fake           script: tell -v samantha `date +%I:%M%p`  # an arbitrary script, which tin laissez passer notice purpose $cur, $prev as well as $label variables

Search engine latency chart, which alerts user when latency exceeds a threshold
runcharts:   - title: SEARCH ENGINE RESPONSE TIME (sec)     rate-ms: 200     items:       - label: GOOGLE         sample: gyre -o /dev/null -s -w '%{time_total}'  https://www.google.com       - label: YAHOO         sample: gyre -o /dev/null -s -w '%{time_total}'  https://search.yahoo.com          triggers:       - title: Latency threshold exceeded         condition: echo "$prev < 0.3 && $cur > 0.3" |bc -l  # expects "1" equally TRUE indicator         actions:           terminal-bell: truthful  # touchstone finally bell, default = fake           sound: truthful   # NASA quindar tone, default = fake           visual: truthful  # visual notification on top of the ingredient area, default = fake           script: 'say alert: ${label} latency exceeded ${cur} second' # an arbitrary script, which tin laissez passer notice purpose $cur, $prev as well as $label variables

Interactive trounce support
In add-on to the sample command, 1 tin laissez passer notice specify init dominance (executed solely in 1 lawsuit earlier sampling) as well as transform dominance (to post-process sample dominance output). That covers interactive trounce purpose case, e.g. to institute connexion to a database solely once, as well as and hence perform polling inside an interactive trounce session.

Basic mode
textboxes:   - title: MongoDB polling     rate-ms: 500     init: mongo --quiet --host=localhost bear witness # executes solely in 1 lawsuit to start the interactive session     sample: Date.now();                       # executes amongst a required rate, inwards orbit of the interactive session     transform: echo final result = $sample          # executes inwards orbit of local session, $sample variable is available for transformation

PTY mode
In some cases interactive trounce won't work, because its stdin is non a terminal. We tin laissez passer notice fool it, using PTY mode:
textboxes:   - title: Neo4j polling     pty: truthful  # enables pseudo-terminal mode, default = fake     init: cypher-shell -u neo4j -p pwd --format obviously     sample: RETURN rand();     transform: echo "$sample" | tail -n 1   - title: Top on a remote server     pty: truthful  # enables pseudo-terminal mode, default = fake     init: ssh -i  /user.pem ec2-user@1.2.3.4     sample: top    

Multistep init
It is also possible to execute multiple init commands 1 afterwards another, earlier y'all start sampling.
textboxes:   - title: Java application uptime     multistep-init:       - coffee -jar jmxterm-1.0.0-uber.jar       - opened upward host:port # or local PID       - edible bean java.lang:type=Runtime     sample: instruct Uptime

Variables
If the configuration file contains repeated patterns, they tin laissez passer notice move extracted into the variables section. Also variables tin laissez passer notice move specified using -v/--variable flag on startup, as well as whatever organization surround variables volition also move available inwards the scripts.
variables:     mongoconnection: mongo --quiet --host=localhost bear witness barcharts:   - title: MongoDB documents past times status     items:       - label: IN_PROGRESS         init: $mongoconnection         sample: db.getCollection('events').find({status:'IN_PROGRESS'}).count()       - label: SUCCESS         init: $mongoconnection         sample: db.getCollection('events').find({status:'SUCCESS'}).count()       - label: FAIL         init: $mongoconnection         sample: db.getCollection('events').find({status:'FAIL'}).count()

Color theme


theme: lite # default = nighttime sparklines:   - title: CPU usage     sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'

Real-world recipes

Databases
The next are unlike database connexion examples. Interactive trounce (init script) usage is recommended to institute connexion solely in 1 lawsuit as well as and hence reuse it during sampling.

MySQL
# prerequisite: installed mysql trounce  variables:   mysql_connection: mysql -u root -s --database mysql --skip-column-names sparklines:     - title: MySQL (random discover example)     pty: truthful     init: $mysql_connection     sample: conduct rand();

PostgreSQL
# prerequisite: installed psql trounce  variables:   PGPASSWORD: pwd   postgres_connection: psql -h localhost -U postgres --no-align --tuples-only sparklines:   - title: PostgreSQL (random discover example)     init: $postgres_connection     sample: conduct random();

MongoDB
# prerequisite: installed mongo trounce  variables:   mongo_connection: mongo --quiet --host=localhost bear witness sparklines:   - title: MongoDB (random discover example)     init: $mongo_connection     sample: Math.random();

Neo4j
# prerequisite: installed cypher trounce  variables:   neo4j_connection: cypher-shell -u neo4j -p pwd --format obviously sparklines:   - title: Neo4j (random discover example)     pty: truthful     init: $neo4j_connection     sample: RETURN rand();     transform: echo "$sample" | tail -n 1

Kafka lag per consumer group
variables:   kafka_connection: $KAFKA_HOME/bin/kafka-consumer-groups --bootstrap-server localhost:9092 runcharts:   - title: Kafka lag per consumer grouping     rate-ms: 5000     scale: 0     items:       - label: A->B         sample: $kafka_connection --group group_a --describe | awk 'NR>1 {sum += $5} END {print sum}'       - label: B->C         sample: $kafka_connection --group group_b --describe | awk 'NR>1 {sum += $5} END {print sum}'       - label: C->D         sample: $kafka_connection --group group_c --describe | awk 'NR>1 {sum += $5} END {print sum}'

Docker containers stats (CPU, MEM, O/I)
textboxes:   - title: Docker containers stats     sample: docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDs}}"

SSH

TOP dominance on a remote server
variables:   sshconnection: ssh -i  /my-key-pair.pem ec2-user@1.2.3.4 textboxes:   - title: SSH     pty: truthful     init: $sshconnection     sample: top

JMX

Java application uptime example
# prerequisite: download [jmxterm jounce file](https://docs.cyclopsgroup.org/jmxterm)  textboxes:   - title: Java application uptime     multistep-init:       - coffee -jar jmxterm-1.0.0-uber.jar       - opened upward host:port # or local PID       - edible bean java.lang:type=Runtime     sample: instruct Uptime     transform: echo $sample | tr -dc '0-9' | awk '{printf "%.1f min", $1/1000/60}'