一官方網(wǎng)址
1夜鶯github網(wǎng)址:https://github.com/ccfos/nightingale
2這Flashcat官網(wǎng):https://flashcat.cloud/
相關(guān)包下載可以在github的Releases里面下載也可以在Flashcat官網(wǎng)下載
夜鶯的定位:定位類似于grafana。grafana更擅長看圖,夜鶯更擅長告警規(guī)則的管理(主打的多個團(tuán)隊(duì)權(quán)限的管理,項(xiàng)目的協(xié)同等等)
二夜鶯V6架構(gòu)
(一)中心匯聚式部署方案
-
Mysql:所有配置信息以及告警事件都存在mysql中,也可以用PG數(shù)據(jù)庫
(prometheus的告警事件存在內(nèi)存里面,重啟之后可能歷史告警沒有了), - Redis:V6版本主要存驗(yàn)證信息(jwt token)一些機(jī)器的元信息(對象列表里面的那些信息)
3. 時序庫:時序庫除了 Prometheus,還可以使用 VictoriaMetrics、M3DB 等
4. LB:前面建議有個LB,一般是nginx做七層代理就可以,n9e是http的
5. n9e:v5版本是webapi和server兩個模塊,v6是合成一個,多個n9e搭多個實(shí)例就可以組成一個集群,分擔(dān)告警處理,查詢的壓力。
n9e在通過promql查數(shù)據(jù)把請求proxy給時序庫或者在配置大盤或告警寫到mysql的邏輯中n9e是無狀態(tài)的。不過n9e作為告警引擎的時候是有狀態(tài)的,不過他會自動處理這個狀態(tài),比如lb后端有三個n9e,他們每個人處理100條告警規(guī)則的邏輯,當(dāng)一個n9e掛掉了,它處理的100條告警規(guī)則運(yùn)算邏輯會分配給另外兩臺(所以是可以直接擴(kuò)容的)。
6. 數(shù)據(jù)流:categraf采集監(jiān)控?cái)?shù)據(jù)以及元數(shù)據(jù)(cpu架構(gòu),cpu,內(nèi)存使用等),上報(bào)到LB,LB轉(zhuǎn)發(fā)給n9e,n9e會把metadata的信息寫到redis,還會從監(jiān)控?cái)?shù)據(jù)中提取ident的標(biāo)簽,如果是categraf采集的或者grafana agent采集的,服務(wù)器的標(biāo)識是agent hostname,就會識別成一個機(jī)器,然后重命名成ident寫到mysql里面target那個表里面去。
7. 接入其他的數(shù)據(jù)庫:直接在頁面上配datasource就可以了
8. 瓶頸:目前看瓶頸是在時序庫,目前看性能最好的是vm數(shù)據(jù)庫,具體看告警能承擔(dān)多少量收到機(jī)器配置,網(wǎng)絡(luò)帶寬,io,數(shù)據(jù)查詢頻率等等。所以最好是做灰度自己測。
(二)邊緣下沉式混雜部署方案
- 服務(wù)端部署同上
- 各個機(jī)房如果和中心網(wǎng)絡(luò)鏈路不好,則把時序庫、pushgw、alert下沉部署。categraf只把heartbeat繼續(xù)發(fā)送到中心去,把metrics推到本地的時序數(shù)據(jù)庫,n9e去查這部分?jǐn)?shù)據(jù)就去機(jī)房本地的時序庫去查,有可能會查詢比較慢,不過數(shù)據(jù)丟失是不會有的,因?yàn)檎麄€數(shù)據(jù)采集轉(zhuǎn)發(fā)存儲都是在機(jī)房內(nèi)完成的。
并且中間需要通過n9e-pushgw模塊,才能從數(shù)據(jù)中提取到ident機(jī)器信息寫到target的表,就不會在對象列表看到這臺機(jī)器,不過沒有n9e-pushgw這個模塊不影響告警和看圖,不過會影響告警自愈(告警自愈依賴于對象列表的業(yè)務(wù)組來做權(quán)限的控制)。n9e-alert去做告警判斷。 - 如果有部分categraf不能連通中心的lb,只需要在能連通中心lb的categraf機(jī)器上做一個nginx代理,讓heartbeat地址寫到nginx上,nginx代理中心端的n9e即可。
- 如果單獨(dú)有個k8s集群,里面部署了promtheus做監(jiān)控,如果這個機(jī)房到中心網(wǎng)絡(luò)也不好,就會在prometheus邊上部署n9e-alert,n9e-alert就會從mysql里面同步告警規(guī)則,去prometheus里面查詢數(shù)據(jù)做告警判斷。
三 二進(jìn)制部署
步驟命令搬運(yùn)自官網(wǎng),其他部署方式也可見官網(wǎng)
https://flashcat.cloud/docs/content/flashcat-monitor/nightingale/install/first/
(一)部署數(shù)據(jù)庫
- 夜鶯安裝依賴 mysql、redis,這兩個組件都是開源軟件
# install mysql
yum -y install mariadb*
systemctl enable mariadb
systemctl restart mariadb
mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');"
# install redis
yum install -y redis
systemctl enable redis
systemctl restart redis
- 配置數(shù)據(jù)源(時序庫)以VictoriaMetrics為例
下載地址:https://github.com/VictoriaMetrics/VictoriaMetrics/releases
單機(jī)版端口8428,每秒鐘監(jiān)控的數(shù)據(jù)點(diǎn)數(shù)小于100w,用單機(jī)的vm就足夠了
帶cluster的包是集群的,enterprise是企業(yè)版,類似選擇 victoria-metrics-linux-amd64-v1.90.0.tar.gz是社區(qū)的單機(jī)版
#解壓縮只有二進(jìn)制的文件,是通過參數(shù)來調(diào)整配置,而沒有配置文件.可以用systemctl管理
nohup ./victoria-metrics-prod &
特別注意VictoriaMetrics的單機(jī)和集群版在n9e的配置中url寫法不同,見后面的n9e部署
(二)部署n9e
- 在官網(wǎng)把包下載下來,解壓,配置,啟動服務(wù)
mkdir -p /opt/n9e && cd /opt/n9e
# 去 https://github.com/ccfos/nightingale/releases 找最新版本的包,文檔里的包地址可能已經(jīng)不是最新的了
tarball=n9e-v6.0.0-ga.4.0.1-linux-amd64.tar.gz
urlpath=https://download.flashcat.cloud/${tarball}
wget $urlpath || exit 1
tar zxvf ${tarball}
#進(jìn)入解壓目錄 導(dǎo)入n9e數(shù)據(jù)庫文件
mysql -uroot -p1234 < n9e.sql
- 配置,啟動服務(wù)
#可以進(jìn)入解壓目錄下的etc/config.toml,修改服務(wù)默認(rèn)端口以及數(shù)據(jù)庫的連接地址配置(特別注意VictoriaMetrics的單機(jī)和集群版配置url寫法不同)
[[Pushgw.Writers]]
#集群版VictoriaMetrics配置
# Url = "http://127.0.0.1:8480/insert/0/prometheus/api/v1/write"
#單機(jī)版ictoriaMetrics配置
# Url = "http://127.0.0.1:9090/api/v1/write"
#注意一定要修改配置文件中的HTTP各個部分的BasciAuth
#啟動服務(wù)
nohup ./n9e &> n9e.log &
# check logs tail ./n9e.log
#如果啟動成功,n9e 默認(rèn)會監(jiān)聽在 17000 端口。上面使用 nohup 簡單演示,生產(chǎn)環(huán)境建議用 systemd 托管
- 夜鶯服務(wù)端部署好之后,瀏覽器訪問 17000(默認(rèn)用戶是 root,密碼是 root.2020) 就可以體驗(yàn)相關(guān)功能了,然后修改默認(rèn)密碼
- 添加數(shù)據(jù)源,添加完數(shù)據(jù)源有數(shù)據(jù)推上來,就可以做查詢和告警了
(三)部署categraf
- 去官網(wǎng)下載categraf的壓縮包,解壓
- 修改categraf配置
#在目標(biāo)機(jī)器部署,只需要 categraf 二進(jìn)制、以及 conf 目錄,
#conf 下有一個主配置文件:config.toml,定義機(jī)器名、全局采集頻率、全局附加標(biāo)簽、remote write backend地址等;另外就是各種采集插件的配置目錄,以input.打頭,如果某個采集器 xx 不想啟用,把 input.xx 改個其他前綴(或者刪除這個目錄),比如 bak.input.xx,categraf 就會忽略這個采集器。
vim config.toml
#修改n9e的地址,通過這個地址來推數(shù)據(jù)
[[writers]]
url = "http://127.0.0.1:17000/prometheus/v1/write"
#修改heartbeat為true,里面的地址改成n9e的地址,通過這個地址來心跳
[heartbeat]
enable = true
# report os version cpu.util mem.util metadata
url = "http://127.0.0.1:17000/v1/n9e/heartbeat"
-
配置數(shù)據(jù)源文章來源:http://www.zghlxwxcb.cn/news/detail-487884.html
-
啟動categraf,啟動成功之后文章來源地址http://www.zghlxwxcb.cn/news/detail-487884.html
#啟動前測試
./categraf --test --debug
#啟動categraf.可以用nohup,不過最好可以用systemctl 托管
nohup ./categraf &
#啟動成功之后,在web頁面里面的對象列表可以看到這臺機(jī)器(因?yàn)樯厦娴膆eartbeat的配置,heartbeat的配置會上報(bào)redis,然后從redis里面讀的)
- 配置完categraf數(shù)據(jù)采集之后,能查到數(shù)據(jù)即正常
四n9e配置文件config.toml
[Global]
RunMode = "release"
[Log]
#Output 改成file日志就會輸出到Dir對應(yīng)的目錄中,需要配置日志切割,按照KeepHours的時間進(jìn)行切割,KeepHours= 4就是保存4個小時的日志?;蛘甙凑沾笮砬蟹?,RotateNum = 3 和RotateSize = 256 就是每個日志大小256m,保存3個
# log write dir
Dir = "logs"
# log level: DEBUG INFO WARNING ERROR
Level = "DEBUG"
# stdout, stderr, file
Output = "stdout"
# # rotate by time
# KeepHours= 4
# # rotate by size
# RotateNum = 3
# # unit: MB
# RotateSize = 256
[HTTP]
# http listening address
Host = "0.0.0.0"
# http listening port
Port = 17000
# https cert file path
CertFile = ""
# https key file path
KeyFile = ""
# whether print access log
PrintAccessLog = false
# whether enable pprof
PProf = false
# expose prometheus /metrics?
ExposeMetrics = true
# http graceful shutdown timeout, unit: s
ShutdownTimeout = 30
# max content length: 64M
MaxContentLength = 67108864
# http server read timeout, unit: s
ReadTimeout = 20
# http server write timeout, unit: s
WriteTimeout = 40
# http server idle timeout, unit: s
IdleTimeout = 120
下面這些BasicAuth接口的認(rèn)證信息注意改一下
[HTTP.Pushgw]
Enable = true
# [HTTP.Pushgw.BasicAuth]
# user001 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[HTTP.Alert]
Enable = true
[HTTP.Alert.BasicAuth]
user001 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[HTTP.Heartbeat]
Enable = true
# [HTTP.Heartbeat.BasicAuth]
# user001 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[HTTP.Service]
Enable = true
[HTTP.Service.BasicAuth]
user001 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
[HTTP.JWTAuth]
# signing key 注意改一下
SigningKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# unit: min
AccessExpired = 1500
# unit: min
RefreshExpired = 10080
RedisKeyPrefix = "/jwt/"
[HTTP.ProxyAuth]
# if proxy auth enabled, jwt auth is disabled
Enable = false
# username key in http proxy header
HeaderUserNameKey = "X-User-Name"
DefaultRoles = ["Standard"]
[DB]
# postgres: host=%s port=%s user=%s dbname=%s password=%s sslmode=%s
# 下面是mysql的dsn。上面是postgres的dsn寫法
DSN="root:1234@tcp(127.0.0.1:3306)/n9e_v6?charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true"
# enable debug mode or not
Debug = false
# mysql postgres
DBType = "mysql"
# unit: s
MaxLifetime = 7200
# max open connections
MaxOpenConns = 150
# max idle connections
MaxIdleConns = 50
# table prefix
TablePrefix = ""
# enable auto migrate or not
# EnableAutoMigrate = false
[Redis]
# address, ip:port or ip1:port,ip2:port for cluster and sentinel(SentinelAddrs) ga3可以支持集群版
Address = "127.0.0.1:6379"
# Username = ""
# Password = ""
# DB = 0
# UseTLS = false
# TLSMinVersion = "1.2"
# standalone cluster sentinel
RedisType = "standalone"
# Mastername for sentinel type
# MasterName = "mymaster"
# SentinelUsername = ""
# SentinelPassword = ""
[Alert]
[Alert.Heartbeat]
# auto detect if blank,為空會自動探測
IP = ""
# unit ms 告警引擎的心跳時間,默認(rèn)1000ms。多個n9e分?jǐn)偢婢钠ヅ洌瑢θ康母婢嬷行亩说男奶鴻C(jī)制
Interval = 1000
ClusterName = "default"
# [Alert.Alerting]
# NotifyConcurrency = 10
[Center]
MetricsYamlFile = "./etc/metrics.yaml"
I18NHeaderKey = "X-Language"
[Center.AnonymousAccess]
#是不是可以匿名訪問時序數(shù)據(jù)的接口,可以匿名訪問告警事件的詳情頁面,為了安全性可以改成false
PromQuerier = true
AlertDetail = true
[Pushgw]
# use target labels in database instead of in series
LabelRewrite = true
# # default busigroup key name
# BusiGroupLabelKey = "busigroup"
# ForceUseServerTS = false
# [Pushgw.DebugSample]
# ident = "xx"
# __name__ = "xx"
# [Pushgw.WriterOpt]
# # Writer Options
# QueueCount = 1000
# QueueMaxSize = 1000000
# QueuePopSize = 1000
# # ident or metric
# ShardingKey = "ident"
[[Pushgw.Writers]]
# Url = "http://127.0.0.1:8480/insert/0/prometheus/api/v1/write"
Url = "http://127.0.0.1:9090/api/v1/write"
# Basic auth username
BasicAuthUser = ""
# Basic auth password
BasicAuthPass = ""
# timeout settings, unit: ms
Headers = ["X-From", "n9e"]
Timeout = 10000
DialTimeout = 3000
TLSHandshakeTimeout = 30000
ExpectContinueTimeout = 1000
IdleConnTimeout = 90000
# time duration, unit: ms
KeepAlive = 30000
MaxConnsPerHost = 0
MaxIdleConns = 100
MaxIdleConnsPerHost = 100
## Optional TLS Config
# UseTLS = false
# TLSCA = "/etc/n9e/ca.pem"
# TLSCert = "/etc/n9e/cert.pem"
# TLSKey = "/etc/n9e/key.pem"
# InsecureSkipVerify = false
# [[Writers.WriteRelabels]]
# Action = "replace"
# SourceLabels = ["__address__"]
# Regex = "([^:]+)(?::\\d+)?"
# Replacement = "$1:80"
# TargetLabel = "__address__"
到了這里,關(guān)于夜鶯n9e監(jiān)控V6架構(gòu)以及部署(Nightingale)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!