1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Shell 命令執(zhí)行可視化和告警工具

        共 10557字,需瀏覽 22分鐘

         ·

        2020-12-20 10:34


        點(diǎn)擊藍(lán)色“Python交流圈”關(guān)注我丫

        加個(gè)“星標(biāo)”,每天一起進(jìn)步一點(diǎn)點(diǎn)



        Sampler是一個(gè)用于shell命令執(zhí)行,可視化和告警的工具。其配置使用的是一個(gè)簡(jiǎn)單的YAML文件。

        1、為什么我需要它?

        你可以直接從終端對(duì)任意動(dòng)態(tài)進(jìn)程進(jìn)行采樣 – 觀察數(shù)據(jù)庫(kù)中的更改,監(jiān)控MQ動(dòng)態(tài)消息(in-flight messages),觸發(fā)部署腳本并在完成后獲取通知。

        如果有一種方法可以使用shell命令獲取指標(biāo)(metric),那么可以使用Sampler立即對(duì)其進(jìn)行可視化。

        2、安裝

        macOS

        brew?cask?install?sampler



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

        Linux

        sudo?wget?https://github.com/sqshq/sampler/releases/download/v1.0.3/sampler-1.0.3-linux-amd64?-O?/usr/local/bin/sampler
        sudo?chmod?+x?/usr/local/bin/sampler

        注意:需要為Sampler安裝libasound2-dev系統(tǒng)庫(kù)用以播放觸發(fā)器聲音。通常庫(kù)已安裝在相應(yīng)位置,但如果沒(méi)有 – 你可以使用你習(xí)慣的包管理器進(jìn)行安裝,例如apt install libasound2-dev

        Windows(實(shí)驗(yàn))

        建議在高級(jí)控制臺(tái)模擬器下使用,如Cmder

        Download .exe

        3、使用

        指定shell命令,Sampler會(huì)相應(yīng)的速率執(zhí)行這些命令。輸出用于可視化。

        使用Sampler基本上的三步過(guò)程:

        在YAML配置文件中定義shell命令

        運(yùn)行sampler -c config.yml

        在UI上調(diào)整組件大小和位置

        市面早已有許多監(jiān)控系統(tǒng)

        Sampler絕不是監(jiān)控系統(tǒng)的替代品,而是易于設(shè)置的開(kāi)發(fā)工具。

        如果spinning up和使用Grafana配置Prometheus是完全多余的任務(wù),那么Sampler可能是正確的解決方案。沒(méi)有服務(wù)器,沒(méi)有數(shù)據(jù)庫(kù),不需要部署 – 你指定了shell命令,它就可以工作了。

        我監(jiān)控的每臺(tái)服務(wù)器上都需要安裝嗎?

        不,你可以在本地運(yùn)行Sampler,但仍然可以從多臺(tái)遠(yuǎn)程計(jì)算機(jī)上收集遙測(cè)數(shù)據(jù)。任何可視化都可能具有init命令,你可以在其中ssh到遠(yuǎn)程服務(wù)器。請(qǐng)參閱SSH example

        4、組件

        以下是每種組件類(lèi)型的配置示例列表,其中包含與macOS兼容的采樣腳本。

        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

        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

        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

        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

        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

        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


        5、額外功能

        Triggers

        觸發(fā)器允許執(zhí)行條件操作,如視覺(jué)/聲音告警或任意shell命令。以下示例說(shuō)明了此概念。

        Clock gauge,從開(kāi)始的每分鐘顯示時(shí)間進(jìn)度和當(dāng)前時(shí)間

        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


        搜索引擎延遲圖表,在延遲超過(guò)閾值時(shí)向用戶(hù)發(fā)出告警

        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"?|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

        交互式 shell 支持

        除了sample命令之外,還可以指定init命令(在采樣前僅執(zhí)行一次)和transform命令(后處理采樣命令輸出)。這包括交互式shell用例,例如僅建立與數(shù)據(jù)庫(kù)的連接一次,然后在交互式shell會(huì)話(huà)中執(zhí)行輪詢(xún)。

        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

        在某些情況下,交互式shell將無(wú)法工作,因?yàn)樗膕tdin不是終端。這種情況下我們可以使用PTY模式:

        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?ec2-user@1.2.3.4
        ????sample:?top

        init 命令逐步執(zhí)行

        在開(kāi)始采樣之前,還可以逐個(gè)執(zhí)行多個(gè)init命令。

        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

        變量

        如果配置文件包含重復(fù)的模式,則可以將它們提取到變量部分。此外,還可以在啟動(dòng)時(shí)使用-v/–variable標(biāo)志指定變量,并且任意的系統(tǒng)環(huán)境變量也可以在腳本中使用。

        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()

        顏色主題

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


        6、真實(shí)場(chǎng)景

        數(shù)據(jù)庫(kù)

        以下是不同的數(shù)據(jù)庫(kù)連接示例。建議使用交互式shell(init腳本)僅建立一次連接,然后在采樣期間重用即可。

        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值,計(jì)算每個(gè)隊(duì)列l(wèi)ag值的和,高于閾值報(bào)警,多consumergroup,多topic。

        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容器統(tǒng)計(jì)信息(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

        遠(yuǎn)程服務(wù)器上的TOP命令

        variables:
        ??sshconnection:?ssh?-i?~/[email protected]
        textboxes:
        ??-?title:?SSH
        ????pty:?true
        ????init:?$sshconnection
        ????sample:?top

        JMX

        Java應(yīng)用程序的正常運(yùn)行示例

        #?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}'

        作者:secist

        鏈接:https://www.freebuf.com/sectool/212820.html


        --End--


        近期熱門(mén)推薦?

        1、打馬賽克就安全了嗎?AI消除馬賽克,GitHub開(kāi)源項(xiàng)目上線(xiàn)三天收獲近7000星

        2、垃圾分類(lèi)的正確姿勢(shì)?用 OpenCV 人工智能圖像識(shí)別技術(shù)來(lái)進(jìn)行

        3、Python 游戲編程之實(shí)現(xiàn)飛機(jī)大戰(zhàn)(含源代碼)

        4、用 Hypothesis 快速測(cè)試你的 Python 代碼

        5、別這樣直接運(yùn)行Python命令,否則電腦等于“裸奔”

        6、太sao了吧!微信可以改彩色昵稱(chēng)了?。?!

        7、同步與異步 Python 有何不同?

        8、厲害了!手?jǐn)]一個(gè)微信訂閱號(hào)鑒黃機(jī)器人!用起來(lái)很可以!

        9、大廠的 404 頁(yè)面都長(zhǎng)啥樣?看到最后一個(gè),我笑了。。。

        10、爬取QQ音樂(lè)全部歌曲

        關(guān)注公眾號(hào),回復(fù)“001”
        領(lǐng)取Python入門(mén)+進(jìn)階+實(shí)戰(zhàn)開(kāi)發(fā)92天全套視頻教程


        點(diǎn)贊最大的支持?

        瀏覽 60
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            久久成人五月天 | 啊~嗯去浴室做h老师双男主 | 红桃视频91| 日本乱大交xxxxx | 久久午夜电影院 | 成人电影999 | 国产按摩一区二区三区 | 国产女人高潮毛片 | 色噜噜在线 | 综合色综合色 |