sampler是一个用于shell命令执行,可视化和告警的工具。其配置使用的是一个简单的yaml文件。
1、为什么我需要它?
你可以直接从终端对任意动态进程进行采样 – 观察数据库中的更改,监控mq动态消息(in-flight messages),触发部署脚本并在完成后获取通知。
如果有一种方法可以使用shell命令获取指标(metric),那么可以使用sampler立即对其进行可视化。
2、安装
macos
brewcaskinstallsampler
或
sudocurl-lo/usr/local/bin/samplerhttps://github.com/sqshq/sampler/releases/download/v1.0.3/sampler-1.0.3-darwin-amd64 sudochmod+x/usr/local/bin/sampler
linux
sudowgethttps://github.com/sqshq/sampler/releases/download/v1.0.3/sampler-1.0.3-linux-amd64-o/usr/local/bin/sampler sudochmod+x/usr/local/bin/sampler
注意:需要为sampler安装libasound2-dev系统库用以播放触发器声音。通常库已安装在相应位置,但如果没有 – 你可以使用你习惯的包管理器进行安装,例如apt install libasound2-dev
windows(实验)
建议在高级控制台模拟器下使用,如cmder
download .exe
3、使用
指定shell命令,sampler会相应的速率执行这些命令。输出用于可视化。
使用sampler基本上的三步过程:
在yaml配置文件中定义shell命令
运行sampler -c config.yml
在ui上调整组件大小和位置
市面早已有许多监控系统
sampler绝不是监控系统的替代品,而是易于设置的开发工具。
如果spinning up和使用grafana配置prometheus是完全多余的任务,那么sampler可能是正确的解决方案。没有服务器,没有数据库,不需要部署 – 你指定了shell命令,它就可以工作了。
我监控的每台服务器上都需要安装吗?
不,你可以在本地运行sampler,但仍然可以从多台远程计算机上收集遥测数据。任何可视化都可能具有init命令,你可以在其中ssh到远程服务器。请参阅ssh example
4、组件
以下是每种组件类型的配置示例列表,其中包含与macos兼容的采样脚本。
runchart
runcharts: -title:searchengineresponsetime rate-ms:500#samplingrate,default=1000 scale:2#numberofdigitsaftersampledecimalpoint,default=1 legend: enabled:true#enablesitemlabels,default=true details:false#enablesitemstatistics:cur/min/max/dltvalues,default=true items: -label:google sample:curl-o/dev/null-s-w'%{time_total}'https://www.google.com color:178#8-bitcolornumber,defaultoneischosenfromapre-definedpalette -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:cpuusage rate-ms:200 scale:0 sample:ps-a-o%cpu|awk'{s+=$1}end{prints}' -title:freememorypages rate-ms:200 scale:0 sample:memory_pressure|grep'pagesfree'|awk'{print$3}'
barchart
barcharts: -title:localnetworkactivity rate-ms:500#samplingrate,default=1000 scale:0#numberofdigitsaftersampledecimalpoint,default=1 items: -label:udpbytesin sample:nettop-jbytes_in-l1-mudp|awk'{sum+=$4}end{printsum}' -label:udpbytesout sample:nettop-jbytes_out-l1-mudp|awk'{sum+=$4}end{printsum}' -label:tcpbytesin sample:nettop-jbytes_in-l1-mtcp|awk'{sum+=$4}end{printsum}' -label:tcpbytesout sample:nettop-jbytes_out-l1-mtcp|awk'{sum+=$4}end{printsum}'
gauge
gauges: -title:minuteprogress rate-ms:500#samplingrate,default=1000 scale:2#numberofdigitsaftersampledecimalpoint,default=1 percent-only:false#toggledisplayofthecurrentvalue,default=false color:178#8-bitcolornumber,defaultoneischosenfromapre-definedpalette cur: sample:date+%s#samplescriptforcurrentvalue max: sample:echo60#samplescriptformaxvalue min: sample:echo0#samplescriptforminvalue -title:yearprogress cur: sample:date+%j max: sample:echo365 min: sample:echo0
textbox
textboxes: -title:localweather rate-ms:10000#samplingrate,default=1000 sample:curlwttr.in?0atqf border:false#borderaroundtheitem,default=true color:178#8-bitcolornumber,defaultiswhite -title:dockercontainersstats rate-ms:500 sample:dockerstats--no-stream--formattable{{.name}} {{.cpuperc}} {{.memusage}} {{.pids}}
asciibox
asciiboxes: -title:utctime rate-ms:500#samplingrate,default=1000 font:3d#fonttype,default=2d border:false#borderaroundtheitem,default=true color:43#8-bitcolornumber,defaultiswhite sample:envtz=utcdate+%r
5、额外功能
triggers
触发器允许执行条件操作,如视觉/声音告警或任意shell命令。以下示例说明了此概念。
clock gauge,从开始的每分钟显示时间进度和当前时间
gauges: -title:minuteprogress position:[[0,18],[80,0]] cur: sample:date+%s max: sample:echo60 min: sample:echo0 triggers: -title:clockbelleveryminute condition:'[$label==cur]&&[$cur-eq0]&&echo1||echo0'#expects1astrueindicator actions: terminal-bell:true#standardterminalbell,default=false sound:true#nasaquindartone,default=false visual:false#notificationwithcurrentvalueontopofthecomponentarea,default=false script:say-vsamantha`date+%i:%m%p`#anarbitraryscript,whichcanuse$cur,$prevand$labelvariables
搜索引擎延迟图表,在延迟超过阈值时向用户发出告警
runcharts: -title:searchengineresponsetime(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:latencythresholdexceeded condition:echo$prev0.3|bc-l#expects1astrueindicator actions: terminal-bell:true#standardterminalbell,default=false sound:true#nasaquindartone,default=false visual:true#visualnotificationontopofthecomponentarea,default=false script:'sayalert:${label}latencyexceeded${cur}second'#anarbitraryscript,whichcanuse$cur,$prevand$labelvariables
交互式 shell 支持
除了sample命令之外,还可以指定init命令(在采样前仅执行一次)和transform命令(后处理采样命令输出)。这包括交互式shell用例,例如仅建立与数据库的连接一次,然后在交互式shell会话中执行轮询。
basic mode
textboxes: -title:mongodbpolling rate-ms:500 init:mongo--quiet--host=localhosttest#executesonlyoncetostarttheinteractivesession sample:date.now();#executeswitharequiredrate,inscopeoftheinteractivesession transform:echoresult=$sample#executesinscopeoflocalsession,$samplevariableisavailablefortransformation
pty mode
在某些情况下,交互式shell将无法工作,因为它的stdin不是终端。这种情况下我们可以使用pty模式:
textboxes: -title:neo4jpolling pty:true#enablespseudo-terminalmode,default=false init:cypher-shell-uneo4j-ppwd--formatplain sample:returnrand(); transform:echo$sample|tail-n1 -title:toponaremoteserver pty:true#enablespseudo-terminalmode,default=false init:ssh-i~/user.pemec2-user@1.2.3.4 sample:top
init 命令逐步执行
在开始采样之前,还可以逐个执行多个init命令。
textboxes: -title:javaapplicationuptime multistep-init: -java-jarjmxterm-1.0.0-uber.jar -openhost:port#orlocalpid -beanjava.lang:type=runtime sample:getuptime
变量
如果配置文件包含重复的模式,则可以将它们提取到变量部分。此外,还可以在启动时使用-v/–variable标志指定变量,并且任意的系统环境变量也可以在脚本中使用。
variables: mongoconnection:mongo--quiet--host=localhosttest barcharts: -title:mongodbdocumentsbystatus 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()
颜色主题
theme:light#default=dark sparklines: -title:cpuusage sample:ps-a-o%cpu|awk'{s+=$1}end{prints}'
6、真实场景
数据库
以下是不同的数据库连接示例。建议使用交互式shell(init脚本)仅建立一次连接,然后在采样期间重用即可。
mysql
#prerequisite:installedmysqlshell variables: mysql_connection:mysql-uroot-s--databasemysql--skip-column-names sparklines: -title:mysql(randomnumberexample) pty:true init:$mysql_connection sample:selectrand();
postgresql
#prerequisite:installedpsqlshell variables: pgpassword:pwd postgres_connection:psql-hlocalhost-upostgres--no-align--tuples-only sparklines: -title:postgresql(randomnumberexample) init:$postgres_connection sample:selectrandom();
mongodb
#prerequisite:installedmongoshell variables: mongo_connection:mongo--quiet--host=localhosttest sparklines: -title:mongodb(randomnumberexample) init:$mongo_connection sample:math.random();
neo4j
#prerequisite:installedcyphershell variables: neo4j_connection:cypher-shell-uneo4j-ppwd--formatplain sparklines: -title:neo4j(randomnumberexample) pty:true init:$neo4j_connection sample:returnrand(); transform:echo$sample|tail-n1
kafka
检查kafka lag值,计算每个队列lag值的和,高于阈值报警,多consumergroup,多topic。
variables: kafka_connection:$kafka_home/bin/kafka-consumer-groups--bootstrap-serverlocalhost:9092 runcharts: -title:kafkalagperconsumergroup rate-ms:5000 scale:0 items: -label:a->b sample:$kafka_connection--groupgroup_a--describe|awk'nr>1{sum+=$5}end{printsum}' -label:b->c sample:$kafka_connection--groupgroup_b--describe|awk'nr>1{sum+=$5}end{printsum}' -label:c->d sample:$kafka_connection--groupgroup_c--describe|awk'nr>1{sum+=$5}end{printsum}'
docker
docker容器统计信息(cpu,mem,o/i)
textboxes: -title:dockercontainersstats sample:dockerstats--no-stream--formattable{{.name}} {{.cpuperc}} {{.memperc}} {{.memusage}} {{.netio}} {{.blockio}} {{.pids}}
ssh
远程服务器上的top命令
variables: sshconnection:ssh-i~/my-key-pair.pemec2-user@1.2.3.4 textboxes: -title:ssh pty:true init:$sshconnection sample:top
jmx
java应用程序的正常运行示例
#prerequisite:download[jmxtermjarfile](https://docs.cyclopsgroup.org/jmxterm) textboxes: -title:javaapplicationuptime multistep-init: -java-jarjmxterm-1.0.0-uber.jar -openhost:port#orlocalpid -beanjava.lang:type=runtime sample:getuptime transform:echo$sample|tr-dc'0-9'|awk'{printf%.1fmin,$1/1000/60}'
光电晶体管的运作模式及规格参数
管理元器件停产的6个步骤
NVIDIA Instant NeRF赢得SIGGRAPH最佳论文
物联网易受攻击的原因
索尼发MWC邀请 Xperia 5 Plus有望亮相
Shell命令执行可视化和告警工具
活动预告 | 润和软件主办“科技创新优势推动医药产业高质量发展论坛”,议题抢鲜看
“全球IPv6峰会”入选“2022年IPv6规模部署和应用优秀案例”
CMOS图像传感器市场前景预期
小编科普一下DI/DO故障诊断流程
贸泽贸泽电子STM32H7系列MCU,能提升互联智能设备防护性能
Klari数据采集测量模块探头参数分享
如何选择数据采集系统中滤波器
车间无线呼叫系统实例分析
回顾超高灵敏度TMR磁开关传感器的性能介绍和应用
C8051F041的高精度频率计设计
铁总抛出大动作,高铁WiFi面向社会招商
面向未来AI世界,做当下观察、思考和感悟的“机器人文明”
以太坊代币ETH长期价值的四个关键问题分析
BOE(京东方)携手创维推出行业首款主动式玻璃基Mini LED显示器