Sampler是一個用于shell命令執(zhí)行,可視化和告警的工具。其配置使用的是一個簡單的YAML文件。
1、為什么我需要它?
你可以直接從終端對任意動態(tài)進程進行采樣 – 觀察數(shù)據(jù)庫中的更改,監(jiān)控MQ動態(tài)消息(in-flight messages),觸發(fā)部署腳本并在完成后獲取通知。
如果有一種方法可以使用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
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系統(tǒng)庫用以播放觸發(fā)器聲音。通常庫已安裝在相應位置,但如果沒有 – 你可以使用你習慣的包管理器進行安裝,例如apt install libasound2-dev
Windows(實驗)
建議在高級控制臺模擬器下使用,如Cmder
Download .exe
3、使用
指定shell命令,Sampler會相應的速率執(zhí)行這些命令。輸出用于可視化。
使用Sampler基本上的三步過程:
在YAML配置文件中定義shell命令
運行sampler -c config.yml
在UI上調(diào)整組件大小和位置
市面早已有許多監(jiān)控系統(tǒng)
Sampler絕不是監(jiān)控系統(tǒng)的替代品,而是易于設(shè)置的開發(fā)工具。
如果spinning up和使用Grafana配置Prometheus是完全多余的任務(wù),那么Sampler可能是正確的解決方案。沒有服務(wù)器,沒有數(shù)據(jù)庫,不需要部署 – 你指定了shell命令,它就可以工作了。
我監(jiān)控的每臺服務(wù)器上都需要安裝嗎?
不,你可以在本地運行Sampler,但仍然可以從多臺遠程計算機上收集遙測數(shù)據(jù)。任何可視化都可能具有init命令,你可以在其中ssh到遠程服務(wù)器。請參閱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--format"table{{.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
觸發(fā)器允許執(zhí)行條件操作,如視覺/聲音告警或任意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'#expects"1"asTRUEindicator 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
搜索引擎延遲圖表,在延遲超過閾值時向用戶發(fā)出告警
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?&&?$cur?>0.3"|bc-l#expects"1"asTRUEindicator 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命令(在采樣前僅執(zhí)行一次)和transform命令(后處理采樣命令輸出)。這包括交互式shell用例,例如僅建立與數(shù)據(jù)庫的連接一次,然后在交互式shell會話中執(zhí)行輪詢。
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 命令逐步執(zhí)行
在開始采樣之前,還可以逐個執(zhí)行多個init命令。
textboxes: -title:Javaapplicationuptime multistep-init: -java-jarjmxterm-1.0.0-uber.jar -openhost:port#orlocalPID -beanjava.lang:type=Runtime sample:getUptime
變量
如果配置文件包含重復的模式,則可以將它們提取到變量部分。此外,還可以在啟動時使用-v/–variable標志指定變量,并且任意的系統(tǒng)環(huán)境變量也可以在腳本中使用。
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、真實場景
數(shù)據(jù)庫
以下是不同的數(shù)據(jù)庫連接示例。建議使用交互式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值,計算每個隊列l(wèi)ag值的和,高于閾值報警,多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容器統(tǒng)計信息(CPU,MEM,O/I)
textboxes: -title:Dockercontainersstats sample:dockerstats--no-stream--format"table{{.Name}} {{.CPUPerc}} {{.MemPerc}} {{.MemUsage}} {{.NetIO}} {{.BlockIO}} {{.PIDs}}"
SSH
遠程服務(wù)器上的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}'
責任編輯:lq
-
數(shù)據(jù)庫
+關(guān)注
關(guān)注
7文章
3926瀏覽量
66218 -
可視化
+關(guān)注
關(guān)注
1文章
1263瀏覽量
21862 -
Shell
+關(guān)注
關(guān)注
1文章
372瀏覽量
24216
原文標題:Shell 命令執(zhí)行可視化和告警工具
文章出處:【微信號:LinuxHub,微信公眾號:Linux愛好者】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
如何使用協(xié)議分析儀進行數(shù)據(jù)分析與可視化
VirtualLab Fusion應用:3D系統(tǒng)可視化
可視化組態(tài)物聯(lián)網(wǎng)平臺是什么
VirtualLab Fusion中的可視化設(shè)置
VirtualLab Fusion應用:光波導k域布局可視化(“神奇的圓環(huán)”)
七款經(jīng)久不衰的數(shù)據(jù)可視化工具!
光學系統(tǒng)的3D可視化
什么是大屏數(shù)據(jù)可視化?特點有哪些?
智慧能源可視化監(jiān)管平臺——助力可視化能源數(shù)據(jù)管理

評論