Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux/Ubuntu useful configurations/pipes thread #34

Open
e4c6 opened this issue Aug 8, 2019 · 6 comments
Open

Linux/Ubuntu useful configurations/pipes thread #34

e4c6 opened this issue Aug 8, 2019 · 6 comments

Comments

@e4c6
Copy link

e4c6 commented Aug 8, 2019

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'}
@sqshq
Copy link
Owner

sqshq commented Aug 9, 2019

Hey @WaffleMongeringShit, thank you for sharing and starting the thread! I've pinned it.

btw I recommend to use init script to establish the database connection, otherwise it will be done each time the sample script is executed, which might cause unnecessary CPU utilization at higher update rates

@sqshq sqshq pinned this issue Aug 9, 2019
@aimbot31
Copy link

aimbot31 commented Aug 9, 2019

Kubernetes RAM, CPU, Events :
Requires : kubectl with a valid configuration

runcharts:
  - title: K8S Node Ram Usage
    position: [[0, 20], [40, 20]]
    rate-ms: 5000
    legend:
        enabled: true
        details: false
    scale: 0
    items:
      - label: node1
        color: 178
        sample: kubectl top nodes | awk 'NR==2 {printf "%d", $5}'
      - label: node2
        sample: kubectl top nodes | awk 'NR==3 {printf "%d", $5}'
      - label: node4
        sample: kubectl top nodes | awk 'NR==4 {printf "%d", $5}'
    triggers:
      - title: RAM usage exceeded
        condition: echo "$cur > 80" |bc -l
        actions:
          terminal-bell: true
          sound: true
          visual: true
          script: 'say alert: ${label} : RAM exceeded ${cur}% of usage'
  - title: K8S Node CPU Usage
    position: [[40, 20], [40, 20]]
    rate-ms: 5000
    legend:
        enabled: true
        details: false
    scale: 0
    items:
      - label: node1
        color: 178
        sample: kubectl top nodes | awk 'NR==2 {printf "%d", $3}'
      - label: node2
        sample: kubectl top nodes | awk 'NR==3 {printf "%d", $3}'
      - label: node4
        sample: kubectl top nodes | awk 'NR==4 {printf "%d", $3}'
    triggers:
      - title: CPU usage exceeded
        condition: echo "$cur > 80" |bc -l
        actions:
          terminal-bell: true
          sound: true
          visual: true
          script: 'say alert: ${label} : CPU exceeded ${cur}% of usage'
textboxes:
  - title: Kubernetes events
    position: [[0, 0], [80, 20]]
    rate-ms: 3000
    color: 211
    sample: kubectl get events -A | grep -e "Failed" -e "NAMESPACE"

@Asherslab
Copy link

Asherslab commented Aug 9, 2019

[Request]
Could someone make something for some nice Docker Swarm metrics?
Node metrics (maybe cpu and such) and stack metrics?

EDIT:
Also @sqshq you could make this a wiki page instead, and have additions to this issue added to it if wanted?

@Asherslab
Copy link

On another note. lemme throw in my small (and stupidly complicated) Bash script, and config, for github issues/pr count viewing.

BTW, only my second time writing a bash script. don't stab me =P

https://gist.github.com/Asherslab/2553dc63a95702563007e193e93878ae

a few example sections using the script:

Requirements: All these scripts require the jq bash command, plus the script above (yeah it's death)

View your projects open PRs vs Closed (in a gauge)

gauges:
  - title: "[ChatChain] Open Prs"
    rate-ms: 300000
    percent-only: false
    color: 178
    cur:
      sample: ./github.sh -n -r ldtteam/chatchain -s open -t pr
    max:
      sample: ./github.sh -n -r ldtteam/chatchain -s total -t pr
    min:
      sample: echo 0

View your project's open Issues vs Closed (in a gauge)

gauges:
  - title: "[ChatChain] Open Issues"
    rate-ms: 300000
    percent-only: false
    cur:
      sample: ./github.sh -n -r ldtteam/chatchain -s open -t issue
    max:
      sample: ./github.sh -n -r ldtteam/chatchain -s total -t issue
    min:
      sample: echo 0

View all stats in a simple text box

textboxes:
  - title: "[ChatChain] Status"
    position: [[1, 6], [23, 35]]
    rate-ms: 300000
    sample: ./github.sh -r ldtteam/chatchain

Note: there are rate limits on github's API. (you can increase them by using an API Key with the -u and -p parameters)

Note2: Large repositories take a decent while to load/whatever. The script could very much be improved. i'm probably gonna redo it in python or something similar at a later point. maybe

@Asherslab
Copy link

Asherslab commented Aug 10, 2019

So, after a days work. i improved upon my thing above.
Now, it's python, and faster, and better. does sometimes error though.

Python3 script: https://gist.github.com/Asherslab/1f37627854e913b86f088aa8ca30e8d0

i use a cache file to keep just one session accessing the api, so this is needed for all the elements below it:

This would definitely be improved by: #38
(instead of having cache.json)

Note: i have the rate-ms at 30 minutes because my repo was large and didn't wanna update too often. just be careful that you don't exceed github's rate limiting

textboxes:
  - title: ""
    position: [[0, 0], [0, 0]]
    rate-ms: 1800000
    sample: github/main.py output -k <GITHUB OAUTH KEY> -r ldtteam/minecolonies -f cache.json -l > /dev/null
    border: false

Sparklines for open and closed issues

sparklines:
  - title: Open Issues
    position: [[0, 6], [40, 9]]
    rate-ms: 2000
    sample: cat cache.json | github/main.py input -si -v issues.open
  - title: Closed Issues
    position: [[40, 6], [40, 9]]
    rate-ms: 2000
    sample: cat cache.json | github/main.py input -si -v issues.closed

Runcharts for issue labels

runcharts:
  - title: Issues
    position: [[0, 20], [80, 20]]
    rate-ms: 2000
    legend:
        enabled: true
        details: false
    scale: 2
    items:
      - label: Bug
        sample: cat cache.json | github/main.py input -si -v issues.labels.bug.open
      - label: Invalid
        sample: cat cache.json | github/main.py input -si -v issues.labels.invalid.open
      - label: Question
        sample: cat cache.json | github/main.py input -si -v issues.labels.question.open
      - label: In Progress
        sample: cat cache.json | github/main.py input -si -v issues.labels.in_progress.open

Text box for some data:

textboxes:
  - title: Pull Requests
    position: [[0, 15], [20, 5]]
    rate-ms: 2000
    sample: cat cache.json | github/main.py input -si --verbose -v pull_requests.open pull_requests.closed pull_requests.total pull_requests.labels.hotfix.open

ASCII box that uses the repo's name:

asciiboxes:
  - title: name
    position: [[0, 0], [26, 6]]
    rate-ms: 2000
    sample: cat cache.json | github/main.py input -si -v name

@aimbot31 aimbot31 mentioned this issue Aug 12, 2019
@umbynos
Copy link

umbynos commented Apr 10, 2020

Here's my contribution: CPU temperature runchart:

  - title: CPU Temp
    rate-ms: 1000        # sampling rate, default = 1000
    scale: 0            # number of digits after sample decimal point, default = 1
    legend:
      enabled: true     # enables item labels, default = true
      details: true    # enables item statistics: cur/min/max/dlt values, default = true
    items:
      - label: CPU Temp
        sample: cat /sys/class/thermal/thermal_zone2/temp | awk '{ print ($1 / 1000)}'
        color: 178      # 8-bit color number, default one is chosen from a pre-defined palette

PS: thermal_zone2 may not correspond with your CPU. I suggest to search it with cat /sys/class/thermal/thermal_zone*/type and find x86_pkg_temp, which in my case correspond to thermal_zone2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants