Grafana 是 Graphite 和 InfluxDB 仪表盘和图形编辑器。
Grafana 是开源的,功能齐全的度量仪表盘和图形编辑器,支持 Graphite,InfluxDB 和 OpenTSDB。
Grafana 主要特性:灵活丰富的图形化选项;可以混合多种风格;支持白天和夜间模式;多个数据源;Graphite 和 InfluxDB 查询编辑器等。

部署Grafana

Prometheus采取到k8s集群的监控数据后,由于Prometheus自带的展示图形不太友好,故我们需要选择更加强大的图形展示工具。Prometheus的时区是UTC +0且不支持修改,而Grafana可以选择时区

Grafana官网:https://grafana.com/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[root@localhost Prometheus]# cat prometheus-grafana.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: grafana
namespace: kube-ops
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: grafana
task: monitoring
spec:
containers:
- name: grafana
image: yfshare/heapster-grafana-amd64:v4.4.3
ports:
- containerPort: 3000
hostPort: 3000
protocol: TCP
resources:
limits:
cpu: 200m
memory: 256Mi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: ca-certificates
mountPath: /etc/ssl/certs
readOnly: true
- name: grafana-data
mountPath: /var
subPath: grafana
env:
- name: INFLUXDB_HOST
value: influxdb
- name: INFLUXDB_SERVICE_URL
value: http://influxdb.kube-ops.svc.cluster.local:8086
- name: GF_SERVER_HTTP_PORT
value: "3000"
- 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/proxy/namespaces/kube-system/services/monitoring-grafana/
value: /
volumes:
- name: ca-certificates
hostPath:
path: /etc/ssl/certs
- name: grafana-data
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: grafana
name: grafana
namespace: kube-ops
spec:
ports:
- port: 3000
targetPort: 3000
selector:
k8s-app: grafana
[root@localhost Prometheus]#

1
[root@localhost Prometheus]# kubectl apply -f prometheus-grafana.yaml
1
2
3
4
[root@localhost ~]# kubectl get pod -n kube-ops -o wide
NAME READY STATUS RESTARTS AGE IP NODE
grafana-694786cf95-ph5pr 1/1 Running 0 1d 172.30.57.8 192.168.1.198
[root@localhost ~]#

访问Grafana Dashboard

访问 http://192.168.1.198:3000 打开Grafana WEB界面

添加数据源
Prometheus-Grafana

Add Data Source添加数据源
Prometheus-Grafana

这里是编辑 influxdb-datasource
执行kubectl get svc --all-namespaces -o wide | grep -i influxdb可以获取influxdb的cluster-ip和Port
Prometheus-Grafana

添加Grafana的Prometheus数据源
数据源Type选择Prometheus
执行kubectl get pod --all-namespaces -o wide | grep -i prometheus可以获取Prometheus的ip
Prometheus-Grafana
Prometheus-Grafana

添加Dashboard
Grafana官方有个Prometheus模板,参考:https://grafana.com/dashboards/162 ,可以把它导入到Grafana

把下载的kubernetes-pod-monitoring_rev1.json 导入到Grafana
Prometheus-Grafana

上传json文件并选择数据源
Prometheus-Grafana

导入成功。下图为模板默认监控数据,具体需要根据实际情况修改
Prometheus-Grafana


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2022/01/14/Grafana展示Prometheus数据/