Manifest实时分析:监控应用使用情况
【免费下载链接】manifest Effortless backends ✨ 项目地址: https://gitcode.com/GitHub_Trending/manifest7/manifest
你是否在开发应用时遇到过用户行为难以追踪、系统性能瓶颈无法定位的问题?Manifest提供了一套完整的实时分析解决方案,帮助开发者轻松监控应用使用情况。本文将详细介绍如何利用Manifest的内置工具实现应用监控,从数据采集到可视化展示的全流程。
监控系统架构概述
Manifest的监控系统基于其核心的实体模型和API接口构建,主要包含数据采集、处理和展示三个层级。系统架构如图所示:
核心实现位于packages/core/manifest/src/manifest/services/manifest/manifest.service.ts,该服务负责加载和转换应用清单,为监控提供基础数据模型。
数据采集:追踪实体操作
Manifest通过记录实体(Entity)的CRUD操作实现用户行为追踪。每个实体的操作都会生成相应的日志,这些日志包含操作类型、时间戳、用户信息等关键数据。
实体模型定义
实体模型定义在应用清单(Manifest)中,如packages/core/manifest/src/manifest/json-schema/schema.json所示:
{
"title": "App Manifest Schema",
"description": "A complete backend in a single file.",
"type": "object",
"properties": {
"name": {
"description": "The name of your app",
"type": "string"
},
"entities": {
"description": "The entities in your app. Doc: https://manifest.build/docs/entities",
"type": "object",
"additionalProperties": {
"$ref": "./definitions/entity-schema.json"
}
}
},
"required": ["name"],
"additionalProperties": false
}
每个实体的属性和关系定义决定了系统需要采集哪些数据。例如,用户实体可能包含以下属性:
entities:
User:
properties:
- name: string
- email: string
- signupDate: date
belongsTo: []
操作日志采集
操作日志通过CRUD控制器实现,位于packages/core/manifest/src/crud/controllers/crud.controller.ts。每当执行创建、读取、更新或删除操作时,系统会自动记录相关信息。
健康检查与性能监控
Manifest内置了健康检查接口,可以实时监控系统状态。健康检查控制器packages/core/manifest/src/health/health.controller.ts提供了基础的状态检查:
import { Controller, Get } from '@nestjs/common'
@Controller('health')
export class HealthController {
@Get()
getHealth() {
return { status: 'OK' }
}
}
对于更详细的性能监控,可结合分页查询服务packages/core/manifest/src/crud/services/pagination.service.ts实现请求响应时间追踪。该服务提供了分页查询的基础实现,通过扩展可以添加性能计时功能:
async paginate({
query,
resultsPerPage,
currentPage,
transformResult,
asyncTransformResult
}: {
query?: SelectQueryBuilder<BaseEntity>
currentPage: number
resultsPerPage?: number
transformResult?: (result: BaseEntity) => BaseEntity
asyncTransformResult?: (result: BaseEntity) => Promise<BaseEntity>
}): Promise<Paginator<BaseEntity>> {
const startTime = Date.now();
// 分页查询逻辑...
const endTime = Date.now();
console.log(`Query executed in ${endTime - startTime}ms`);
// 返回结果...
}
前端可视化展示
Manifest的管理界面提供了直观的监控数据展示。前端监控模块位于packages/core/admin/src/app/modules/shared/services/manifest.service.ts,该服务从后端API获取监控数据并提供给前端组件:
getManifest(): Promise<AppManifest> {
if (!this.manifestPromise) {
this.manifestPromise = firstValueFrom(
this.http.get<AppManifest>(`${environment.apiBaseUrl}/manifest`)
);
}
return this.manifestPromise;
}
管理界面使用多种图表展示监控数据,包括实体操作统计、系统健康状态等。例如,使用以下组件展示实体操作趋势:
<ngx-charts-line-chart
[results]="entityOperationsData"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true"
xAxisLabel="时间"
yAxisLabel="操作次数">
</ngx-charts-line-chart>
自定义监控指标
除了系统默认的监控指标,Manifest还支持自定义指标采集。通过扩展实体模型,添加自定义属性来跟踪特定业务指标。例如,为产品实体添加"点击量"属性:
entities:
Product:
properties:
- name: string
- price: number
- clickCount: number
belongsTo: []
然后在相应的控制器中更新该属性:
@Get(':id/click')
async trackClick(@Param('id') id: string) {
const product = await this.productService.findOne(id);
product.clickCount++;
await this.productService.update(id, product);
return product;
}
部署与配置
要启用监控功能,只需在应用清单中添加相关配置。首先,确保已正确安装Manifest:
git clone https://gitcode.com/GitHub_Trending/manifest7/manifest
cd manifest
npm install
然后在项目根目录的manifest.yml中添加监控配置:
name: MyApp
entities:
# 实体定义...
monitoring:
enabled: true
samplingRate: 1.0
retentionDays: 30
启动应用后,监控系统会自动运行,数据存储在examples/standalone/manifest/backend.db中。
总结与进阶
通过本文介绍的方法,你已经掌握了Manifest实时分析系统的基本使用。要进一步提升监控能力,可以考虑:
- 集成第三方监控工具,如Prometheus和Grafana
- 实现用户行为漏斗分析
- 开发自定义告警规则
Manifest的监控系统设计灵活,可根据项目需求进行扩展。更多高级用法请参考官方文档README.md和示例项目examples/standalone/。
监控界面截图:
通过Manifest的实时分析功能,开发者可以深入了解应用使用情况,及时发现并解决问题,为用户提供更优质的体验。立即尝试,开启你的应用监控之旅吧!
【免费下载链接】manifest Effortless backends ✨ 项目地址: https://gitcode.com/GitHub_Trending/manifest7/manifest
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



