Sampler : A Tool For Shell Commands Execution, Visualization & Alerting

Sampler is a tool for shell commands execution, visualization and alerting. Configured with a simple YAML file.

One can sample any dynamic process right from the terminal – observe changes in the database, monitor MQ in-flight messages, trigger a deployment script and get notification when it’s done.

If there is a way to get a metric using shell command – then it can be visualized with Sampler momentarily.

Installation

MacOS

brew cask install sampler

or

sudo curl -Lo /usr/local/bin/sampler https://github.com/sqshq/sampler/releases/download/v1.0.2/sampler-1.0.2-darwin-amd64
sudo chmod +x /usr/local/bin/sampler

Linux

sudo wget https://github.com/sqshq/sampler/releases/download/v1.0.2/sampler-1.0.2-linux-amd64 -O /usr/local/bin/sampler
sudo chmod +x /usr/local/bin/sampler

Note: libasound2-dev system library is required to be installed for Sampler to play a trigger sound tone. Usually the library is in place, but if not – you can in

stall it with your favorite package manager, e.g apt install libasound2-dev

Usage

You specify shell commands, Sampler executes them with a required rate. The output is used for visualization.

Using Sampler is basically a 3-step process:

  • Define your shell commands in a YAML configuration file
  • Run sampler -c config.yml
  • Adjust components size and location on UI

But there are so many monitoring systems already

Sampler is by no means an alternative to full-scale monitoring systems, but rather easy to setup development tool.

If spinning up and configuring Prometheus with Grafana is complete overkill for you task, Sampler might be the right solution. No servers, no databases, no deploy – you specify shell commands, and it just works.

Then it should be installed on every server I monitor?

No, you can run Sampler on local, but still gather telemetry from multiple remote machines. Any visualization might have init command, where you can ssh to a remote server.

Also Read – Goop : Google Search Scraper

Components

The following is a list of configuration examples for each component type, with macOS compatible sampling scripts.

Runchart

  • runcharts:
    • title: Search engine response time
    • rate-ms: 500 # sampling rate, default = 1000
    • scale: 2 # number of digits after sample decimal point, default = 1
    • legend:
      • enabled: true # enables item labels, default = true
      • details: false # enables item statistics: cur/min/max/dlt values, default = true
    • items:
      • label: GOOGLE
        • sample: curl -o /dev/null -s -w ‘%{time_total}’ https://www.google.com
        • color: 178 # 8-bit color number, default one is chosen from a pre-defined palette
      • label: YAHOO
        • sample: curl -o /dev/null -s -w ‘%{time_total}’ https://search.yahoo.com
      • label: BING
        • sample: curl -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 = 1000
      • scale: 0 # number of digits after sample decimal point, default = 1
    • items:
      • label: UDP bytes in
        • 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 in
        • 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 = 1000
      • scale: 2 # number of digits after sample decimal point, default = 1
      • percent-only: false # toggle display of the current value, default = false
      • color: 178 # 8-bit color number, default one is chosen from a pre-defined palette
      • cur:
        • sample: date +%S # sample script for current value
      • max:
        • sample: echo 60 # sample script for max value
      • min:
        • sample: echo 0 # sample script for min value
    • title: Year progress
      • cur:
        • sample: date +%j
      • max:
        • sample: echo 365
      • min:
        • sample: echo 0

Textbox

  • textboxes:
    • title: Local weather
      • rate-ms: 10000 # sampling rate, default = 1000
      • sample: curl wttr.in?0ATQF
      • border: false # border around the item, default = true
      • 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 time
      • rate-ms: 500 # sampling rate, default = 1000
      • font: 3d # font type, default = 2d
      • border: false # border around the item, default = true
      • color: 43 # 8-bit color number, default is white
      • sample: env TZ=UTC date +%r
R K

Recent Posts

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

2 weeks ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

2 weeks ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

4 weeks ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

4 weeks ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

4 weeks ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

4 weeks ago