什麼是普羅米修斯?
Prometheus是最初在SoundCloud上構建的開源系統監視和警報工具包 。html
自2012年成立以來,許多公司和組織都採用了Prometheus,該項目擁有很是活躍的開發人員和用戶社區。node
組件說明
- MetricServer:是kubernetes集羣資源使用狀況的聚合器,收集數據給kubernetes集羣內使用,如kubectl,hpa,scheduler等。
- PrometheusOperator:是一個系統監測和警報工具箱,用來存儲監控數據。
- NodeExporter:用於各node的關鍵度量指標狀態數據。
- KubeStateMetrics:收集kubernetes集羣內資源對象數據,制定告警規則。
- Prometheus:採用pull方式收集apiserver,scheduler,controller-manager,kubelet組件數據,經過http協議傳輸。
- Grafana:是可視化數據統計和監控平臺。
系統架構
何時合適?
Prometheus很是適合記錄任何純數字時間序列。git
它既適合以機器爲中心的監視,也適合於高度動態的面向服務的體系結構的監視。在微服務世界中,它對多維數據收集和查詢的支持是一種特別的優點。github
Prometheus的設計旨在提升可靠性,使其成爲中斷期間要使用的系統,以使您可以快速診斷問題。api
每一個Prometheus服務器都是獨立的,而不依賴於網絡存儲或其餘遠程服務。當基礎結構的其餘部分損壞時,您能夠依靠它,而且無需設置普遍的基礎結構便可使用它。服務器
何時不合適?
普羅米修斯重視可靠性。即便在故障狀況下,您始終能夠查看有關係統的可用統計信息。網絡
若是您須要100%的準確性(例如按請求計費),則Prometheus並非一個不錯的選擇,由於所收集的數據可能不會足夠詳細和完整。架構
在這種狀況下,最好使用其餘系統來收集和分析數據以進行計費,並使用Prometheus進行其他的監視。app
部署安裝
Github : https://github.com/coreos/kube-prometheuside
一、下載官方源碼文件(默認鏡像源來自quay.io)
wget -o kube-prometheus.tgz https://github.com/coreos/kube-prometheus/archive/v0.3.0.tar.gz
- 固然,若是你的國外網不太友好,也能夠下載本人百度雲文件(已修改鏡像源到aliyuncs)kube-prometheus.tgz(eb3m )
二、解壓並部署安裝
tar -zxvf kube-prometheus.tgz && cd kube-prometheus-0.3.0/manifests
kubectl create -f setup
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done
kubectl create -f .
![]()
ls -R[root@k8s-32 manifests]# ls -R .: alertmanager-alertmanager.yaml kube-state-metrics-service.yaml prometheus-clusterRole.yaml alertmanager-secret.yaml node-exporter-clusterRoleBinding.yaml prometheus-operator-serviceMonitor.yaml alertmanager-serviceAccount.yaml node-exporter-clusterRole.yaml prometheus-prometheus.yaml alertmanager-serviceMonitor.yaml node-exporter-daemonset.yaml prometheus-roleBindingConfig.yaml alertmanager-service.yaml node-exporter-serviceAccount.yaml prometheus-roleBindingSpecificNamespaces.yaml grafana-dashboardDatasources.yaml node-exporter-serviceMonitor.yaml prometheus-roleConfig.yaml grafana-dashboardDefinitions.yaml node-exporter-service.yaml prometheus-roleSpecificNamespaces.yaml grafana-dashboardSources.yaml prometheus-adapter-apiService.yaml prometheus-rules.yaml grafana-deployment.yaml prometheus-adapter-clusterRoleAggregatedMetricsReader.yaml prometheus-serviceAccount.yaml grafana-serviceAccount.yaml prometheus-adapter-clusterRoleBindingDelegator.yaml prometheus-serviceMonitorApiserver.yaml grafana-serviceMonitor.yaml prometheus-adapter-clusterRoleBinding.yaml prometheus-serviceMonitorCoreDNS.yaml grafana-service.yaml prometheus-adapter-clusterRoleServerResources.yaml prometheus-serviceMonitorKubeControllerManager.yaml kube-state-metrics-clusterRoleBinding.yaml prometheus-adapter-clusterRole.yaml prometheus-serviceMonitorKubelet.yaml kube-state-metrics-clusterRole.yaml prometheus-adapter-configMap.yaml prometheus-serviceMonitorKubeScheduler.yaml kube-state-metrics-deployment.yaml prometheus-adapter-deployment.yaml prometheus-serviceMonitor.yaml kube-state-metrics-roleBinding.yaml prometheus-adapter-roleBindingAuthReader.yaml prometheus-service.yaml kube-state-metrics-role.yaml prometheus-adapter-serviceAccount.yaml setup kube-state-metrics-serviceAccount.yaml prometheus-adapter-service.yaml kube-state-metrics-serviceMonitor.yaml prometheus-clusterRoleBinding.yaml ./setup: 0namespace-namespace.yaml prometheus-operator-0prometheusruleCustomResourceDefinition.yaml prometheus-operator-deployment.yaml prometheus-operator-0alertmanagerCustomResourceDefinition.yaml prometheus-operator-0servicemonitorCustomResourceDefinition.yaml prometheus-operator-serviceAccount.yaml prometheus-operator-0podmonitorCustomResourceDefinition.yaml prometheus-operator-clusterRoleBinding.yaml prometheus-operator-service.yaml prometheus-operator-0prometheusCustomResourceDefinition.yaml prometheus-operator-clusterRole.yaml![]()
kubectl create -f .[root@k8s-32 manifests]# kubectl create -f setup/. namespace/monitoring created customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created clusterrole.rbac.authorization.k8s.io/prometheus-operator created clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator created deployment.apps/prometheus-operator created service/prometheus-operator created serviceaccount/prometheus-operator created [root@k8s-32 manifests]# kubectl create -f . alertmanager.monitoring.coreos.com/main created secret/alertmanager-main created service/alertmanager-main created serviceaccount/alertmanager-main created servicemonitor.monitoring.coreos.com/alertmanager created secret/grafana-datasources created configmap/grafana-dashboard-apiserver created configmap/grafana-dashboard-cluster-total created configmap/grafana-dashboard-controller-manager created configmap/grafana-dashboard-k8s-resources-cluster created configmap/grafana-dashboard-k8s-resources-namespace created configmap/grafana-dashboard-k8s-resources-node created configmap/grafana-dashboard-k8s-resources-pod created configmap/grafana-dashboard-k8s-resources-workload created configmap/grafana-dashboard-k8s-resources-workloads-namespace created configmap/grafana-dashboard-kubelet created configmap/grafana-dashboard-namespace-by-pod created configmap/grafana-dashboard-namespace-by-workload created configmap/grafana-dashboard-node-cluster-rsrc-use created configmap/grafana-dashboard-node-rsrc-use created configmap/grafana-dashboard-nodes created configmap/grafana-dashboard-persistentvolumesusage created configmap/grafana-dashboard-pod-total created configmap/grafana-dashboard-pods created configmap/grafana-dashboard-prometheus-remote-write created configmap/grafana-dashboard-prometheus created configmap/grafana-dashboard-proxy created configmap/grafana-dashboard-scheduler created configmap/grafana-dashboard-statefulset created configmap/grafana-dashboard-workload-total created configmap/grafana-dashboards created deployment.apps/grafana created service/grafana created serviceaccount/grafana created servicemonitor.monitoring.coreos.com/grafana created clusterrole.rbac.authorization.k8s.io/kube-state-metrics created clusterrolebinding.rbac.authorization.k8s.io/kube-state-metrics created deployment.apps/kube-state-metrics created role.rbac.authorization.k8s.io/kube-state-metrics created rolebinding.rbac.authorization.k8s.io/kube-state-metrics created service/kube-state-metrics created serviceaccount/kube-state-metrics created servicemonitor.monitoring.coreos.com/kube-state-metrics created clusterrole.rbac.authorization.k8s.io/node-exporter created clusterrolebinding.rbac.authorization.k8s.io/node-exporter created daemonset.apps/node-exporter created service/node-exporter created serviceaccount/node-exporter created servicemonitor.monitoring.coreos.com/node-exporter created apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created clusterrole.rbac.authorization.k8s.io/prometheus-adapter created clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created clusterrolebinding.rbac.authorization.k8s.io/prometheus-adapter created clusterrolebinding.rbac.authorization.k8s.io/resource-metrics:system:auth-delegator created clusterrole.rbac.authorization.k8s.io/resource-metrics-server-resources created configmap/adapter-config created deployment.apps/prometheus-adapter created rolebinding.rbac.authorization.k8s.io/resource-metrics-auth-reader created service/prometheus-adapter created serviceaccount/prometheus-adapter created clusterrole.rbac.authorization.k8s.io/prometheus-k8s created clusterrolebinding.rbac.authorization.k8s.io/prometheus-k8s created servicemonitor.monitoring.coreos.com/prometheus-operator created prometheus.monitoring.coreos.com/k8s created rolebinding.rbac.authorization.k8s.io/prometheus-k8s-config created rolebinding.rbac.authorization.k8s.io/prometheus-k8s created rolebinding.rbac.authorization.k8s.io/prometheus-k8s created rolebinding.rbac.authorization.k8s.io/prometheus-k8s created role.rbac.authorization.k8s.io/prometheus-k8s-config created role.rbac.authorization.k8s.io/prometheus-k8s created role.rbac.authorization.k8s.io/prometheus-k8s created role.rbac.authorization.k8s.io/prometheus-k8s created prometheusrule.monitoring.coreos.com/prometheus-k8s-rules created service/prometheus-k8s created serviceaccount/prometheus-k8s created servicemonitor.monitoring.coreos.com/prometheus created servicemonitor.monitoring.coreos.com/kube-apiserver created servicemonitor.monitoring.coreos.com/coredns created servicemonitor.monitoring.coreos.com/kube-controller-manager created servicemonitor.monitoring.coreos.com/kube-scheduler created servicemonitor.monitoring.coreos.com/kubelet created
三、等待部署完成
kubectl get pod -n monitoring
NAME READY STATUS RESTARTS AGE alertmanager-main-0 2/2 Running 0 65m alertmanager-main-1 2/2 Running 0 65m alertmanager-main-2 2/2 Running 0 65m grafana-7c54b4677d-btwfb 1/1 Running 0 65m kube-state-metrics-58b656b699-p8m29 3/3 Running 0 65m node-exporter-rc5mx 2/2 Running 0 65m node-exporter-vdzkb 2/2 Running 0 65m node-exporter-xzdw2 2/2 Running 0 65m prometheus-adapter-7d6f96974c-76m4z 1/1 Running 0 65m prometheus-k8s-0 3/3 Running 1 65m prometheus-k8s-1 3/3 Running 1 65m prometheus-operator-5bd99d6457-89n7h 1/1 Running 0 66m
四、更改訪問模式(ClusterIP => NodePort)
1)Prometheus
kubectl edit svc/prometheus-k8s -n monitoring
2)Alert Manager
kubectl edit svc/alertmanager-main -n monitoring
3)Grafana
kubectl edit svc/grafana -n monitoring
五、訪問MasterIP:Port,其中Grafana默認用戶名和密碼都是admin
>>> 普羅米修斯功能強大,目前我也尚未徹底掌握,具體應用還須要你們本身深度學習。
做者:Leozhanggg
出處:https://www.cnblogs.com/leozhanggg/p/12661566.html
本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出原文鏈接,不然保留追究法律責任的權利。