Giter Site home page Giter Site logo

sqshq / sampler Goto Github PK

View Code? Open in Web Editor NEW
12.2K 160.0 539.0 2.18 MB

Tool for shell commands execution, visualization and alerting. Configured with a simple YAML file.

Home Page: https://sampler.dev

License: GNU General Public License v3.0

Go 99.71% Dockerfile 0.29%
shell visualization cmd terminal charts alerting sampler command-line command-line-tool monitoring golang dashbord

sampler's Introduction

Sampler. Visualization for any shell command.

Build Status Go Report Card

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

sampler

Why do I need it?

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 a shell command, then it can be visualized with Sampler momentarily.

Installation

macOS

HomeBrew:

brew install sampler

MacPorts:

sudo port install sampler

or

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

Linux

sudo wget https://github.com/sqshq/sampler/releases/download/v1.1.0/sampler-1.1.0-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 install it with your favorite package manager, e.g apt install libasound2-dev

Packaging status

  • Fedora sudo dnf install golang-github-sqshq-sampler (F31+)
  • Arch yay -S sampler

Windows (experimental)

Recommended to use with advanced console emulators, e.g. Cmder

Via Chocolatey

choco install sampler

or

Download .exe

Docker

# Create a configuration file
vim config.yml

# Build the container image
docker build --tag sampler .

# Run a container
docker run --interactive --tty --volume $(pwd)/config.yml:/root/config.yml sampler --config /root/config.yml

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 an 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. See the SSH example

Contents

Components

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

Runchart

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

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

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

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

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

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

Bells and whistles

Triggers

Triggers allow to perform conditional actions, like visual/sound alerts or an arbitrary shell command. The following examples illustrate the concept.

Clock gauge, which shows minute progress and announces current time at the beginning of each minute

gauges:
  - title: MINUTE PROGRESS
    position: [[0, 18], [80, 0]]  
    cur:
      sample: date +%S
    max:
      sample: echo 60
    min:
      sample: echo 0
    triggers:
      - title: CLOCK BELL EVERY MINUTE
        condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'  # expects "1" as TRUE indicator
        actions:
          terminal-bell: true  # standard terminal bell, default = false
          sound: true    # NASA quindar tone, default = false
          visual: false  # notification with current value on top of the component area, default = false
          script: say -v samantha `date +%I:%M%p`  # an arbitrary script, which can use $cur, $prev and $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: curl -o /dev/null -s -w '%{time_total}'  https://www.google.com
      - label: YAHOO
        sample: curl -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" as TRUE indicator
        actions:
          terminal-bell: true  # standard terminal bell, default = false
          sound: true   # NASA quindar tone, default = false
          visual: true  # visual notification on top of the component area, default = false
          script: 'say alert: ${label} latency exceeded ${cur} second' # an arbitrary script, which can use $cur, $prev and $label variables

Interactive shell support

In addition to the sample command, one can specify init command (executed only once before sampling) and transform command (to post-process sample command output). That covers interactive shell use case, e.g. to establish connection to a database only once, and then perform polling within interactive shell session.

Basic mode

textboxes:
  - title: MongoDB polling
    rate-ms: 500
    init: mongo --quiet --host=localhost test # executes only once to start the interactive session
    sample: Date.now();                       # executes with a required rate, in scope of the interactive session
    transform: echo result = $sample          # executes in scope of local session, $sample variable is available for transformation

PTY mode

In some cases interactive shell won't work, because its stdin is not a terminal. We can fool it, using PTY mode:

textboxes:
  - title: Neo4j polling
    pty: true  # enables pseudo-terminal mode, default = false
    init: cypher-shell -u neo4j -p pwd --format plain
    sample: RETURN rand();
    transform: echo "$sample" | tail -n 1
  - title: Top on a remote server
    pty: true  # enables pseudo-terminal mode, default = false
    init: ssh -i ~/user.pem [email protected]
    sample: top    

Multistep init

It is also possible to execute multiple init commands one after another, before you start sampling.

textboxes:
  - title: Java application uptime
    multistep-init:
      - java -jar jmxterm-1.0.0-uber.jar
      - open host:port # or local PID
      - bean java.lang:type=Runtime
    sample: get Uptime

Variables

If the configuration file contains repeated patterns, they can be extracted into the variables section. Also variables can be specified using -v/--variable flag on startup, and any system environment variables will also be available in the scripts.

variables:
    mongoconnection: mongo --quiet --host=localhost test
barcharts:
  - title: MongoDB documents by 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

light-theme

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

Real-world recipes

Databases

The following are different database connection examples. Interactive shell (init script) usage is recommended to establish connection only once and then reuse it during sampling.

MySQL
# prerequisite: installed mysql shell

variables:
  mysql_connection: mysql -u root -s --database mysql --skip-column-names
sparklines:  
  - title: MySQL (random number example)
    pty: true
    init: $mysql_connection
    sample: select rand();
PostgreSQL
# prerequisite: installed psql shell

variables:
  PGPASSWORD: pwd
  postgres_connection: psql -h localhost -U postgres --no-align --tuples-only
sparklines:
  - title: PostgreSQL (random number example)
    init: $postgres_connection
    sample: select random();
MongoDB
# prerequisite: installed mongo shell

variables:
  mongo_connection: mongo --quiet --host=localhost test
sparklines:
  - title: MongoDB (random number example)
    init: $mongo_connection
    sample: Math.random();
Neo4j
# prerequisite: installed cypher shell

variables:
  neo4j_connection: cypher-shell -u neo4j -p pwd --format plain
sparklines:
  - title: Neo4j (random number example)
    pty: true
    init: $neo4j_connection
    sample: RETURN rand();
    transform: echo "$sample" | tail -n 1

Kafka

Kafka lag per consumer group
variables:
  kafka_connection: $KAFKA_HOME/bin/kafka-consumer-groups --bootstrap-server localhost:9092
runcharts:
  - title: Kafka lag per consumer group
    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

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 command on a remote server
variables:
  sshconnection: ssh -i ~/my-key-pair.pem [email protected]
textboxes:
  - title: SSH
    pty: true
    init: $sshconnection
    sample: top

JMX

Java application uptime example
# prerequisite: download [jmxterm jar file](https://docs.cyclopsgroup.org/jmxterm)

textboxes:
  - title: Java application uptime
    multistep-init:
      - java -jar jmxterm-1.0.0-uber.jar
      - open host:port # or local PID
      - bean java.lang:type=Runtime
    sample: get Uptime
    transform: echo $sample | tr -dc '0-9' | awk '{printf "%.1f min", $1/1000/60}'

sampler's People

Contributors

0xflotus avatar c00w avatar digitalcoyote avatar harmon758 avatar herbygillot avatar ivan-marquez avatar johnson-christopher avatar odinshat avatar pcgeek86 avatar sgarciac avatar simross avatar sqshq avatar the-louie avatar tim77 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sampler's Issues

Compilation error for ARM architecture

src/github.com/sqshq/sampler$ GOOS=linux GOARCH=arm go build
# github.com/hajimehoshi/oto
../../hajimehoshi/oto/context.go:69:12: undefined: newDriver

Scp in init returns a "write broken pipe" error

Hi, I try to copy a local script to my remote server in the init then execute it.

    - title: status
      #rate-ms: 60000
      multistep-init:
        - scp monit.sh raspberry:/tmp/monit.sh
        - ssh raspberry
      sample: sh /tmp/monit.sh

But the scp command seems to fail with the following error:

    SAMPLING FAILURE failed to execute command: write |1: broken pipe

All commands work properly outsite of sampler.
The monit.sh script is in the current working directory.
I also try to use absolute path with no success.

Tested on Ubuntu mate with amd-64 binary and the remote server is a raspberry pi.

Running on Linux ARM?

Hi folks! This looks great. I want to try it out on an ARM box of mine, but the executable doesn't work, of course. I'll grab the source and see if I can make it go, but any thoughts on adding an "advanced linux installation" section or something?

getPlatformStoragePath won't find my $HOME

(You make a commit, 8 hours after that someone complains about it. Internet is wild.)

In metadata/storage.go, the getPlatformStoragePath function is unable to find my $HOME:

2019/08/03 11:45:28 Failed to init storage: mkdir /.config: permission denied

$HOME is properly set and available in the environment variables.

I'm not a Go guy, but this may be related.

Thanks!

Create some pre-built configs

Currently there is a single example config file which serves as a great starting point, but it would be nice to have a few pre-built configs for people to drop in and go.

Some examples:

  • One designed entirely around Docker and monitoring container metrics.
  • Another designed to look pretty and having an overview of system metrics.

Failed to parse a number: strconv.ParseFloat on Runcharts

Set up exactly like in the tutorial. Running on ubuntu.

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

error

Sample output from 'curl -o /dev/null -s -w '%{time_total}' https://www.bing.com' : 0,435571

Support for Raspberry PI

I'm trying to set up sampler to work as a dashboard running on a Raspberry PI.
I managed to get it to compile on the PI but when i try to run it i get the following error:

# sampler --config conf.yml
panic: non-positive interval for NewTicker [recovered]
        panic: non-positive interval for NewTicker

goroutine 1 [running]:
main.handleCrash(0x108e5a0, 0x10708a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1075cc0)
        /root/sampler-1.0.3/main.go:127 +0x170
panic(0x339418, 0x100e198)
        /usr/lib/go-1.11/src/runtime/panic.go:513 +0x194
time.NewTicker(0xd964b800, 0xffffffff, 0x123a5a0)
        /usr/lib/go-1.11/src/time/tick.go:23 +0x1bc
github.com/sqshq/sampler/data.NewSampler(0x1085310, 0x1085320, 0x3, 0x4, 0x650634, 0x0, 0x0, 0x10708a0, 0x0, 0x0, ...)
        /root/sampler-1.0.3/data/sampler.go:20 +0x2c
main.(*Starter).start(0x10d7f30, 0x3eb490, 0x1183b80, 0x1085310, 0x107ad70, 0xb, 0x10759c0, 0x2, 0x2, 0x107bd88, ...)
        /root/sampler-1.0.3/main.go:68 +0x288
main.(*Starter).startAll(0x10d7f30, 0x1202000, 0x1196060, 0x1196090)
        /root/sampler-1.0.3/main.go:49 +0x538
main.main()
        /root/sampler-1.0.3/main.go:115 +0x26c

Cannot use MySQL query as a source for runcharts

Hi!

I'm trying to setup monitoring of number of records per minute in a table. It works like a charm when when using sparklines, but show nothing if I switch to runcharts.
Am I doing something wrong or MySQL is not supported for runcharts yet? Thank you!

variables:
  mysql_connection: mysql -u user -s --database someDBName  --skip-column-names
runcharts:
  - title: App log messages
    position: [[40, 0], [40, 24]]
    rate-ms: 1000
    legend:
        enabled: true
        details: true
    scale: 2
    items:
      - label: Errors
        init: $mysql_connection
        sample: SELECT RAND();
      - label: Warnings
        init: $mysql_connection
        sample: SELECT RAND();
sparklines:
  - title: MySQL (random number example)
    pty: true
    init: $mysql_connection
    sample: SELECT RAND();

[Suggestion] Variables that are shared across elements, but are run every sample time

So while making a stupidly long script for github status retrieving. i realised that i could probably have the speed increased a tonne if each of my elements were able to use the same data.

Specifically, say i have a json downloaded from github's API. and i parse any "usable" statistics from it (say issue count, pr count, stars, forks, watchers, commits, etc). normally i'd have to parse all that data on each element. what would be nice, is something similar to how you can have variables, you share it across multiple elements (same instance and etc), however it has a rate-ms still. other elements then use this variable in the multistep-init, or other things alike.

Would be nice to have.

Currently i could technically cache the data in a temp .json file or etc, but where's the fun in that?

Running sampler on catalina prompts alert...

------------- alert ------------------
“sampler-1.0.2-darwin-amd64” can’t be opened because its integrity cannot be verified.

This software needs to be updated. Contact the developer for more information.

Move to Trash | Cancel
------------- end alert --------------

Explicit min/max for sparklines and runcharts?

Can we explicitly set the min/max on the scale for sparklines and/or runcharts? I've tried and it doesn't seem to respond. I should probably just use gauges, but I like seeing the history. I'd just like to define the vertical axis' min/max.

I'm in love

Honestly, I have no real use for this, but I had to tell you how much I love it. I'm trying to find a use case, I love it so much.

Maybe if you made some way of working with Prometheus trivial?

But anyway, thanks for brightening my day!

rate-ms appears to be not honoured in gauges

I've set rate-ms to 10000 but it is updated at least once a second. The full block is:

gauges:
  - title: Memory used (MiB)
    position: [[0, 20], [20, 4]]
    rate-ms: 10000
    scale: 0
    color: 58
    cur:
      sample: env LC_ALL=C free -m | grep ^Mem | awk '{print $3}'
    max:
      sample: env LC_ALL=C free -m | grep ^Mem | awk '{print $2}'
    min:
      sample: echo 0
    triggers:
      - title: Low memory
        condition: '[ $label == "cur" ] && [ $cur -ge 15000 ] && echo 1 || echo 0'
        actions:
            visual: true

Allow nested components

It'd be nice to have something like:

--- My dashboard ----------------
| Component:1     | Component:2 |
|                               |
| Component:3                   |
---------------------------------

can't run on ubuntu server

I get this on ubuntu server 18.04

panic: oto: ALSA error: No such file or directory

goroutine 1 [running]:
github.com/sqshq/sampler/asset.NewAudioPlayer(0x0)
	/home/sqshq/go/src/github.com/sqshq/sampler/asset/player.go:24 +0x188
main.main()
	/home/sqshq/go/src/github.com/sqshq/sampler/main.go:86 +0xf0

encoding problems

I am using WSL (https://docs.microsoft.com/en-us/windows/wsl/install-win10) Debian GNU/Linux and I'm having problems with the encoding
/etc/default/locale:

#  File generated by update-locale
LC_ALL=C
LANGUAGE=en_US.UTF-8

/etc/default/keyboard:


# Consult the keyboard(5) manual page.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT="rus"
XKBOPTIONS=""

BACKSPACE="guess"

image

Windows version require SH

Windows version require sh but default command interpreter in Windows OS is cmd.exe

SAMPLING FAILURE exec: "sh": executable file not found in %PATH%

Исполняемый файл под Windows, пытается запустить внешние программы через SH. Командным интерпретатором в операционных системах Windows является cmd.exe.

Default config

Would it be possible to add either a default config location (Maybe user .config directory?) or a way to set a default location to always look for a config from?
Would mean you can just run the binary, rather than having to include the config flag. Just saves a little bit of time 😄

Feature Request - Reuse init command for multiple charts

The example configuration suggests using an init command for things that require some initial setup, such as getting performance metrics from a database server. In some cases, multiple charts may be fetching data from the same source, so it would be convenient if the sample instance of an init command could be reused somehow. This would be useful for e.g. setting up charts for multiple production servers, separately showing CPU load and RAM usage, where both data sets are coming from the same data source.

libasound is mandatory for startup on Linux

when trying to run on latest WSL with Ubuntu, getting the following error:
sampler: error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory

Feature Request - Runchart legend position

Before the actual request, just want to say that like others, I've only known about this tool for a few days and I already love it. Thank you so much for building it!

For run charts, is it possible to add an option for which corner to anchor the legend to? Since the most recent data is on the right, the legend sometimes covers up some of that data.

Add templating

Hi,

It could be great to have go template to loop over stuff in the yaml config file.

throws SIGSEV on WSL

Using sampler on Windows subsystem for linux throws SIGSEV.

Below is the config file used.

╭─nd33p@trv-wl-srenjith ~
╰─$ cat test.conf
variables:
  sshconnection: ssh [email protected]
textboxes:
  - title: SSH
    pty: true
    init: $sshconnection
    sample: top

Below are the errors thrown

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x463252] goroutine 45 [running]: io.WriteString(0x0, 0x0, 0xc0005b6018, 0x5, 0x0, 0xc0005b6018, 0x5) /usr/lib/go-1.12/src/io/io.go:293 +0xc2 github.com/sqshq/sampler/data.(*PtyInteractiveShell).execute(0xc0002ea000, 0x0, 0x0, 0x0, 0x0) /home/sqshq/go/src/github.com/sqshq/sampler/data/int_pty.go:70 +0x128 github.com/sqshq/sampler/data.(*Item).nextValue(0xc0000fe180, 0xc0001c0020, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0) /home/sqshq/go/src/github.com/sqshq/sampler/data/item.go:57 +0x60 github.com/sqshq/sampler/data.(*Sampler).sample(0xc0001a6120, 0xc0000fe180, 0xc0000906c0, 0x0, 0x0, 0x0, 0x0) /home/sqshq/go/src/github.com/sqshq/sampler/data/sampler.go:59 +0x58 created by github.com/sqshq/sampler/data.NewSampler.func1 /home/sqshq/go/src/github.com/sqshq/sampler/data/sampler.go:35 +0x86

Linux invalid memory addres or nil pointer deference on strart

Have crash at start after nothing changed (working config, open in vim, close vim, restart, not working config)
ArchLinux, linux 5.2.0, sampler v 1.0.2
Error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x555ea1784b2d]

goroutine 8 [running]:
main.verifyLicense(0xc000013c20, 0xc000013aa0)
	main.go:146 +0x2d
created by main.main
	main.go:107 +0x983

Config:

variables:
  sshconnection: ssh -C -i ~/.ssh/rsa_weak user@ip
runcharts:
  - title: Search engine response time
    init: $sshconnection
    pty: true
    position: [[0, 7], [40, 24]]
    rate-ms: 500
    legend:
        enabled: true
        details: false
    scale: 2
    items:
      - label: GOOGLE
        color: 178
        sample: curl -o /dev/null -s -w '%{time_total}'  https://www.google.com
      - 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
sparklines:
  - title: CPU usage
    position: [[40, 7], [40, 24]]
    rate-ms: 200
    scale: 0
    sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'
  - title: Free memory pages
    position: [[0, 0], [80, 8]]
    rate-ms: 200
    scale: 0
    sample: free | rg 'Mem' | awk '{print $3}'

Fix:

rm -r ~/.config/Sampler

Where is your color palette defined?

I'm trying to run your runcharts.yml example, but I'm not a fan of the color you chose for Google. It seems to me that it is closer to the color that should be used for Yahoo.

So, this has sent me down the rathole of trying to figure out where your color palette is defined, so that I can find the appropriate Web-safe or HTML color that would most appropriately represent different entities, and then map that back to the closest matching 8-bit color.

But I can't find anything anywhere in your repo that makes this mapping obvious.

Can you help me out here? Is there a standard Go reference that I'm not aware of? Thanks!

The first two lines of "top" output is not visible in textboxes

I don't see the top two lines (with uptime, load averages, taks, etc) of the "top" command output in textboxes.

This is the output of the command:

top - 16:17:43 up 1 day,  9:59,  1 user,  load average: 3.86, 5.15, 5.02
Tasks: 1955 total,   4 running, 1923 sleeping,   0 stopped,  28 zombie
%Cpu(s):  7.1 us,  2.2 sy,  0.0 ni, 89.6 id,  0.5 wa,  0.0 hi,  0.5 si,  0.0 st
KiB Mem : 73932664 total, 20585044 free, 42106204 used, 11241416 buff/cache
KiB Swap: 16777212 total, 16777212 free,        0 used. 29785392 avail Mem

This is what I see in a textbox:

┌─ SSH AP12-CTRL3 ─────────────────────────────────────────────────────────────────┐
│                                                                                  │
│ %Cpu(s): 25.8 us,  4.5 sy,  0.0 ni, 67.1 id,  1.6 wa,  0.0 hi,  1.1 si,  0.0 st  │
│ KiB Mem : 73932664 total, 19868300 free, 42800772 used, 11263592 buff/cache      │
│ KiB Swap: 16777212 total, 16777212 free,        0 used. 29081084 avail Mem       │
│     PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    │
│   40153 42435     20   0  505252 262224   2312 R  87.5  0.4 184:04.73 neutron-+  │
│   39890 42434     20   0   17.1g   1.8g 145996 S  78.5  2.6 642:54.60 mysqld     │
│   40149 42435     20   0  504192 261164   2312 S  75.0  0.4 184:18.85 neutron-+  │
│   36016 42439     20   0   19.5g   1.1g   4468 S  71.5  1.5 941:18.90 beam.smp   │
│   40146 42435     20   0  534168 284064   2312 S  62.5  0.4 174:22.72 neutron-+  │
│  398434 openvsw+  10 -10 2310908 107236  13752 S  39.0  0.1 198:12.35 ovs-vswi+  │
└──────────────────────────────────────────────────────────────────────────────────┘

I tried moving and resizing of the textbox, doesn't help. Textbox config is very simple:

  - title: SSH AP12-CTRL3
    position: [[0, 25], [50, 13]]
    rate-ms: 2000
    pty: true
    init: $ctrl3
    sample: top

I can see the two missing line if I change sample: top to sample: echo; top. But, these lines would be printed as second and third and the first line would contain data from the last:

┌─ SSH AP12-CTRL3 ─────────────────────────────────────────────────────────────────┐
│                                                                                  │
│ 24856 42435     20   0  652288 321340   8144 S   8.5  0.4 146:25.65 neutron-+    │
│ top - 16:24:08 up 1 day, 10:05,  2 users,  load average: 5.34, 5.88, 5.51        │
│ Tasks: 2025 total,   6 running, 1989 sleeping,   0 stopped,  30 zombie           │
│ %Cpu(s): 13.9 us,  3.0 sy,  0.0 ni, 81.7 id,  0.7 wa,  0.0 hi,  0.7 si,  0.0 st  │
│ KiB Mem : 73932664 total, 20154456 free, 42510780 used, 11267428 buff/cache      │
│ KiB Swap: 16777212 total, 16777212 free,        0 used. 29378672 avail Mem       │
│     PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    │
│   40148 42435     20   0  523576 274008   2312 R  92.5  0.4 179:48.86 neutron-+  │
│   36016 42439     20   0   19.5g   1.1g   4468 S  57.0  1.5 943:32.69 beam.smp   │
│   40151 42435     20   0  514352 271324   2312 R  56.0  0.4 179:21.51 neutron-+  │
└──────────────────────────────────────────────────────────────────────────────────┘

Cannot run sampler on MacOS Catalina [10.15 Beta (19A558d)]

When I try to run sampler from shell (both ZSH and BASH) I get an error popup saying that "Application sampler-1.0.3-darwin-amd64 cannot be opened, because its identity cannot be verified".

I suspect that it has to do something with Catalinas security improvements/enforcement.

Some problems about using software in centos 7

1、barcharts:
items:
- label: UDP bytes in
sample: nettop -J bytes_in -l 1 -m udp | awk '{sum += $4} END {print sum}'
Nettop is a command in mac. Can CentOS now use commands similar to this function to help? Thanks
2、asciiboxes
About the asciiboxes option。Whether I use it on the Mac or in centos, it doesn't show up. I'm wondering if there are additional steps that I haven't done, such as the requirement for date format. Seek your help。thanks
1565322972675
1565323006200

Linux/Ubuntu useful configurations/pipes thread

Hi,

This topic is dedicated to sharing useful pipes that enhances the sampler experience on GNU/Linux/Ubuntu. Don't hesistate to share! Here are mines:

HTOP
Requires: aha, html2text

textboxes:
  - title: HTOP
    rate-ms: 1000
    color: 122
    sample: echo q | htop -C | aha --line-fix | html2text -width 999 | grep -v "F1Help\|xml version="

HTOP OVER SSH
Requires: aha, html2text
Warning: Significant CPU load on devices such as raspberry pi.

textboxes:
  - title: HTOP
    rate-ms: 1000
    color: 121
    pty: true
    init: ssh -i ~/.ssh/id_rsa user@host
    sample: echo q | htop -C | aha --line-fix | html2text -width 999 | grep -v "F1Help\|xml version="

POSTGRESQL single line query

barcharts:
  - title: Database Distribution
    rate-ms: 180000
    scale: 0
    items:
      - label: Record Count
        sample: PGPASSWORD=PASSWORD psql -h host -U user --no-align --tuples-only -c 'select count(*) from tablename'

Periodic directory count
Requires: dircnt

barcharts:
  - title: Directory Counts
    rate-ms: 180000
    scale: 0
    items:
      - label: Master
        sample: /path/to/dircnt /path/to/target/directory/ | awk {'print $3'}

Free memory pages on Ubuntu

on ubuntu memory_pressure need change to free:

sample: memory_pressure | grep 'Pages free' | awk '{print $3}'

to

    sample: free -w | grep 'Mem' | awk '{print $3}'

but how the nettop command be solved on ubuntu ?

Unicode characters not rendering properly in WSL

Hi there, nice product btw

When I execute sampler with a sample config.yml file, the charts display a '?' inside a square where should be a point or a line to display the chart properly.

I guess this should be because my computer doesn't have the font, or the correct character to display.

Enviroment:
Ubuntu 18.04.2 LTS
Executing Ubuntu from windows throught WSL (not virtual machine!)

Segfault when asciibox contains a newline

If you try this config, it works:

asciiboxes:
  - title: ""
    sample: date +%r%D

Now try adding a newline in the date format (%n):

asciiboxes:
  - title: ""
    sample: date +%r%n%D

And I get:

panic: runtime error: index out of range

goroutine 36 [running]:
github.com/mbndr/figlet4go.(*font).getCharSlice(0xc00018e420, 0xc00000000a, 0xc0002ce4e0, 0x6, 0x6)
	/home/sqshq/go/src/github.com/mbndr/figlet4go/font.go:46 +0x1b9
github.com/mbndr/figlet4go.newAsciiChar(0xc00018e420, 0xc00000000a, 0xc0000122a0, 0x0, 0x0)
	/home/sqshq/go/src/github.com/mbndr/figlet4go/char.go:24 +0xa3
github.com/mbndr/figlet4go.(*AsciiRender).RenderOpts(0xc0001c8010, 0xc0000d2000, 0x14, 0xc0001ce070, 0x14, 0x0, 0x0, 0x0)
	/home/sqshq/go/src/github.com/mbndr/figlet4go/render.go:72 +0x108
github.com/sqshq/sampler/component/asciibox.NewAsciiBox.func1(0xc000252000)
	/home/sqshq/go/src/github.com/sqshq/sampler/component/asciibox/asciibox.go:62 +0x18a
created by github.com/sqshq/sampler/component/asciibox.NewAsciiBox
	/home/sqshq/go/src/github.com/sqshq/sampler/component/asciibox/asciibox.go:57 +0x5ff

Run actions on a textboxes item

Sometimes it might be useful to run a user-defined action for an item being monitored, e.g. kill/restart/reload etc. It looks like currently it only makes sense for textboxes items.

It would be nice if I can select an item and press enter to run a pre-configured action. Going further, there can be a pop-up menu with several items.

Web page mirroring

Probably not related to this project directly.
But I would love to have this dashboard both in the terminal with ssh access and as a web page.
Is there any simple way to generate dynamic html page based on terminal output?

FreeBSD support (Linux® Binary Compatibility)

Hello,
I have currently tested sampler on FreeBSD with Linux layer, I can not get past "License info", it seems that keyboard events are not working.
I have compiled sampler without that intro and I can see that sampler is indeed working on FreeBSD but like I said there is some issue with keyboard events handling.

There is a chance I will look more into it but let's for now just create an issue

ANSI-formated text in logs

Hi!
My logs are colour formatted using ANSI escape codes. But when I trying to "tail" them into textbox, I have got unformatted text, like: [31merror[39m, instead if red "error". Would you add ANSI support?

[Question] Triggers in textboxes

Hey guys, is it possible to use Triggers in Textboxes?
I'm trying to make a "ping machine" to determine whether the webserver is online. If not - make an alarm.

textboxes:
  - title: Google
    sample: curl -o /dev/null -s -w '%{http_code}'  https://google.com
    triggers:
      - title: Server down
        condition: echo "$cur != 200" | bc -l
        actions:
            visual: true
            script: 'say alert: ${label} server is Down'

Right now the config shows me an error: TRIGGER CONDITION FAILURE fork/exec /bin/sh: invalid argument

I can't figure out how can I overcome this. Please help :)

Feature request - Multiple display "pages"

Would it be possible to add some form of pages that can be switched between? Similar to how a security camera system has multiple cameras/ camera groupings that it flips through.

If you would have it if i made it, I would love to work on this myself.

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.