开源酷炫的Linux监控工具:sampler

sampler是一个开源的监控工具,来自GitHub用户sqshq(Alexander Lukyanchikov)的匠心之作。

简单来说,sampler能干这些事儿:

  • 实时监控:CPU、内存、磁盘、网络,甚至应用程序的状态,它都能盯着。
  • 可视化展示:支持多种组件,比如折线图、条形图、仪表盘,界面清爽又好看。
  • 警报提醒:当数据达到某个条件时,可以响铃、弹窗,甚至跑个脚本提醒你。
  • 高度自定义:通过YAML配置文件,想怎么玩就怎么玩。

比如,你可以用它监控CPU使用率、观察数据库的QPS,甚至盯着消息队列的消息堆积情况。

macOS安装

bash 复制代码
# 使用 HomeBrew 安装
brew install sampler

# 或直接下载安装
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安装

bash 复制代码
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

Windows安装

bash 复制代码
# 通过 Chocolatey 安装
choco install sampler

Docker安装

bash 复制代码
# 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

基本用法

1.创建 YAML 配置文件:定义你的监控命令。

2.运行命令:

复制代码
sampler -c config.yml

3.动态调整界面,实时查看你的监控指标。

配置文件内容参考

bash 复制代码
runcharts:
  - title: Search engine response time
    position: [[0, 0], [45, 19]]
    rate-ms: 500
    triggers:
      - title: Latency threshold exceeded
        condition: echo "$prev < 0.8 && $cur > 0.8" |bc -l
        actions:
            terminal-bell: true
            sound: true
            visual: true
            script: 'say alert: ${label} latency exceeded ${cur} second'
    legend:
        enabled: true
        details: false
    scale: 2
    items:
      - label: tencent
        color: 178
        sample: curl -o /dev/null -s -w '%{time_total}'  https://www.tencent.com
      - label: Bilibili
        sample: curl -o /dev/null -s -w '%{time_total}'  https://www.bilibili.com
      - label: Juejin
        sample: curl -o /dev/null -s -w '%{time_total}'  https://juejin.cn
barcharts:
  - title: Local network activity
    position: [[45, 20], [35, 8]]
    rate-ms: 500
    scale: 0
    items:
      - label: UDP bytes in
        sample: nstat -z | grep UdpInDatagrams | awk '{print $2}'
      - label: UDP bytes out
        sample: nstat -z | grep UdpOutDatagrams | awk '{print $2}'
      - label: TCP bytes in
        sample: nstat -z | grep TcpInSegs | awk '{print $2}'
      - label: TCP bytes out
        sample: nstat -z | grep TcpOutSegs | awk '{print $2}'
gauges:
  - title: YEAR PROGRESS
    position: [[45, 0], [35, 2]]
    cur:
        sample: date +%j
    max:
        sample: echo 365
    min:
        sample: echo 0
  - title: DAY PROGRESS
    position: [[45, 3], [35, 2]]
    cur:
        sample: date +%H
    max:
        sample: echo 24
    min:
        sample: echo 0
  - title: HOUR PROGRESS
    position: [[45, 6], [35, 2]]
    cur:
        sample: date +%M
    max:
        sample: echo 60
    min:
        sample: echo 0
  - title: MINUTE PROGRESS
    position: [[45, 9], [35, 2]]
    triggers:
      - title: CLOCK BELL EVERY MINUTE
        condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'
        actions:
            sound: true
            script: say -v samantha `date +%I:%M%p`
    cur:
        sample: date +%S
    max:
        sample: echo 60
    min:
        sample: echo 0
sparklines:
  - title: CPU usage
    position: [[0, 20], [22, 8]]
    rate-ms: 200
    scale: 0
    sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'
  - title: Free memory pages
    position: [[22, 20], [23, 8]]
    rate-ms: 200
    scale: 0
    sample: memory_pressure | grep 'Pages free' | awk '{print $3}'
textboxes:
  - title: Docker containers stats
    position: [[0, 29], [45, 10]]
    rate-ms: 500
    sample: docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.PIDs}}"
  - title: Local weather
    position: [[69, 31], [13, 7]]
    rate-ms: 10000
    sample: curl wttr.in?0ATQF
    border: false
  - title: New York weather
    position: [[45, 31], [13, 7]]
    rate-ms: 10000
    sample: curl wttr.in/newyork?0ATQF
    transform: echo 1
    border: false
  - title: San Francisco weather
    position: [[56, 31], [13, 7]]
    rate-ms: 10000
    sample: curl wttr.in/sanfrancisco?0ATQF
    border: false
asciiboxes:
  - title: UTC time
    position: [[45, 12], [35, 7]]
    rate-ms: 500
    sample: env TZ=UTC date +%r
    border: false
    font: 3d
相关推荐
爱吃山竹的大肚肚40 分钟前
EasyPOI 大数据导出
java·linux·windows
周杰伦_Jay1 小时前
【大模型数据标注】核心技术与优秀开源框架
人工智能·机器学习·eureka·开源·github
极地星光1 小时前
dmesg 工具的核心功能与作用
linux
雾削木1 小时前
k230 Pyhton三角形识别
运维·服务器·网络·stm32·智能路由器
玄魂2 小时前
如何查看、生成 github 开源项目star 图表
前端·开源·echarts
隐语SecretFlow2 小时前
【隐语Secreflow】如何配置 Kuscia 对请求进行 Path Rewrit
架构·开源
hh.h.2 小时前
开源鸿蒙生态下Flutter的发展前景分析
flutter·开源·harmonyos
福尔摩斯张2 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)
java·linux·c语言·数据结构·c++·驱动开发·算法
hgz07102 小时前
Linux服务器环境部署与JMeter压测准备
linux·服务器·jmeter
ShirleyWang0122 小时前
VMware如何导入vmdk文件
linux·数据库