Sampler – A Device For Shell Instructions Execution, Visualization And Alerting (Configured With A Easy YAML Record)

Sampler is a device for shell instructions execution, visualization and alerting. Configured with a easy YAML document.
cause sound tone. Generally the library is in position, but when no longer – you’ll do it together with your favourite package deal supervisor, e.g apt set up libasound2-dev

Home windows (experimental)
Really useful to make use of with complex console emulators, e.g. Cmder
Obtain .exe

Utilization
You specify shell instructions, Sampler executes them with a required price. The output is used for visualisation.
One can pattern any dynamic task proper from the terminal – apply adjustments within the database, track MQ in-flight messages, cause deployment task and get notification when it is carried out.
The use of Sampler is mainly a 3-step task:

  • Outline your configuration in a YAML document
  • Run sampler -c config.yml
  • Alter parts measurement and site on UI

Parts
The next is an inventory of configuration examples for every part kind, with macOS appropriate sampling scripts.

Runchart

runcharts:
- name: Seek engine reaction time
rate-ms: 500 # sampling price, default = 1000
scale: 2 # choice of digits after pattern decimal level, default = 1
legend:
enabled: true # permits merchandise labels, default = true
main points: false # permits merchandise statistics: cur/min/max/dlt values, default = true
pieces:
- label: GOOGLE
pattern: curl -o /dev/null -s -w '%time_total' https://www.google.com
colour: 178 # 8-bit colour quantity, default one is selected from a pre-defined palette
- label: YAHOO
pattern: curl -o /dev/null -s -w '%time_total' https://seek.yahoo.com
- label: BING
pattern: curl -o /dev/null -s -w '%time_total' https://www.bing.com

Sparkline

sparklines:
- name: CPU utilization
rate-ms: 200
scale: 0
pattern: playstation -A -o %cpu | awk ' END '
- name: Loose reminiscence pages
rate-ms: 200
scale: 0
pattern: memory_pressure | grep 'Pages loose' | awk ''

Barchart

barcharts:
- name: Native community task
rate-ms: 500 # sampling price, default = 1000
scale: 0 # choice of digits after pattern decimal level, default = 1
pieces:
- label: UDP bytes in
pattern: nettop -J bytes_in -l 1 -m udp | awk ' END print sum'
- label: UDP bytes out
pattern: nettop -J bytes_out -l 1 -m udp | awk ' END print sum'
- label: TCP bytes in
pattern: nettop -J bytes_in -l 1 -m tcp | awk ' END print sum'
- label: TCP bytes out
pattern: nettop -J bytes_out -l 1 -m tcp | awk ' END print sum'

Gauge

gauges:
- name: Minute growth
rate-ms: 500 # sampling price, default = 1000
scale: 2 # choice of digits after pattern decimal level, default = 1
percent-only: false # toggle show of the present worth, default = false
colour: 178 # 8-bit colour quantity, default one is selected from a pre-defined palette
cur:
pattern: date +%S # pattern script for present worth
max:
pattern: echo 60 # pattern script for maximum worth
min:
pattern: echo 0 # pattern script for min worth
- name: Yr growth
cur:
pattern: date +%j
max:
pattern: echo 365
min:
pattern: echo 0

Textbox

textboxes:
- name: Native climate
rate-ms: 10000 # sampling price, default = 1000
pattern: curl wttr.in?0ATQF
border: false # border across the merchandise, default = true
colour: 178 # 8-bit colour quantity, default is white
- name: Docker boxes stats
rate-ms: 500
pattern: docker stats --no-stream --format "desk ttt"

Asciibox

asciiboxes:
- name: UTC time
rate-ms: 500 # sampling price, default = 1000
font: 3d # font kind, default = 2nd
border: false # border across the merchandise, default = true
colour: 43 # 8-bit colour quantity, default is white
pattern: env TZ=UTC date +%r

Bells and whistles

Triggers
Triggers permit to accomplish conditional movements, like visible/sound signals or an arbitrary shell command. The next examples illustrate the idea that.

Clock gauge, which displays minute growth and publicizes present time in the beginning of every minute

gauges:
- name: MINUTE PROGRESS
place: [[0, 18], [80, 0]]
cur:
pattern: date +%S
max:
pattern: echo 60
min:
pattern: echo 0
triggers:
- name: CLOCK BELL EVERY MINUTE
situation: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0' # expects "1" as TRUE indicator
movements:
terminal-bell: true # usual terminal bell, default = false
sound: true # NASA quindar tone, default = false
visible: false # notification with present worth on most sensible of the part space, default = false
script: say -v samantha `date +%I:%Mp.cp` # an arbitrary script, which is able to use $cur, $prev and $label variables

Seek engine latency chart, which signals person when latency exceeds a threshold

runcharts:
- name: SEARCH ENGINE RESPONSE TIME (sec)
rate-ms: 200
pieces:
- label: GOOGLE
pattern: curl -o /dev/null -s -w '%time_total' https://www.google.com
- label: YAHOO
pattern: curl -o /dev/null -s -w '%time_total' https://seek.yahoo.com
triggers:
- name: Latency threshold exceeded
situation: echo "$prev < 0.3 && $cur > 0.3" |bc -l # expects "1" as TRUE indicator
movements:
terminal-bell: true # usual terminal bell, default = false
sound: true # NASA quindar tone, default = false
visible: true # visible notification on most sensible of the part space, default = false
script: 'say alert: $ latency exceeded $cur 2nd' # an arbitrary script, which is able to use $cur, $prev and $label variables

Interactive shell beef up
Along with the pattern command, one can specify init command (done solely as soon as sooner than sampling) and grow to be command (to post-process pattern command output). That covers interactive shell use case, e.g. to determine connection to a database solely as soon as, after which carry out polling inside of an interactive shell consultation.

Fundamental mode

textboxes:
- name: MongoDB polling
rate-ms: 500
init: mongo --quiet --host=localhost check # executes solely as soon as to begin the interactive consultation
pattern: Date.now(); # executes with a required price, in scope of the interactive consultation
grow to be: echo outcome = $pattern # executes in scope of native consultation, $pattern variable is to be had for transformation

PTY mode
In some circumstances interactive shell may not paintings, as a result of its stdin isn’t a terminal. We will be able to idiot it, the usage of PTY mode:

textboxes:
- name: Neo4j polling
pty: true # permits pseudo-terminal mode, default = false
init: cypher-shell -u neo4j -p pwd --format simple
pattern: RETURN rand();
grow to be: echo "$pattern" | tail -n 1
- name: Most sensible on a far flung server
pty: true # permits pseudo-terminal mode, default = false
init: ssh -i ~/person.pem [email protected]
pattern: most sensible

Multistep init
It’s also imaginable to execute a couple of init instructions one after some other, sooner than you get started sampling.

textboxes:
- name: Java utility uptime
multistep-init:
- java -jar jmxterm-1.0.0-uber.jar
- open host:port # or native PID
- bean java.lang:kind=Runtime
pattern: get Uptime

Variables
If the configuration document accommodates repeated patterns, they may be able to be extracted into the variables phase. Additionally variables can also be specified the usage of -v/--variable flag on startup, and any machine atmosphere variables may also be to be had within the scripts.

variables:
mongoconnection: mongo --quiet --host=localhost check
barcharts:
- name: MongoDB paperwork by way of standing
pieces:
- label: IN_PROGRESS
init: $mongoconnection
pattern: db.getCollection('occasions').to find().depend()
- label: SUCCESS
init: $mongoconnection
pattern: db.getCollection('occasions').to find(standing:'SUCCESS').depend()
- label: FAIL
init: $mongoconnection
pattern: db.getCollection('occasions').to find(standing:'FAIL').depend()

Colour theme

theme: mild # default = darkish
sparklines:
- name: CPU utilization
pattern: playstation -A -o %cpu | awk ' END '

Actual-world recipes

Databases
The next are other database connection examples. Interactive shell (init script) utilization is really helpful to determine connection solely as soon as after which reuse it throughout sampling.

MySQL

# prerequisite: put in mysql shell

variables:
mysql_connection: mysql -u root -s --database mysql --skip-column-names
sparklines:
- name: MySQL (random quantity instance)
pty: true
init: $mysql_connection
pattern: choose rand();


PostgreSQL

# prerequisite: put in psql shell

variables:
PGPASSWORD: pwd
postgres_connection: psql -h localhost -U postgres --no-align --tuples-only
sparklines:
- name: PostgreSQL (random quantity instance)
init: $postgres_connection
pattern: choose random();


MongoDB

# prerequisite: put in mongo shell

variables:
mongo_connection: mongo --quiet --host=localhost check
sparklines:
- name: MongoDB (random quantity instance)
init: $mongo_connection
pattern: Math.random();


Neo4j

# prerequisite: put in cypher shell

variables:
neo4j_connection: cypher-shell -u neo4j -p pwd --format simple
sparklines:
- name: Neo4j (random quantity instance)
pty: true
init: $neo4j_connection
pattern: RETURN rand();
grow to be: echo "$pattern" | tail -n 1

Kafka lag in step with person organization

variables:
kafka_connection: $KAFKA_HOME/bin/kafka-consumer-groups --bootstrap-server localhost:9092
runcharts:
- name: Kafka lag in step with person organization
rate-ms: 5000
scale: 0
pieces:
- label: A->B
pattern: $kafka_connection --group group_a --describe | awk 'NR>1 sum += $5 END print sum'
- label: B->C
pattern: $kafka_connection --group group_b --describe | awk 'NR>1 sum += $5 END print sum'
- label: C->D
pattern: $kafka_connection --group group_c --describe | awk 'NR>1 sum += $5 END print sum'

Docker boxes stats (CPU, MEM, O/I)

textboxes:
- name: Docker boxes stats
pattern: docker stats --no-stream --format "desk tttttt"

SSH

TOP command on a far flung server

variables:
sshconnection: ssh -i ~/my-key-pair.pem [email protected]
textboxes:
- name: SSH
pty: true
init: $sshconnection
pattern: most sensible

JMX

Java utility uptime instance

# prerequisite: obtain [jmxterm jar file](https://medical doctors.cyclopsgroup.org/jmxterm)

textboxes:
- name: Java utility uptime
multistep-init:
- java -jar jmxterm-1.0.0-uber.jar
- open host:port # or native PID
- bean java.lang:kind=Runtime
pattern: get Uptime
grow to be: echo $pattern | tr -dc '0-9' | awk ''
Obtain Sampler

Published by Marshmallow

Marshmallow Android is BT Ireland’s Head of Sales for Republic of Ireland domestic multi-site companies, indigenous MNCs and public sector accounts. He is responsible for the direction and control of all sales activity in the region. He has over 10 years management experience from high growth start-ups to more established businesses. He’s led teams in Ireland, India and China across various industries (ICT, On-Line Recruitment, Corporate Training and International Education).