feat: add dashboard intergration guideline

This commit is contained in:
icecheng 2025-09-22 17:42:50 +08:00
parent 27468f2324
commit e474d5dff8
8 changed files with 44 additions and 29 deletions

BIN
docs/asserts/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

BIN
docs/asserts/image1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

BIN
docs/asserts/image2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

BIN
docs/asserts/image3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

View File

@ -1,15 +1,16 @@
# 1. 服务提供Metrics接口 # 1. Service Provides Metrics Interface
在`webapi/providers`目录下创建一个`metrics.py`文件用于提供Metrics接口。 Create a `metrics.py` file in the `webapi/providers` directory to provide the Metrics interface.
内容如下 Content as follows:
``` ```
# Prometheus metric prefix is : freeleaps_metrics
def register(app): def register(app):
instrumentator = ( instrumentator = (
Instrumentator().instrument( Instrumentator().instrument(
app, app,
metric_namespace="freeleaps-mertics", metric_namespace="freeleaps",
metric_subsystem=app_settings.APP_NAME) metric_subsystem="metrics",)
) )
@app.on_event("startup") @app.on_event("startup")
@ -18,32 +19,32 @@ def register(app):
logging.info("Metrics endpoint exposed at /api/_/metrics") logging.info("Metrics endpoint exposed at /api/_/metrics")
``` ```
参考https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-service-hub/src/branch/master/apps/metrics的接入方式 Reference the integration approach at https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-service-hub/src/branch/master/apps/metrics
# 2. 配置Metrics采集 # 2. Configure Metrics Collection
## 2.1. 找到helm pkg目录 ## 2.1. Find the helm pkg directory
对于freeleaps内部服务而言,你需要在freeleaps-ops仓库下找到该服务部署的helm-package配置 For freeleaps internal services, you need to find the helm-package configuration for the service deployment in the freeleaps-ops repository
> 比如metrics服务他的配置在`https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/metrics` > For example, the metrics service configuration is at `https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/metrics`
对于freeleaps租户服务而言(通过one-click部署),你需要在对应服务仓库下找到`.freeleas/devops/helm-pkg` For freeleaps tenant services (deployed via one-click), you need to find `.freeleaps/devops/helm-pkg` in the corresponding service repository
> 比如magicleaps服务他的配置在`https://gitea.freeleaps.mathmast.com/products/magicleaps/src/branch/main/.freeleaps/devops/helm-pkg` > For example, the magicleaps service configuration is at `https://gitea.freeleaps.mathmast.com/products/magicleaps/src/branch/main/.freeleaps/devops/helm-pkg`
## 2.2. 新增新增servicemonitor配置 ## 2.2. Add servicemonitor configuration
在templates文件夹下新增`servicemonitor.yaml`文件,内容如下,内容参考`https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/templates/notification/servicemonitor.yaml` Add a `servicemonitor.yaml` file in the templates folder with the following content, referencing `https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/templates/notification/servicemonitor.yaml`
根据value.yaml中的配置更新必要内容比如第6行从notification修改为metrics Update necessary content based on the configuration in value.yaml, for example, change line 6 from notification to metrics
## 2.3. 修改value.{alpha|prod}.yaml ## 2.3. Modify value.{alpha|prod}.yaml
新增serviceMonitor配置参考`https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/values.prod.yaml` Add serviceMonitor configuration, referencing `https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/values.prod.yaml`
``` ```
- name: notification-service - name: notification-service
type: ClusterIP type: ClusterIP
port: 8003 port: 8003
targetPort: 8003 targetPort: 8003
serviceMonitor: serviceMonitor:
enabled: true # alpha环境设置为false enabled: true # Set to false for alpha environment
labels: labels:
release: kube-prometheus-stack release: kube-prometheus-stack
namespace: freeleaps-monitoring-system namespace: freeleaps-monitoring-system
@ -51,22 +52,36 @@ def register(app):
scrapeTimeout: '' scrapeTimeout: ''
``` ```
# 3. 配置Grafanana Dashboard ## 2.4. Verify Metrics Collection Results
## 2.1. 在helm-pkg下新增`dashboard.yaml` Forward the service [kube-prometheus-stack-prometheus] to local port through LENS, access `http://localhost:9090/targets` to check if the corresponding Endpoint can be found
![alt text](asserts/image.png)
Access `http://localhost:9090/query` to check if the corresponding metrics can be found
![alt text](asserts/image2.png)
内容参考`https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/templates/notification/dashboard.yaml` # 3. Configure Grafana Dashboard
# 3. Configure Grafana Dashboard
## 3.1. Add `dashboard.yaml` under helm-pkg
Content reference `https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops/src/branch/master/freeleaps/helm-pkg/notification/templates/notification/dashboard.yaml`
## 2.2. 修改value.{alpha|prod}.yaml ## 3.2. Modify value.{alpha|prod}.yaml
```yaml ```yaml
dashboard: dashboard:
enabled: true # alphah环境设置为false enabled: true # Set to false for alpha environment
name: freeleaps-prod-metrics-dashboard name: freeleaps-prod-metrics-dashboard
title: Freeleaps Metrics Dashboard (PROD/ALPHA) title: Freeleaps Metrics Dashboard (PROD/ALPHA)
metricsPrefix: freeleaps_metrics metricsPrefix: freeleaps_metrics
``` ```
## 3.3. Verify Dashboard Addition
Login to `https://grafana.mathmast.com` to check if the dashboard was added successfully
![alt text](asserts/image1.png)
![alt text](asserts/image3.png)

View File

@ -5,8 +5,8 @@ global:
logIngest: logIngest:
enabled: false enabled: false
dashboard: dashboard:
enabled: true enabled: false
name: freeleaps-prod-metrics-dashboard name: freeleaps-alpha-metrics-dashboard
title: Freeleaps Metrics Dashboard (ALPHA) title: Freeleaps Metrics Dashboard (ALPHA)
metricsPrefix: freeleaps_metrics metricsPrefix: freeleaps_metrics
metrics: metrics:
@ -56,7 +56,7 @@ metrics:
port: 8009 port: 8009
targetPort: 8009 targetPort: 8009
serviceMonitor: serviceMonitor:
enabled: true enabled: false
labels: labels:
release: kube-prometheus-stack release: kube-prometheus-stack
namespace: freeleaps-monitoring-system namespace: freeleaps-monitoring-system

View File

@ -5,7 +5,7 @@ global:
logIngest: logIngest:
enabled: false enabled: false
dashboard: dashboard:
enabled: false enabled: true
name: freeleaps-prod-metrics-dashboard name: freeleaps-prod-metrics-dashboard
title: Freeleaps Metrics Dashboard (PROD) title: Freeleaps Metrics Dashboard (PROD)
metricsPrefix: freeleaps_metrics metricsPrefix: freeleaps_metrics
@ -56,7 +56,7 @@ metrics:
port: 8009 port: 8009
targetPort: 8009 targetPort: 8009
serviceMonitor: serviceMonitor:
enabled: false enabled: true
labels: labels:
release: kube-prometheus-stack release: kube-prometheus-stack
namespace: freeleaps-monitoring-system namespace: freeleaps-monitoring-system

View File

@ -6,7 +6,7 @@ logIngest:
enabled: false enabled: false
dashboard: dashboard:
enabled: false enabled: false
name: freeleaps-prod-metrics-dashboard name: freeleaps-metrics-dashboard
title: Freeleaps Metrics Dashboard title: Freeleaps Metrics Dashboard
metrics: metrics:
replicas: 1 replicas: 1