我们开发了世界上最方便的*日志查看界面

如果您曾经使用过Web界面来查看日志,那么通常您可能已经注意到这些界面繁琐且(通常)非常不便且响应迅速。您可能已经习惯了一些,有些绝对是可怕的,但是在我看来,所有问题的原因是我们处理了错误地查看日志的任务:我们正在尝试创建一个Web界面,其中CLI(命令行界面)可以更好地工作。我个人非常喜欢使用tail,grep,awk和其他工具,因此对我来说,用于处理日志的理想界面应该类似于tail和grep,但同时可以用来读取来自许多服务器的日志... 那当然是从ClickHouse阅读它们!



*根据habrapuser的个人意见 你摇滚



认识logscli



我没有为接口命名,说实话,它只是一个原型而已,但是如果您想立即查看源代码,请欢迎:https : //github.com/YuriyNasretdinov/logscli(350行选定的Go代码) ...



能力



我的目标是要使习惯于tail / grep的用户熟悉的界面,即支持以下内容:



  1. 查看所有日志,无需过滤。
  2. 保留包含固定子字符串(-Fy标志grep)的字符串
  3. 保留与正则表达式(-Ey标志grep匹配的行
  4. 默认情况下,扫描按时间倒序进行,因为通常最先关注最新日志。
  5. ( -A, -B -C grep, N , , ).
  6. , ( tail -f | grep).
  7. less, head, tail — ; , ; SIGPIPE , , tail, grep UNIX-.




, - ClickHouse. , lsd kittenhouse, .



. , . , — , ClickHouse ( ~1 ).



, :



CREATE TABLE logs(
    category LowCardinality(String), --   ()
    time DateTime, --  
    millis UInt16, --  (   ,  ..):  ,   ,       
    ..., --   ,   ,  ,   
    message String --  
) ENGINE=MergeTree()
ORDER BY (category, time, millis)


, - , , Amazon 2015 . , , , .



Amazon ClickHouse

:



CREATE TABLE amazon(
   review_date Date,
   time DateTime DEFAULT toDateTime(toUInt32(review_date) * 86400 + rand() % 86400),
   millis UInt16 DEFAULT rand() % 1000,
   marketplace LowCardinality(String),
   customer_id Int64,
   review_id String,
   product_id LowCardinality(String),
   product_parent Int64,
   product_title String,
   product_category LowCardinality(String),
   star_rating UInt8,
   helpful_votes UInt32,
   total_votes UInt32,
   vine FixedString(1),
   verified_purchase FixedString(1),
   review_headline String,
   review_body String
)
ENGINE=MergeTree()
ORDER BY (time, millis)
SETTINGS index_granularity=8192


, , .



tsv- ~10-20, , 16 . TSV- :



for i in *.tsv; do
    echo $i;
    tail -n +2 $i | pv |
    clickhouse-client --input_format_allow_errors_ratio 0.5 --query='INSERT INTO amazon(marketplace,customer_id,review_id,product_id,product_parent,product_title,product_category,star_rating,helpful_votes,total_votes,vine,verified_purchase,review_headline,review_body,review_date) FORMAT TabSeparated'
done


Persistent Disk ( HDD) Google Cloud 1000 ( , , , SSD ) ~75 / 4 .



  • , Google,


, , .





ClickHouse full scan , , , . HTTP- , HTTP: send_progress_in_http_headers=1. , Go , HTTP 1.0 ( 1.1!) ClickHouse, TCP- ClickHouse, GET /?query=... HTTP/1.0\n\n - , .



ClickHouse



ClickHouse ( 2019 ?) ORDER BY,



SELECT time, millis, message
FROM logs
WHERE message LIKE '%something%'
ORDER BY time DESC, millis DESC


, message "something", .



, , ClickHouse , , . cancel_http_readonly_queries_on_client_close=1.



SIGPIPE Go



, , some_cmd | head -n 10, some_cmd , head 10 ? : head , pipe , stdout some_cmd , , «». some_cmd pipe, SIGPIPE, .



Go , SIGPIPE "signal: SIGPIPE" , , SIGPIPE , , :



ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGPIPE)
go func() {
    <-ch
    os.Exit(0)
}()




, - (, , ), grep -A, -B -C, , , .



, ClickHouse, , , ( , ):



SELECT time,millis,review_body FROM amazon
WHERE (time = '_' AND millis < _) OR (time < '_')
ORDER BY time DESC, millis DESC
LIMIT __
SETTINGS max_threads=1


, ClickHouse , CPU ( ~6 ).





, () , , timestamp, .





logscli ?



Amazon, , :



#  ,    walmart
$ logscli -F 'walmart' | less

#    10 ,   "terrible"
$ logscli -F terrible -limit 10

#     -limit:
$ logscli -F terrible | head -n 10

#   ,   /times [0-9]/,   vine     
$ logscli -E 'times [0-9]' -where="vine='Y' AND star_rating>4" | less

#      "panic"  3   
$ logscli -F 'panic' -C 3 | less

#       "5-star"
$ logscli -F '5-star' -tailf




( ) github https://github.com/YuriyNasretdinov/logscli. ClickHouse.




All Articles