Prometheus -1-2

4?安裝和配置可視化?UI?界面?Grafana

安裝?Grafana?需要的鏡像. ? heapster-grafana-amd64_v5_0_4.tar.gz?

cat grafana.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

? name: monitoring-grafana

? namespace: kube-system

spec:

? replicas: 1

? selector:

? ? matchLabels:

? ? ? task: monitoring

? ? ? k8s-app: grafana

? template:

? ? metadata:

? ? ? labels:

? ? ? ? task: monitoring

? ? ? ? k8s-app: grafana

? ? spec:

? ? ? containers:

? ? ? - name: grafana

? ? ? ? image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4

? ? ? ? ports:

? ? ? ? - containerPort: 3000

? ? ? ? ? protocol: TCP

? ? ? ? volumeMounts:

? ? ? ? - mountPath: /etc/ssl/certs

? ? ? ? ? name: ca-certificates

? ? ? ? ? readOnly: true

? ? ? ? - mountPath: /var

? ? ? ? ? name: grafana-storage

? ? ? ? env:

? ? ? ? - name: INFLUXDB_HOST

? ? ? ? ? value: monitoring-influxdb

? ? ? ? - name: GF_SERVER_HTTP_PORT

? ? ? ? ? value: "3000"

? ? ? ? ? # The following env variables are required to make Grafana accessible via

? ? ? ? ? # the kubernetes api-server proxy. On production clusters, we recommend

? ? ? ? ? # removing these env variables, setup auth for grafana, and expose the grafana

? ? ? ? ? # service using a LoadBalancer or a public IP.

? ? ? ? - name: GF_AUTH_BASIC_ENABLED

? ? ? ? ? value: "false"

? ? ? ? - name: GF_AUTH_ANONYMOUS_ENABLED

? ? ? ? ? value: "true"

? ? ? ? - name: GF_AUTH_ANONYMOUS_ORG_ROLE

? ? ? ? ? value: Admin

? ? ? ? - name: GF_SERVER_ROOT_URL

? ? ? ? ? # If you're only using the API Server proxy, set this value instead:

? ? ? ? ? # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

? ? ? ? ? value: /

? ? ? volumes:

? ? ? - name: ca-certificates

? ? ? ? hostPath:

? ? ? ? ? path: /etc/ssl/certs

? ? ? - name: grafana-storage

? ? ? ? emptyDir: {}

---

apiVersion: v1

kind: Service

metadata:

? labels:

? ? # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)

? ? # If you are NOT using this as an addon, you should comment out this line.

? ? kubernetes.io/cluster-service: 'true'

? ? kubernetes.io/name: monitoring-grafana

? name: monitoring-grafana

? namespace: kube-system

spec:

? # In a production setup, we recommend accessing Grafana through an external Loadbalancer

? # or through a public IP.

? # type: LoadBalancer

? # You could also use NodePort to expose the service at a randomly-generated port

? # type: NodePort

? ports:

? - port: 80

? ? targetPort: 3000

? selector:

? ? k8s-app: grafana

? type: NodePort

kubectl get pods -n kube-system| grep monitor

monitoring-grafana-675798bf47-9l8f8? ? ? ? 1/1? ? Running? 0? ? ? ? ? 9s

#查看?grafana?前端的?service

kubectl get svc -n kube-system | grep grafana

monitoring-grafana NodePort 10.97.239.168 <none> 80:31308/TCP 21h

#登陸?grafana,在瀏覽器訪問

192.168.172.164:31308

#配置?grafana?界面

開始配置?grafana?的?web?界面: 選擇?Create your first data source

Name: Prometheus

Type: Prometheus

HTTP?

處的?URL?如下:?http://prometheus.monitor-sa.svc:9090?配置好的整體頁面如下:

點擊左下角?Save & Test,出現(xiàn)如下?Data source is working,說明?prometheus?數(shù)據(jù)源成功的 被?grafana?接入了:

導(dǎo)入監(jiān)控模板,可在如下鏈接搜索?https://grafana.com/dashboards?dataSource=prometheus&search=kubernetes

可直接導(dǎo)入?node_exporter.json?監(jiān)控模板,這個可以把?node?節(jié)點指標(biāo)顯示出來

也可直接導(dǎo)入?docker_rev1.json,這個可以把容器資源指標(biāo)顯示 出來,node_exporter.json?和?docker_rev1.json?

怎么導(dǎo)入監(jiān)控模板,按如下步驟

上面 Save & Test?測試沒問題之后,就可以返回?Grafana?主頁面

點擊左側(cè)+號下面的?Import

選擇?Upload json file,上傳prometheus-cfg.yaml

選擇一個本地的?json?文件,我們選擇的是上面讓大家下載的?node_exporter.json?這個文件,選擇 之后出現(xiàn)如下:

注:箭頭標(biāo)注的地方?Name?后面的名字是?node_exporter.json?定義的

Prometheus?后面需要變成?Prometheus,然后再點擊?Import,就可以出現(xiàn)如下界面:

導(dǎo)入?docker_rev1.json?監(jiān)控模板,步驟和上面導(dǎo)入?node_exporter.json?步驟一樣,導(dǎo)入之后顯示 如下:

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容