ကျွန်တော် ဒီနေ့ share ပေးမှာက alertmanager ကနေ google chat ကို alert ပို့တဲ့ အကြောင်းပဲဖြစ်ပါတယ်။ ကျွန်တော်တို့ဆီမှာ system တွေအများကြီးရှိတာမလို့ alert တွေကို configure လုပ်ထားဖို့ မဖြစ်မနေလိုပါတယ်။ ဒီနေ့ sharing အတွက် ကျွန်တော်ကတော့ kubernetes နဲ့ပဲ alert တွေအကြောင်း ကို ပြောပြပါမယ်။
alert တွေဘာလို့လုပ်ထားဖို့လိုလဲ
alert တွေ လုပ်ထားမှသာ cluster မှာ node တွေသေချာအလုပ်လုပ်နေလား pod တွေ အလုပ်လုပ်နေလားဆိုတာသိနိုင်မှာဖြစ်တယ်။ alert တွေသာလုပ်မထားဖူးဆိုရင် node တွေ service တစ်ခုခု down သွားတဲ့အခါ ကျွန်တော်တို့ သိနိုင်မှာမဟုတ်ဖူး။ downtime ဖြစ်ပြီဆိုတာနဲ့ business ကိုပါ impact ဖြစ်တော့မှာဆိုတော့ အတတ်နိုင်ဆုံး ကျွန်တော်တို့ရဲ့ system တွေကို downtime မရှိအောင် ထားရမယ်။ downtime ဖြစ်လာခဲ့ရင်လည်း အမြန်ဆုံးဖြေရှင်းနိုင်ဖို့ alerting သေချာလုပ်ထားရမယ်။ ဒီလောက်ဆို alert တွေ အရေးပါပုံကိုသိမယ်ထင်ပါတယ်။
Prometheus + Alertmanager အလုပ်လုပ်ပုံ
monitoring အတွက် အသုံးများတဲ့ tools တွေထဲကမှ prometheus က အသုံးအများဆုံးထဲကတစ်ခုဖြစ်တယ်။ သူတို့ ဘယ်လိုအလုပ်လုပ်လဲဆိုတော့ prometheus ကနေ kubernetes cluster ရဲ့ metrics တွေကို စောင့်ကြည့်ပေးတယ်။ prometheus alertmanager က ရလာတဲ့ raw metrics တွေကို slack, email တို့ဆီကို actionable alerts တွေအနေနဲ့ပြန်ပို့ပေးမှာဖြစ်ပါတယ်။ ဥပမာ - kubernetes pod တွေ crash ဖြစ်တဲ့အချိန်မျိုး node တွေ cpu ၊ memory ပြသနာတွေဖြစ်လာတဲ့အချိန်မျိုးတွေ မှာ alert ပို့ပေးမှာဖြစ်တယ်
Google Chat ကို ဘာကြောင့် တိုက်ရိုက် alert မပို့နိုင်တာလဲ
alertmanager က slack, email တို့ကို built-in support လုပ်တာမလို့ configure ချရတာလွယ်ပါတယ်။ ဒါပေမယ့် နောက်ပိုင်း google space ကိုသုံးလာကြတာများလို့ ဒီ post ကို share ပေးရခြင်းဖြစ်ပါတယ်။ google chat interface က simple webbhook ကိုသုံးပါတယ်။ json payload ကို ရိုးရိုးပဲလက်ခံတယ် ( eg. { "text": "Alert: High CPU usage on node xyz" } ) ဒါပေမယ့် alertmanager ကပို့လိုက်တဲ့ message တွေမှာ object တွေများတယ် ( eg. { "receiver": "webhook", "status": "firing", "alerts": [ ... ], } ) အဲ့ဒီ format က google chat လက်ခံနိုင်တဲ့ format နဲ့ အဆင်မပြေတာမလို့ alerts တွေကို ignore လုပ်ပြစ်လိုက်ပါတယ်။
ဘယ်လိုဖြေရှင်းမလဲ
ဒီပြသနာတွေကိုဖြေရှင်းဖို့အတွက် relay or translator တစ်ခုလိုပါတယ်။ relay က alertmanager webhook ကိုစောင့်ကြည့်နေတယ်။ တစ်နည်းအားဖြင့် တောက်လျှောက် alert manager ကို listen လုပ်နေတယ်ပေါ့။ ပြီးမှ အပေါ်ကပြထားတဲ့ ရလာတဲ့ json object alert တွေကို parse လုပ်ပေးတယ်။ ပြီးရင် google chat က လက်ခံပေးနိုင်မယ့် format အဖြစ်နဲ့ google chat ဆီကိုပြန်ပို့ပေးပါတယ်။
relay ကို pod အနေနဲ့ run မယ်
relay ကိုကျွန်တော်ကတော့ kubernetes pod အနေနဲ့ run ပါမယ်။ တခြား နည်းတွေနဲ့ run လည်းရပါတယ်။ run ဖို့အတွက်ဆို image ထွက်အောင် docker နဲ့ build လုပ်ပေးလိုက်ပါ။ လိုအပ်တဲ့ code နဲ့ dockerfile ကို အောက်မှာ share ပေးထားပါတယ်။
- https://gist.github.com/thaunghtike-share/3fe54cab7b1684cae15c188e310c480f
- https://gist.github.com/thaunghtike-share/6a8f5e11069793f5ac646342fc4e8df8
ရလာတဲ့ image ကိုမှ kubernetes pod အနေနဲ့ ပြန် run လိုက်ပါတယ်။ GOOGLE_CHAT_WEBHOOK နေရာမှာ ကိုယ့်ရဲ့ chat webhook api ကိုထည့်ပေးပါ။ ကျွန်တော်ကတော့ pod ကို monitoring namespace မှာပဲ run လိုက်ပါတယ်။ k8s ထဲမှာဆိုတော့ relay service ကို google-chat-relay.monitoring.svc.cluster.local/alert ဆိုပြီး လှမ်းခေါ်လို့ရပါပြီ။အောက်မှာ relay အတွက် လိုအပ်တဲ့ pod ပါ။
ကျွန်တော်ကတော့ prometheus-community/kube-prometheus-stack helm chart ကိုသုံးထားပါတယ်။ sample helm value ထဲကအတိုင်း လိုအပ်တဲ့ custom rule တွေသတ်မှတ်ပေးလို့ရပါပြီ။
ဒါဆိုရင်တော့ ကျွန်တော်တို့ google chat ထဲကို ဖတ်ရလွယ်တဲ့ alert တွေ google chat ထဲကိုရောက်လာမှာဖြစ်ပါတယ်။ အဆုံးထိဖတ်ပေးလို့ ကျေးဇူးတင်ပါတယ်။ အဆင်ပြေကြပါစေခင်ဗျာ
Discussion
Join the conversation
How do you feel about this article?
Comments
Sign in to join the conversation
Sign in to be the first to comment!
Share Your Article
Share with your professional network
Recent Articles

Day 2 - GitHub Actions ရဲ့ အဓိက Concepts များနှင့် Runner အကြောင်း
ပြီးခဲ့တဲ့အပတ် Day 1 တုန်းက ကျွန်တော်တို့ CI/CD ရဲ့ Concept တွေကို အကြမ်းဖျင်း ပြောခဲ့ကြပြီးပြီနော်။ ဒီနေရာမှာ လက်တွေ့မစ...
Day 1 - Software Development ကို ပိုပြီးမြန်စေမယ့် CI/CD
Software တစ်ခုရေးပြီးပြီဆိုရင် "ငါ့စက်ထဲမှာတော့ အလုပ်လုပ်တယ်" ဆိုရုံနဲ့ မပြီးသေးပါဘူး။ User တွေသုံးမယ့် Server ပေါ်ရောက်...

Secure AWS ECR Github Action Using OIDC
Modern DevOps နှင့် Cloud Security တို့မှာ အဓိကဖြစ်လာသည့် Authentication System ယနေ့ခေတ် DevOps, Cloud Engineering, CI/C...

Manual vs Automated Infrastructure: Why "useradd" Still Matters in the Terraform Era
DevOps careerကို လျှောက်နေတဲ့သူတိုင်း Terraform၊ Ansible စတဲ့ Infrastructure as Code (IaC) tools တွေရဲ့ အလုပ်လုပ်နိုင်စွ...
From Surviving to Thriving
“AI ကြောင့် developer အလုပ်ပျောက်သွားမလား?” ဆိုတဲ့ မေးခွန်းကို Junior developer တိုင်း စဉ်းစားဖူးကြမှာပါ။ ဈေးကွက်အခြေအနေ...

