自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

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

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

為什么我需要它?

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

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

安裝

macOS

  1. brew cask install sampler 

或 

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

Linux 

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

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

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

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

Download .exe

使用

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

使用Sampler基本上的三步過程:

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

運(yùn)行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)控的每臺(tái)服務(wù)器上都需要安裝嗎?

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

組件

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

Runchart

 

  1. runcharts:  
  2.   - title: Search engine response time  
  3.     rate-ms: 500        # sampling rate, default = 1000  
  4.     scale: 2            # number of digits after sample decimal point, default = 1  
  5.     legend:  
  6.       enabled: true     # enables item labels, default = true  
  7.       details: false    # enables item statistics: cur/min/max/dlt values, default = true  
  8.     items:  
  9.       - label: GOOGLE  
  10.         sample: curl -o /dev/null -s -w '%{time_total}'  https://www.google.com  
  11.         color: 178      # 8-bit color number, default one is chosen from a pre-defined palette  
  12.       - label: YAHOO  
  13.         sample: curl -o /dev/null -s -w '%{time_total}'  https://search.yahoo.com  
  14.       - label: BING  
  15.         sample: curl -o /dev/null -s -w '%{time_total}'  https://www.bing.com 

Sparkline

 

  1. sparklines:  
  2.   - title: CPU usage  
  3.     rate-ms: 200 
  4.      scale: 0  
  5.     sample: ps -A -o %cpu | awk '{s+=$1} END {print s}'  
  6.   - title: Free memory pages  
  7.     rate-ms: 200  
  8.     scale: 0  
  9.     sample: memory_pressure | grep 'Pages free' | awk '{print $3}' 

Barchart

 

  1. barcharts:  
  2.   - title: Local network activity  
  3.     rate-ms: 500        # sampling rate, default = 1000  
  4.     scale: 0            # number of digits after sample decimal point, default = 1  
  5.     items:  
  6.       - label: UDP bytes in  
  7.         sample: nettop -J bytes_in -l 1 -m udp | awk '{sum += $4} END {print sum}'  
  8.       - label: UDP bytes out  
  9.         sample: nettop -J bytes_out -l 1 -m udp | awk '{sum += $4} END {print sum}'  
  10.       - label: TCP bytes in  
  11.         sample: nettop -J bytes_in -l 1 -m tcp | awk '{sum += $4} END {print sum}'  
  12.       - label: TCP bytes out  
  13.         sample: nettop -J bytes_out -l 1 -m tcp | awk '{sum += $4} END {print sum}' 

Gauge

 

  1. gauges:  
  2.   - title: Minute progress  
  3.     rate-ms: 500        # sampling rate, default = 1000  
  4.     scale: 2            # number of digits after sample decimal point, default = 1  
  5.     percent-only: false # toggle display of the current value, default = false  
  6.     color: 178          # 8-bit color number, default one is chosen from a pre-defined palette  
  7.     cur:  
  8.       sample: date +%S  # sample script for current value  
  9.     max:  
  10.       sample: echo 60   # sample script for max value  
  11.     min:  
  12.       sample: echo 0    # sample script for min value  
  13.   - title: Year progress  
  14.     cur:  
  15.       sample: date +%j  
  16.     max:  
  17.       sample: echo 365  
  18.     min:  
  19.       sample: echo 0 

Textbox

 

  1. textboxes:  
  2.   - title: Local weather  
  3.     rate-ms: 10000      # sampling rate, default = 1000  
  4.     sample: curl wttr.in?0ATQF  
  5.     border: false       # border around the item, default = true  
  6.     color: 178          # 8-bit color number, default is white  
  7.   - title: Docker containers stats  
  8.     rate-ms: 500  
  9.     sample: docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.PIDs}}" 

Asciibox

 

  1. asciiboxes:  
  2.   - title: UTC time  
  3.     rate-ms: 500        # sampling rate, default = 1000  
  4.     font: 3d            # font type, default = 2d 
  5.     border: false       # border around the item, default = true    
  6.     color: 43           # 8-bit color number, default is white 
  7.      sample: env TZ=UTC date +%r 

額外功能

Triggers

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

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

  1. gauges:  
  2.   - title: MINUTE PROGRESS  
  3.     position: [[0, 18], [80, 0]]    
  4.     cur:  
  5.       sample: date +%S  
  6.     max:  
  7.       sample: echo 60  
  8.     min:  
  9.       sample: echo 0  
  10.     triggers:  
  11.       - title: CLOCK BELL EVERY MINUTE  
  12.         condition: '[ $label == "cur" ] && [ $cur -eq 0 ] && echo 1 || echo 0'  # expects "1" as TRUE indicator  
  13.         actions:  
  14.           terminal-bell: true  # standard terminal bell, default = false  
  15.           sound: true    # NASA quindar tone, default = false 
  16.            visual: false  # notification with current value on top of the component area, default = false  
  17.           script: say -v samantha `date +%I:%M%p`  # an arbitrary script, which can use $cur, $prev and $label variables 

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

  1. runcharts:  
  2.   - title: SEARCH ENGINE RESPONSE TIME (sec)  
  3.     rate-ms: 200  
  4.     items:  
  5.       - label: GOOGLE  
  6.         sample: curl -o /dev/null -s -w '%{time_total}'  https://www.google.com  
  7.       - label: YAHOO  
  8.         sample: curl -o /dev/null -s -w '%{time_total}'  https://search.yahoo.com    
  9.      triggers:  
  10.       - title: Latency threshold exceeded  
  11.         condition: echo "$prev < 0.3 && $cur > 0.3" |bc -l  # expects "1" as TRUE indicator  
  12.         actions:  
  13.           terminal-bell: true  # standard terminal bell, default = false  
  14.           sound: true   # NASA quindar tone, default = false  
  15.           visual: true  # visual notification on top of the component area, default = false  
  16.           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ù)庫的連接一次,然后在交互式shell會(huì)話中執(zhí)行輪詢。

Basic mode 

  1. textboxes:  
  2.   - title: MongoDB polling 
  3.     rate-ms: 500  
  4.     init: mongo --quiet --host=localhost test # executes only once to start the interactive session  
  5.     sample: Date.now();                       # executes with a required rate, in scope of the interactive session  
  6.     transform: echo result = $sample          # executes in scope of local session, $sample variable is available for transformation 

PTY mode

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

  1. textboxes:  
  2.   - title: Neo4j polling  
  3.     pty: true  # enables pseudo-terminal mode, default = false  
  4.     init: cypher-shell -u neo4j -p pwd --format plain  
  5.     sample: RETURN rand();  
  6.     transform: echo "$sample" | tail -n 1  
  7.   - title: Top on a remote server  
  8.     pty: true  # enables pseudo-terminal mode, default = false  
  9.     init: ssh -i ~/user.pem ec2-user@1.2.3.4  
  10.     sample: top 

init 命令逐步執(zhí)行

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

  1. textboxes:  
  2.   - title: Java application uptime  
  3.     multistep-init: 
  4.        - java -jar jmxterm-1.0.0-uber.jar  
  5.       - open host:port # or local PID  
  6.       - bean java.lang:type=Runtime  
  7.     sample: get Uptime 

變量

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

  1. variables:  
  2.     mongoconnection: mongo --quiet --host=localhost test  
  3. barcharts:  
  4.   - title: MongoDB documents by status  
  5.     items:  
  6.       - label: IN_PROGRESS  
  7.         init: $mongoconnection  
  8.         sample: db.getCollection('events').find({status:'IN_PROGRESS'}).count()  
  9.       - label: SUCCESS  
  10.         init: $mongoconnection  
  11.         sample: db.getCollection('events').find({status:'SUCCESS'}).count()  
  12.       - label: FAIL  
  13.         init: $mongoconnection  
  14.         sample: db.getCollection('events').find({status:'FAIL'}).count() 

顏色主題

 

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

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

數(shù)據(jù)庫

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

MySQL 

  1. # prerequisite: installed mysql shell  
  2. variables:  
  3.   mysql_connection: mysql -u root -s --database mysql --skip-column-names  
  4. sparklines:    
  5.   - title: MySQL (random number example)  
  6.     pty: true  
  7.     init: $mysql_connection  
  8.     sample: select rand(); 

PostgreSQL 

  1. # prerequisite: installed psql shell  
  2. variables:  
  3.   PGPASSWORD: pwd  
  4.   postgres_connection: psql -h localhost -U postgres --no-align --tuples-only  
  5. sparklines:  
  6.   - title: PostgreSQL (random number example)  
  7.     init: $postgres_connection  
  8.     sample: select random(); 

MongoDB 

  1. # prerequisite: installed mongo shell  
  2. variables:  
  3.   mongo_connection: mongo --quiet --host=localhost test  
  4. sparklines:  
  5.   - title: MongoDB (random number example)  
  6.     init: $mongo_connection 
  7.      sample: Math.random(); 

Neo4j 

  1. # prerequisite: installed cypher shell  
  2. variables:  
  3.   neo4j_connection: cypher-shell -u neo4j -p pwd --format plain  
  4. sparklines:  
  5.   - title: Neo4j (random number example)  
  6.     pty: true  
  7.     init: $neo4j_connection  
  8.     sample: RETURN rand();  
  9.     transform: echo "$sample" | tail -n 1 

Kafka

檢查kafka lag值,計(jì)算每個(gè)隊(duì)列l(wèi)ag值的和,高于閾值報(bào)警,多consumergroup,多topic。 

  1. variables:  
  2.   kafka_connection: $KAFKA_HOME/bin/kafka-consumer-groups --bootstrap-server localhost:9092  
  3. runcharts:  
  4.   - title: Kafka lag per consumer group  
  5.     rate-ms: 5000  
  6.     scale: 0  
  7.     items:  
  8.       - label: A-> 
  9.         sample: $kafka_connection --group group_a --describe | awk 'NR>1 {sum += $5} END {print sum}'  
  10.       - label: B-> 
  11.         sample: $kafka_connection --group group_b --describe | awk 'NR>1 {sum += $5} END {print sum}'  
  12.       - label: C-> 
  13.         sample: $kafka_connection --group group_c --describe | awk 'NR>1 {sum += $5} END {print sum}' 

Docker

Docker容器統(tǒng)計(jì)信息(CPU,MEM,O/I) 

  1. textboxes:  
  2.   - title: Docker containers stats  
  3.     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命令 

  1. variables:  
  2.   sshconnection: ssh -i ~/my-key-pair.pem ec2-user@1.2.3.4  
  3. textboxes:  
  4.   - title: SSH  
  5.     pty: true  
  6.     init: $sshconnection  
  7.     sample: top 

JMX

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

  1. # prerequisite: download [jmxterm jar file](https://docs.cyclopsgroup.org/jmxterm)  
  2. textboxes:  
  3.   - title: Java application uptime  
  4.     multistep-init:  
  5.       - java -jar jmxterm-1.0.0-uber.jar  
  6.       - open host:port # or local PID  
  7.       - bean java.lang:type=Runtime  
  8.     sample: get Uptime  
  9.     transform: echo $sample | tr -dc '0-9' | awk '{printf "%.1f min", $1/1000/60}'  

 

責(zé)任編輯:龐桂玉 來源: Linux學(xué)習(xí)
相關(guān)推薦

2024-12-13 15:36:27

命令行CLI數(shù)據(jù)可視化

2022-05-05 07:01:09

可視化代碼執(zhí)行工具

2020-03-11 14:39:26

數(shù)據(jù)可視化地圖可視化地理信息

2021-02-21 08:11:46

PythonDash工具

2023-04-14 08:21:55

2017-07-03 16:44:10

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

2022-03-03 13:02:37

可視化網(wǎng)頁低代碼編程工具

2021-02-07 20:23:09

GoogeBlockly可視化編程

2018-05-31 08:25:13

誤區(qū)工具可視化

2017-08-31 15:11:10

分析可視化大數(shù)據(jù)

2017-10-14 13:54:26

數(shù)據(jù)可視化數(shù)據(jù)信息可視化

2022-08-26 09:15:58

Python可視化plotly

2020-10-12 18:08:19

JVM技能工具

2018-09-26 16:15:31

數(shù)據(jù)可視化大數(shù)據(jù)數(shù)據(jù)分析

2009-04-21 14:26:41

可視化監(jiān)控IT管理摩卡

2017-04-19 08:32:50

大數(shù)據(jù)數(shù)據(jù)可視化編程工具

2021-04-14 16:20:39

可視化大數(shù)據(jù)工具

2023-05-06 12:57:34

Python工具

2012-06-21 13:42:50

Web

2024-08-20 14:31:16

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)