Waa maxay Prometheus iyo maxaad ugu baahan tahay?
Prometheus waa nidaam korjoogteyn awood leh kaas oo aruuriya oo socodsiiya xogta tirada (metrics) ee codsiyada. Waxay kaa caawinaysaa inaad la socoto tilmaamayaasha muhiimka ah sida:
- Tirada codsiyada uu qabtay adeeggaagu.
- Waqtiga jawaabta codsi kasta.
- Isticmaalka xusuusta iyo CPU.
- Tirada khaladaadka ka dhaca nidaamka
Adigoo isticmaalaya Prometheus, waxaad ka jawaabi kartaa su'aalaha muhiimka ah sida:
"Adeegaygu si hufan ma u shaqaynayaa?"
"Waa maxay caqabadaha wax qabadku?"
"Miyaan u baahanahay inaan kor u qaadno kaabayaashayaga?"
Oo sidee buu Prometheus u ururiyaa cabbirada?
Waxaa jira laba siyaabood oo aasaasiga ah ee Prometheus u ururiyo xogta:
- Qaabka Jiid - Prometheus waxay si firfircoon u waydiisaa adeegyada cabbirkooda.
- Habka riix (Pushgateway) - Adeegyadu waxay ku riixaan cabbirkooda dhexdhexaadiyaha, kaas oo Prometheus uu markaa ururiyo.
Aynu kala jebinno.
Jiid Model
Qaabka jiidashada , Prometheus wuxuu si firfircoon uga soo saarayaa cabbirada codsigaaga HTTP (tusaale, http://your-service:8080/metrics
).
Kani waa habka caadiga ah oo inta badan la isticmaalo.
Dejinta Prometheus leh Golang (Model Jiid)
Ku rakib maktabadaha lagama maarmaanka ah:
go get github.com/prometheus/client_golang/prometheus go get github.com/prometheus/client_golang/prometheus/promhttp
Qeex cabbirkaaga (tusaale, tirinta codsiyada HTTP):
import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" ) var httpRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{ Name: "http_requests_total", Help: "Total number of HTTP requests", })
Soo bandhig barta dhamaadka
/metrics
:import ( "net/http" "github.com/prometheus/client_golang/prometheus/promhttp" ) func main() { http.Handle("/metrics", promhttp.Handler()) }
Ku xidh Prometheus si aad u xoqdo mitirka adeegaaga
prometheus.yml
:scrape_configs: - job_name: "example_service" static_configs: - targets: ["localhost:8080"]
Hadda, Prometheus wuxuu si toos ah u waydiin doonaa http://localhost:8080/metrics
dhowr ilbiriqsi kasta si uu u ururiyo xogta.
Waa maxay sababta Model-jiidka loo door biday?
- Fududeynta - Prometheus waxay xakameysaa jadwalka xoqidda iyo inta jeer.
- Dhibco yar oo guuldarro ah - Looma baahna adeeg dheeraad ah si loo helo cabbirro.
- Nadiifin toos ah - Haddii adeeggu joojiyo ka jawaabista, Prometheus wuxuu si fudud u joojiyaa helitaanka xogta, isaga oo iska ilaalinaya cabbirada taagan.
Qaabka Riixitaanka (Pushgateway Approach)
Qaabka riixitaanka , adeeggu wuxuu u soo diraa mitirkiisa adeeg dhexdhexaad ah oo la yiraahdo Pushgateway , kaas oo kaydiya ilaa Prometheus ka soo qaado.
Sida ay u shaqeyso (Modelka riix)
Codsigaagu wuxuu u riixaa cabbirada Pushgateway:
import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/push" ) func main() { registry := prometheus.NewRegistry() jobCounter := prometheus.NewCounter(prometheus.CounterOpts{ Name: "job_execution_count", Help: "Number of executed jobs", }) registry.MustRegister(jobCounter) jobCounter.Inc() err := push.New("http://localhost:9090", "my_service_or_job"). Collector(jobCounter). Grouping("instance", "worker_1"). Push() if err != nil { panic(err) } }
Habee Prometheus si aad xogta uga soo ururiso Pushgateway:
scrape_configs: - job_name: "pushgateway" static_configs: - targets: ["localhost:9091"]
Goorma ayuu Dhab ahaantii Faa'iido u leeyahay Qaabka Riixa?
- Shaqooyinka muddada-gaaban (hawlaha dufcadda, shaqooyinka cron) ee dhammaystira ka hor inta uusan Prometheus xoqin.
- Xayiraadaha shabakada halka Prometheus uusan si toos ah u heli karin adeega.
- Ilaha xogta dibadda (qalabka IoT, API-yada dibadda) ee aan si toos ah loo xoqin karin.
Qaabkee Aad Isticmaalaysaa?
Habka | Waxa ugu fiican... | Faa'iidooyinka | Qasaarooyinka |
---|---|---|---|
Jiid (la taliyay) | Adeegyada shabakadda, API-yada, codsiyada muddada dheer socda | Habaynta fudud, ku tiirsanaanta yar, nadiifinta tooska ah | Aan ku habboonayn hawlo aad u gaaban |
Riix (Pushgateway) | Shaqooyinka Dufcadaha, hawlo aan lahayn marin shabakad deggan | Oggolow riixitaanka xogta shaqooyinka muddada gaaban | Xogta duugan, kakanaanta dheeraadka ah, khatarta carqaladaha |
Maxay tahay sababta riixitaanka Modelku ugu habboonayn?
In kasta oo Pushgateway ay xalliso dhibaatooyinka qaarkood (tusaale, geeddi-socodyada muddada-gaaban ee dhammaanaya ka hor inta uusan Prometheus xoqin), waxay soo bandhigaysaa dhowr arrimood oo cusub :
- Way adag tahay in la maareeyo xogta duugowday
Haddii adeeggu dhinto, cabbirkiisii hore ayaa ku hadhaya Pushgateway.
Prometheus ma laha hab lagu ogaado haddii adeeggu wali socdo.
Waa inaad gacanta ku tirtirtaa cabbirada duugoobay addoo isticmaalaya
push.Delete(...)
ama dejiso siyaasadaha dhicitaanka.
- Kakanaanta dheeraadka ah
Halkii laga heli lahaa Adeeg toos ah → Prometheus isku xirka, waxaad hadda haysataa Adeeg → Pushgateway → Prometheus .
Pushgateway waa ku-tiirsanaan dheeraad ah, kor u kaca dayactirka.
- Caqabado iman kara
Haddii adeegyo badani ay si joogto ah u riixaan cabbirada, Pushgateway waxay noqon kartaa culays.
Si ka duwan sida tooska ah ee Prometheus xoqid (kaas oo qaybiya culeyska), dhammaan codsiyada waxay ku dhufteen hal tusaale oo Pushgateway ah.
- Arrimaha joogtaynta xogta
- Haddii adeegyo badan ay riixaan mitiro isku magac leh laakiin qiimayaal kala duwan, xogta ayaa laga yaabaa in dib loo qoro, taasoo keenta natiijooyin khaldan.
Gabagabo
Prometheus waa qalab awood leh oo la isku halayn karo oo loogu talagalay la socodka adeegyada. Codsiyada intooda badan, qaabka jiidashada ayaa ah doorashada ugu fiican-waa mid fudud, hufan, oo hubisa xogta cusub iyada oo aan la helin kakanaanta dheeraadka ah. Si kastaba ha ahaatee, haddii aad la shaqaynayso geeddi-socod gaaban sida hawlaha Lambda ama shaqooyinka dufcadda, qaabka riixitaanka ee loo maro Pushgateway ayaa faa'iido u yeelan kara in la qabto cabbirka ka hor inta aan hawsha bixin.
Doorashada habka saxda ah waxay xaqiijinaysaa u fiirsashada wanaagsan iyo joogteynta nidaamkaaga.
Iska ilaali!