# 安裝 Prometheus + Grafana ## Prometheus & Grafana ### Prometheus - 一個開源的系統監視工具 - 可以用來蒐集伺服器、VM、container或是整個 cluster 的各種指標 (Metrics) - 例如硬體資源利用率、網路使用、請求數量、負載壓力等 - 自帶儲存時序化資料的資料庫,可使用特有的 ProQL 語言進行查詢 - 本身支援簡單的資料視覺化功能,但無法產生較複雜的圖表 ### Grafana - 開源的資料視覺化工具 - 本身也可以進行指標蒐集,但也可以接受其他軟體提供的資料 - 常和 Prometheus 結合使用 ## Prometheus Operator - Prometheus 本身不侷限於 K8s,也可以用來監控實體機、VM 等各式不同環境 - 可以透過 Prometheus 的 Image,手動部屬 Prometheus - 過程較為繁瑣 - Prometheus Operator 是針對 K8s 的開發的管理工具 - 可以自動在 K8s 上部屬、設定所有相關的元件 - 自動化的在多個節點上管理、擴展 Prometheus - [Github: prometheus-operator](https://github.com/prometheus-operator/prometheus-operator) ### Kube-Prometheus-Stack - Kube-Prometheus-Stack 包含多個常和 Prometheus 一同使用的的工具 - 可以提供完整的、和 Prometheus 配套的 k8s 監控環境 - Prometheus - Prometheus Operator - Grafana - Alert Manager ## 透過 Helm 安裝 Kube-Prometheus-Stack ### 安裝 Helm - 請先安裝 Helm - 安裝方式可以參考 [官方文件](https://helm.sh/docs/intro/install/) - Ubuntu [安裝方式](https://helm.sh/docs/intro/install/#from-apt-debianubuntu) ```bash curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null sudo apt-get install apt-transport-https --yes echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list sudo apt update sudo apt install helm ``` ### 更新 repo 資訊 ```bash helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update ``` ### 部屬 Kube-Prometheus-Stack ```bash helm install kube-prometheus-stack \ prometheus-community/kube-prometheus-stack \ --namespace monitoring --create-namespace ``` <!-- ## 透過 yaml 安裝 Prometheus Operator ### 下載 YAML - 在 prometheus-operator 的 Github 中可以找到 [bundle.yaml](https://github.com/prometheus-operator/prometheus-operator/blob/main/bundle.yaml) - 此 yaml 除了 Prometheus Operator,還包含其他常一起使用的元件 - Prometheus - Grafana - Alertmanager - kube-state-metrics - prometheus-node-exporter - 複製 yaml 檔的 URL,使用 `wget` 下載檔案 ``` wget https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml ``` ### 部屬 ``` kubectl create -f bundle.yaml ``` - 所有的資源都會被部屬在 namespace `monitoring` 中 - 若所有 pod 都顯示 Ready 代表部屬成功 ``` kubectl get pod -n monitoring ``` -->