建立在Poolboy的可靠性和Extrixir的強大力量之上的完整的Riemann客戶端!
riemannx是建立長生不老藥的Riemann客戶端,目前是Elixir中唯一支持UDP和TLS(以及TCP)的客戶。您還可以使用一個批處理模式,可與任何傳輸一起使用。
它具有實驗合併的選項,可以使TCP和UDP最好 - 在組合模式下,UDP是最喜歡的方法,但是如果消息大小超過最大UDP大小,則將使用TCP。
與往常一樣,在使用riemannx之前,需要有先決條件,其中大多數是顯而易見的(Elixir,Erlang),但包含一些有關對哪些版本進行測試和支持的信息。
目前,所有Erlang版本〜> 18均得到支持。這包括20、20.1尚未測試,但我預見到那裡沒有很大的問題。
由Travis測試:
18.019.320.0我試圖確保兼容性從1.3.4開始,並將在適當的情況下繼續這樣做。測試組合:
18.0 Elixir: 1.3.4 / 1.4.5 / 1.5.119.3 Elixir: 1.3.4 / 1.4.5 / 1.5.120.0 Elixir: 1.4.5 / 1.5.1通常,如果沒有服務器對應物,客戶端是無用的 - 有關Riemann的更多信息,請訪問http://riemann.io。
客戶只經過戰鬥測試: 0.2.11 。從客戶端的4.0.0版本中,如果您使用超過0.2.13的Riemann版本,並且自己不是自己設置時間字段,則需要將use_micro設置為false。它應該與0.3.0一起使用,但以前尚未經過測試(任何想在集成測試上工作的人都會非常感謝它)。
安裝就像其他任何Elixir庫一樣,將其添加到您的混合文件中,其餘的就是歷史記錄:
def deps do
[ { :riemannx , "~> 4.0" } ]
end確保將Riemannx添加到Mix.exs文件中的應用程序列表中,這還確保它可以從您的應用程序開始,並且它將包含在您的版本中(如果您使用Release Manager):
applications : [ :logger , :riemannx ] 要使用riemannx,您需要做的就是填寫一些配置條目 - 之後,一切都會自動化(除了實際的發送課程)。以下是可用選項的全面列表:
config :riemannx , [
host: "localhost" , # The riemann server
event_host: "my_app" , # You can override the host name sent to riemann if you want (see: Host Injection)
send_timeout: 30_000 , # Synchronous send timeout
checkout_timeout: 30_000 , # Timeout for checking out a poolboy worker
type: :batch , # The type of connection you want to run (:tcp, :udp, :tls, :combined, :batch)
settings_module: Riemannx.Settings.Default # The backend used for reading settings back
metrics_module: Riemannx . Metrics.Default # The backend used for sending metrics
use_micro: true # Set to false if you use a riemann version before 0.2.13
batch_settings: [
type : :combined # The underlying connection to use when using batching.
size: 50 , # The size of batches to send to riemann.
interval: { 1 , :seconds } , # The interval at which to send batches.
limit: :infinity # The max limit of batches allowed in the batching queue
]
tcp: [
port : 5555 ,
retry_count: 5 , # How many times to re-attempt a TCP connection
retry_interval: 1000 , # Interval to wait before the next TCP connection attempt (milliseconds).
priority: :high , # Priority to give TCP workers.
options: [ ] , # Specify additional options to be passed to gen_tcp (NOTE: [:binary, nodelay: true, packet: 4, active: true] will be added to whatever you type here as they are deemed essential)
pool_size: 5 , # How many TCP workers should be in the pool.
max_overflow: 5 , # Under heavy load how many more TCP workers can be created to meet demand?
strategy: :fifo # The poolboy strategy for retrieving workers from the queue
] ,
udp: [
port: 5555 ,
priority: :high ,
options: [ ] , # Specify additional options to be passed to gen_udp (NOTE: [:binary, sndbuf: max_udp_size()] will be added to whatever you type here as they are deemed essential)
max_size: 16_384 , # Maximum accepted packet size (this is configured in your Riemann server)
pool_size: 5 ,
max_overflow: 5 ,
strategy: :fifo
] ,
tls: [
port: 5554 ,
retry_count: 5 , # How many times to re-attempt a TLS connection
retry_interval: 1000 , # Interval to wait before the next TLS connection attempt (milliseconds).
priority: :high ,
options: [ ] , # Specify additional options to be passed to :ssl (NOTE: [:binary, nodelay: true, packet: 4, active: true] will be added to whatever you type here as they are deemed essential)
pool_size: 5 ,
max_overflow: 5 ,
strategy: :fifo
]
] riemannx支持兩種send方法,一種異步,另一個同步:
同步發送允許您處理在發送過程中可能發生的錯誤,以下是一個示例,既顯示此錯誤的外觀又顯示成功發送中發生的情況:
event = [ service: "riemannx-elixir" ,
metric: 1 ,
attributes: [ a: 1 ] ,
description: "test" ]
case Riemannx . send ( event ) do
:ok ->
"Success!"
[ error: error , msg: encoded_msg ] ->
# The error will always be a string so you can output it as it is.
#
# The encoded message is a binary blob but you can use the riemannx proto
# msg module to decode it if you wish to see it in human readable form.
msg = encoded_msg |> Riemannx.Proto.Msg . decode ( )
Logger . warn ( "Error: #{ error } Message: #{ inspect msg } " )
end異步發送的速度要快得多,但是您永遠不會真正知道您的消息是否製作了,在很多情況下,這種發送足夠安全,對於大多數用例,建議選擇。實施非常簡單:
event = [ service: "riemannx-elixir" ,
metric: 1 ,
attributes: [ a: 1 ] ,
description: "test" ]
Riemannx . send_async ( event )
# Who knows if it made it? Who cares? 60% of the time it works everytime!注意:如果工人無法發送它,將會死並重新開始,從而有機會返回“正確”狀態。在異步發送時,通過模式匹配來完成此操作:確定發送命令,對於同步發送,如果返回值是錯誤,則我們在返回結果之前殺死了該工人。
TLS支持使您可以使用Riemann Server使用安全的TCP連接,以了解有關如何設置此設置的更多信息:使用TLS安全Riemann流量
如果您選擇使用TLS,則將使用純粹的TCP設置,因此不支持(也不應該)與TLS:
config :riemannx , [
host: "127.0.0.1" ,
type: :tls ,
tls: [
port: 5554 ,
retry_count: 5 , # How many times to re-attempt a TLS connection
retry_interval: 1000 , # Interval to wait before the next TLS connection attempt (milliseconds).
priority: :high ,
# SSL Opts are passed to the underlying ssl erlang interface
# See available options here: http://erlang.org/doc/man/ssl.html
# (NOTE: [:binary, nodelay: true, packet: 4, active: true] will be added to whatever you type here as they are deemed essential)
options: [
keyfile: "path/to/key" ,
certfile: "path/to/cert" ,
verify_peer: true
] ,
pool_size: 5 ,
max_overflow: 5 ,
strategy: :fifo
]
]假設您已經正確設置了服務器端,那麼這應該是您需要啟動的全部。
Riemann具有可查詢索引的概念,該索引允許您搜索特定事件,必須在配置中特別創建索引,否則服務器將返回“無索引”錯誤。
# Lets send an event that we can then query
Riemannx . send ( [ service: "riemannx" , metric: 5.0 , attributes: [ v: "2.2.0" ] ] )
# Let's fish it out
events = Riemannx . query ( 'service ~= "riemannx"' )
# [%{attributes: %{"v" => "2.2.0"}, description: nil, host: _,
# metric: nil, service: "riemannx", state: nil, tags: [],
# time: _, ttl: _}]有關查詢和語言功能的更多信息,請查看核心概念。
本節包含一些有關Riemannx行為的註釋,這些註釋可能會對您感興趣或回答您對某些事情的問題。
截至4.0.0的批處理是默認連接行為 - 默認批處理大小為50,間隔為每1秒鐘。批處理的工作原理:
隊列中的任何內容都將發送每個間隔。
如果隊列的大小達到集合批量的大小,則無論間隔如何,都將被沖洗。
如果沒有工人可用於處理批處理,除非將checkout_timer設置為:infinity批次將被丟棄
有一個名為:batch和設置密鑰的新類型,稱為batch_settings:內部batch_settings您可以為基礎連接指定類型( :tcp , :udp , :combined ,:compined, :tls )。一如既往的組合是默認值。
可選地,可以指定批處理:limit limit )。如果設置,一旦批處理隊列具有指定數量的批次,那就是limit * batch_size事件,將刪除新事件,直到發送至少一批。默認值是:infinity
從Riemann的0.2.13版本中,可以在微秒中設置時間-Riemannx現在支持並使用time_micros字段(除非您自己設置了時間或time_micros字段,否則riemannx不會覆蓋該字段)。如果您使用的是舊版本的Riemann,則只會使用秒字段。
注意:如果您設置了Time和Time_micros Riemann,則將優先考慮微型時間,而Riemannx也不會覆蓋。
聽起來比它更奇特,但基本上描述瞭如果您沒有指定的功能,將主機條目添加到事件中。有3種指定主機的方法:
在發送事件之前執行此操作(將:主機密鑰添加到關鍵字列表)
將:event_host鍵添加到您的配置。
讓riemannx使用:inet.gethostname()進行操作 - 我們只調用一次並保存結果,並非在每個事件中調用。
最後兩個選項最有利,因為它們可以保持您的代碼清潔。
在這個客戶中,有機會為您的工人設定優先級,使您可以將統計數據發送到Riemann時更高或更少的優先級。
優先級設置的區別在很大程度上取決於硬件以及您如何設置其他優先級,可以在此處找到更多信息:http://erlang.org/doc/man/erlang.html#process_flag-2
如果您試圖將優先級設置為:Max Riemannx將提出一個RuntimeRoror,因為這是一個可怕的主意。如果您嘗試的話,它也會提高運行時間:因為這也是一個可怕的主意。
遷移到3.0本質上只是更改配置佈局的一種情況 - 所有相同的選項都存在,但現在您可以在類型級別上對工人進行更多的控制權,當您盡可能地使用組合的設置時,這尤其有價值,例如,TCP工人和較大的UDP Worker池量較小,而不是較大的UDP Worker Pool,而不是2x的pool_size_size_size_size_size_size_size_size you)。
您可以在這裡看到此新佈局:配置
如果有任何東西沒有意義,這裡可以隨意打開一個問題,以便我們可以擴展讀書文件以修復不持久性。
如果要將設置存儲在其他地方,則可以創建一個後端以從數據庫中讀取設置。查看所需回調的默認設置模塊。
如果您想將公司範圍的設置存儲在一個地方,這將很有用。
如果您有疑問,請隨時打開問題。
riemannx支持發送基本指標,您可以創建一個自定義模塊來支持任何基礎架構(石墨,湧入等)。目前有3個回調:
udp_message_sent(size) - 通知何時發送UDP消息並給出消息的大小。tcp_message_sent(size) - 通知何時發送TCP消息並給出消息的大小。tls_message_sent(size) - 通知何時發送TLS消息並給出消息的大小。 捐款得到熱烈接收,請查看“項目”部分,以獲取我寫下的一些想法,以及有關正在進行的內容的最新想法。
該存儲庫使用gitflow工作流,這意味著所有公關都應指向開發分支! 。以下是創建PR之前需要考慮的一些事情:
我想維持100%的測試覆蓋範圍! - 我可能會在緊急情況(錯誤等)中滑動。
為了避免不必要的Travis擁塞,如果您首先在本地檢查以下情況:
mix coveralls.html (目標100%)mix dialyzer (需要一段時間,我感謝您無法測試所有Erlang/Elixir版本)我認為此客戶端功能完成,如果您的PR完全向後兼容或更改預先存在的行為/默認情況,我會很喜歡抬頭和您的理由:)。
一部分代碼已從原始的Elixir-Riemann客戶端借用。大多數Protobuf東西都來自那裡。