基于Prometheus的全方位监控平台--企业监控大盘Grafana一、Grafana简述二、部署Grafana到Kubernetes2.1、数据持久化2.2、配置grafana-config2.3、配置grafana-SVC2.4、部署grafana-DP2.5、部署grafana-ING2.6、Grafana安装插件2.7、验证测试Grafana三、配置数据源四、企业级监控大盘4.1、集群层面监控4.2、域名层面4.3、主机层面
Grafana 是一个开源的度量分析与可视化工具。提供查询、可视化、报警和指标展示等功能,能灵活创建图表、仪表盘等可视化界面。
主要功能:
xxxxxxxxxx
apiVersion v1
kind PersistentVolumeClaim
metadata
name grafana-data-pvc
namespace monitor
spec
accessModes
ReadWriteMany
storageClassName"nfs-storage"
resources
requests
storage 10Gi
xxxxxxxxxx
apiVersion v1
kind ConfigMap
metadata
name grafana-config
namespace monitor
data
grafana.ini
[server]
root_url = http://grafana.kubernets.cn
[smtp]
enabled = true
host = smtp.exmail.qq.com:465
user = devops@xxxx.com
password = aDhUcxxxxyecE
skip_verify = true
from_address = devops@xxxx.com
[alerting]
enabled = true
execute_alerts = true
xxxxxxxxxx
apiVersion v1
kind Service
metadata
name grafana
namespace monitor
labels
app grafana
component core
spec
type ClusterIP
ports
port3000
selector
app grafana
component core
xxxxxxxxxx
apiVersion apps/v1
kind Deployment
metadata
name grafana-core
namespace monitor
labels
app grafana
component core
spec
replicas1
selector
matchLabels
app grafana
template
metadata
labels
app grafana
component core
spec
containers
name grafana-core
image grafana/grafana latest
imagePullPolicy IfNotPresent
volumeMounts
name storage
subPath grafana
mountPath /var/lib/grafana
# env:
resources
# keep request = limit to keep this container in guaranteed class
limits
cpu 500m
memory 1Gi
requests
cpu 100m
memory 500Mi
env#配置环境变量,设置Grafana 的默认管理员用户名/密码
# The following env variables set up basic auth twith the default admin user and admin password.
name GF_AUTH_BASIC_ENABLED
value"true"
name GF_AUTH_ANONYMOUS_ENABLED
value"false"
# - name: GF_AUTH_ANONYMOUS_ORG_ROLE
# value: Admin
# does not really work, because of template variables in exported dashboards:
# - name: GF_DASHBOARDS_JSON_ENABLED
# value: "true"
readinessProbe
httpGet
path /login
port3000
# initialDelaySeconds: 30
# timeoutSeconds: 1
volumeMounts
name data
subPath grafana
mountPath /var/lib/grafana
name grafana-config
mountPath /etc/grafana
readOnlytrue
securityContext#容器安全策略,设置运行容器使用的归属组与用户
fsGroup472
runAsUser472
volumes
name data
persistentVolumeClaim
claimName grafana-data-pvc
name grafana-config
configMap
name grafana-config
xxxxxxxxxx
apiVersion networking.k8s.io/v1
kind Ingress
metadata
name grafana-ingress
namespace monitor
annotations
prometheus.io/http_probe"true"
spec
ingressClassName nginx
rules
host grafana.kubernets.cn
http
paths
pathType Prefix
backend
service
name grafana
port
number3000
path /
进入 Grafana Pod 容器内,通过镜像自带的 grafana-cli 工具进行插件的安装,本文以安装饼图插件为例
xxxxxxxxxx
# kubectl exec -it -n monitor grafana-58ffb4db5d-c4wlz bash
bash-5.0$ grafana-cli plugins install grafana-piechart-panel
bash-5.0$ grafana-cli plugins install camptocamp-prometheus-alertmanager-datasource
插件已经安装成功,不过在默认情况下 Grafana 并不会自动热加载插件,必须将应用重启后才能够重新加载插件。
xxxxxxxxxx
$ curl grafana.kubernets.cn
<a href="/login">Found</a>.
Grafana官方提供了对:Graphite, InfluxDB, OpenTSDB, Prometheus, Elasticsearch, CloudWatch的支持。
添加数据源:Configuration --> Data Sources --> Prometheus
HTTP URL:http://prometheus.monitor:9090 Save & test
创建不同维度的大盘:Create --> New dashboard folder --> 集群层面
官方大盘指引:Dashboards | Grafana Labs
监控指标说明:监控指标说明 | KubeSphere Documents
导入大盘:Create --> Import
集群:
Kubernetes / Views / Global :15757
Kubernetes / Views / Nodes :15759
Kubernetes / Views / Namespaces :15758
Kubernetes / Views / Pods :15760
Kubernetes Deployment Statefulset Daemonset metrics :8588
域名:9965
主机:16098/8919