@cloudbase/manager-node 5.5.5 → 5.5.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ const cloudApp_1 = require("./cloudApp");
22
22
  const permission_1 = require("./permission");
23
23
  const sandbox_1 = require("./sandbox");
24
24
  const aiModel_1 = require("./aiModel");
25
+ const monitor_1 = require("./monitor");
25
26
  class Environment {
26
27
  constructor(context, envId) {
27
28
  this.inited = false;
@@ -47,6 +48,7 @@ class Environment {
47
48
  this.cloudAppService = new cloudApp_1.CloudAppService(this);
48
49
  this.sandboxService = new sandbox_1.SandboxService(this);
49
50
  this.aiModelService = new aiModel_1.AiModelService(this);
51
+ this.monitorService = new monitor_1.MonitorService(this);
50
52
  }
51
53
  async lazyInit() {
52
54
  if (!this.inited) {
@@ -121,6 +123,9 @@ class Environment {
121
123
  getAiModelService() {
122
124
  return this.aiModelService;
123
125
  }
126
+ getMonitorService() {
127
+ return this.monitorService;
128
+ }
124
129
  getCommonService(serviceType = 'tcb', serviceVersion) {
125
130
  return new common_1.CommonService(this, serviceType, serviceVersion);
126
131
  }
package/lib/index.js CHANGED
@@ -122,6 +122,9 @@ class CloudBase {
122
122
  get aiModel() {
123
123
  return this.currentEnvironment().getAiModelService();
124
124
  }
125
+ get monitor() {
126
+ return this.currentEnvironment().getMonitorService();
127
+ }
125
128
  get docs() {
126
129
  if (!this.docsService) {
127
130
  this.docsService = new docs_1.DocsService();
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.MonitorService = void 0;
18
+ const error_1 = require("../error");
19
+ const utils_1 = require("../utils");
20
+ __exportStar(require("./types"), exports);
21
+ // Period 与时间范围的约束规则
22
+ const ONE_DAY_MS = 24 * 60 * 60 * 1000;
23
+ const THREE_DAYS_MS = 3 * ONE_DAY_MS;
24
+ const PERIOD_RULES = [
25
+ { maxRangeMs: ONE_DAY_MS, allowed: [300, 3600] },
26
+ { maxRangeMs: THREE_DAYS_MS, allowed: [300, 3600, 86400] },
27
+ // 超过3天
28
+ { maxRangeMs: Infinity, allowed: [3600, 86400] }
29
+ ];
30
+ function validatePeriod(startStr, endStr, period) {
31
+ if (period === undefined)
32
+ return;
33
+ const startMs = new Date(startStr).getTime();
34
+ const endMs = new Date(endStr).getTime();
35
+ if (isNaN(startMs) || isNaN(endMs))
36
+ return;
37
+ const rangeMs = endMs - startMs;
38
+ const rule = PERIOD_RULES.find(r => rangeMs <= r.maxRangeMs);
39
+ if (rule && !rule.allowed.includes(period)) {
40
+ throw new error_1.CloudBaseError(`Period=${period} 不适用于当前时间范围。` +
41
+ `时间范围 ${startStr} ~ ${endStr}(约 ${(rangeMs / ONE_DAY_MS).toFixed(1)} 天)` +
42
+ `仅支持 Period: [${rule.allowed.join(', ')}]`);
43
+ }
44
+ }
45
+ class MonitorService {
46
+ constructor(environment) {
47
+ this.envId = environment.getEnvId();
48
+ this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
49
+ }
50
+ /**
51
+ * 查询环境监控数据
52
+ *
53
+ * 根据指定指标名称,查询当前环境在指定时间范围内的监控数据,
54
+ * 返回按统计粒度聚合后的时序数据。
55
+ *
56
+ * @param params 查询参数
57
+ * @returns 时序监控数据
58
+ *
59
+ * @example
60
+ * // 查询静态网站存储容量
61
+ * const res = await monitor.describeCurveData({
62
+ * MetricName: 'StaticFsSizePkg',
63
+ * StartTime: '2026-02-05 00:00:00',
64
+ * EndTime: '2026-02-06 23:59:59',
65
+ * Period: 3600
66
+ * })
67
+ *
68
+ * @example
69
+ * // 查询云托管某服务某版本的错误响应
70
+ * const res = await monitor.describeCurveData({
71
+ * MetricName: 'TkeHttpErrorService',
72
+ * StartTime: '2026-03-13 00:00:00',
73
+ * EndTime: '2026-03-16 23:59:59',
74
+ * ResourceID: 'my-service',
75
+ * SubresourceID: 'my-service-001'
76
+ * })
77
+ */
78
+ async describeCurveData(params) {
79
+ // 校验 Period 与时间范围的约束关系
80
+ validatePeriod(params.StartTime, params.EndTime, params.Period);
81
+ const requestParams = {
82
+ EnvId: this.envId,
83
+ MetricName: params.MetricName,
84
+ StartTime: params.StartTime,
85
+ EndTime: params.EndTime
86
+ };
87
+ if (params.ResourceID !== undefined) {
88
+ requestParams.ResourceID = params.ResourceID;
89
+ }
90
+ if (params.WxAppId !== undefined) {
91
+ requestParams.WxAppId = params.WxAppId;
92
+ }
93
+ if (params.SubresourceID !== undefined) {
94
+ requestParams.SubresourceID = params.SubresourceID;
95
+ }
96
+ if (params.ThirdResource !== undefined) {
97
+ requestParams.ThirdResource = params.ThirdResource;
98
+ }
99
+ if (params.Period !== undefined) {
100
+ requestParams.Period = params.Period;
101
+ }
102
+ return this.cloudService.request('DescribeCurveData', requestParams);
103
+ }
104
+ }
105
+ exports.MonitorService = MonitorService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "5.5.5",
3
+ "version": "5.5.6-beta.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@ import { EnvInfo } from './interfaces';
18
18
  import { PermissionService } from './permission';
19
19
  import { SandboxService } from './sandbox';
20
20
  import { AiModelService } from './aiModel';
21
+ import { MonitorService } from './monitor';
21
22
  export declare class Environment {
22
23
  inited: boolean;
23
24
  cloudBaseContext: CloudBaseContext;
@@ -41,6 +42,7 @@ export declare class Environment {
41
42
  private cloudAppService;
42
43
  private sandboxService;
43
44
  private aiModelService;
45
+ private monitorService;
44
46
  constructor(context: CloudBaseContext, envId: string);
45
47
  lazyInit(): Promise<any>;
46
48
  getEnvId(): string;
@@ -62,6 +64,7 @@ export declare class Environment {
62
64
  getPermissionService(): PermissionService;
63
65
  getSandboxService(): SandboxService;
64
66
  getAiModelService(): AiModelService;
67
+ getMonitorService(): MonitorService;
65
68
  getCommonService(serviceType: string, serviceVersion: any): CommonService;
66
69
  getServicesEnvInfo(): Promise<any>;
67
70
  getAuthConfig(): {
package/types/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import { PermissionService } from './permission';
19
19
  import { SandboxService } from './sandbox';
20
20
  import { CloudAppService } from './cloudApp';
21
21
  import { AiModelService } from './aiModel';
22
+ import { MonitorService } from './monitor';
22
23
  interface CloudBaseConfig {
23
24
  secretId?: string;
24
25
  secretKey?: string;
@@ -84,6 +85,7 @@ declare class CloudBase {
84
85
  get permission(): PermissionService;
85
86
  get sandbox(): SandboxService;
86
87
  get aiModel(): AiModelService;
88
+ get monitor(): MonitorService;
87
89
  get docs(): DocsService;
88
90
  getEnvironmentManager(): EnvironmentManager;
89
91
  getManagerConfig(): CloudBaseConfig;
@@ -0,0 +1,37 @@
1
+ import { Environment } from '../environment';
2
+ import { IDescribeCurveDataParams, IDescribeCurveDataResponse } from './types';
3
+ export * from './types';
4
+ export declare class MonitorService {
5
+ private envId;
6
+ private cloudService;
7
+ constructor(environment: Environment);
8
+ /**
9
+ * 查询环境监控数据
10
+ *
11
+ * 根据指定指标名称,查询当前环境在指定时间范围内的监控数据,
12
+ * 返回按统计粒度聚合后的时序数据。
13
+ *
14
+ * @param params 查询参数
15
+ * @returns 时序监控数据
16
+ *
17
+ * @example
18
+ * // 查询静态网站存储容量
19
+ * const res = await monitor.describeCurveData({
20
+ * MetricName: 'StaticFsSizePkg',
21
+ * StartTime: '2026-02-05 00:00:00',
22
+ * EndTime: '2026-02-06 23:59:59',
23
+ * Period: 3600
24
+ * })
25
+ *
26
+ * @example
27
+ * // 查询云托管某服务某版本的错误响应
28
+ * const res = await monitor.describeCurveData({
29
+ * MetricName: 'TkeHttpErrorService',
30
+ * StartTime: '2026-03-13 00:00:00',
31
+ * EndTime: '2026-03-16 23:59:59',
32
+ * ResourceID: 'my-service',
33
+ * SubresourceID: 'my-service-001'
34
+ * })
35
+ */
36
+ describeCurveData(params: IDescribeCurveDataParams): Promise<IDescribeCurveDataResponse>;
37
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * 监控指标名称
3
+ *
4
+ * 文档型数据库 / SQL型数据库 / 云函数 / 云托管 / 静态网站 / 身份认证 / API调用 / HTTP网关 / 大模型 / 知识库 / 用户登录 / 环境QPS / 数据库连接器 / 网关
5
+ */
6
+ export type MetricName = 'DbRead' | 'DbWrite' | 'DbCostTime10ms' | 'DbCostTime50ms' | 'DbCostTime100ms' | 'DbSizepkg' | 'MysqlStorageUsage' | 'MysqlCCU' | 'MysqlCpuUsageRate' | 'MysqlDbConnections' | 'MysqlMemoryUse' | 'MysqlSlowQueries' | 'MysqlTps' | 'MysqlQps' | 'FunctionCU' | 'FunctionInvocation' | 'FunctionFlux' | 'FunctionThrottle' | 'FunctionConcurrentExecutions' | 'FunctionTimeout' | 'FunctionGBs' | 'FunctionError' | 'FunctionDuration' | 'FunctionConcurrencyMemoryMB' | 'FunctionMemOverFlow' | 'FunctionIdleProvisioned' | 'FunctionProvisionedConcurrency' | 'TkeRspTimeService' | 'TkeCpuUsedService' | 'TkeMemUsedService' | 'TkeQPSService' | 'TkePodNumService' | 'TkeHttpServiceNatPkg' | 'TkeCUUsedService' | 'TkeInvokeNumService' | 'TkeHttpErrorService' | 'StaticFsFluxPkg' | 'StaticFsSizePkg' | 'AuthInvocationNumPkg' | 'GwCloudDevelopmentSecureCallsInvocation' | 'GwWXInvocation' | 'GwCloudDevelopmentStandardCallsInvocation' | 'AIPromptTokenNumPkg' | 'AICompletionTokenNumPkg' | 'AITotalTokenNumPkg' | 'KnowledgeBaseCapacity' | 'DayActiveLoginAnonymousUser' | 'DayActiveLoginAllUser' | 'DayActiveLoginExternalUser' | 'DayActiveLoginInternalUser' | 'EnvQPSAll' | 'MongoConnectorRead' | 'MongoConnectorWrite' | 'MongoConnectorCostTime10ms' | 'MongoConnectorCostTime50ms' | 'MongoConnectorCostTime100ms' | 'MongoConnectorInvokeNum' | 'GatewayTraceEnvQPS' | 'GatewayShowAPIInvokeNum' | 'GatewayShowAPICostTotal' | 'GatewayShowAPIHTTP2XX' | 'GatewayShowAPIHTTPError' | 'GatewayTraceAccessSourceQPS' | 'GatewayShowHttpInvokeNum' | 'GatewayShowHttpCostTotal' | 'GatewayShowHttpHTTP2XX' | 'GatewayShowHttpHTTPError' | 'GatewayTraceResourceQPS' | (string & {});
7
+ /** 统计周期(秒) */
8
+ export type MetricPeriod = 300 | 3600 | 86400;
9
+ /** DescribeCurveData 请求参数 */
10
+ export interface IDescribeCurveDataParams {
11
+ /** 指标名称 */
12
+ MetricName: MetricName;
13
+ /** 开始时间,格式 'YYYY-MM-DD HH:mm:ss',需早于结束时间至少5分钟 */
14
+ StartTime: string;
15
+ /** 结束时间,格式 'YYYY-MM-DD HH:mm:ss',需晚于开始时间至少5分钟 */
16
+ EndTime: string;
17
+ /**
18
+ * 资源ID(可选)
19
+ * - 文档型数据库:集合名称
20
+ * - 云函数:函数名称
21
+ * - 云托管:服务名称(必传)
22
+ * - 数据库连接器:实例id(必传)
23
+ * - 网关-调用链路维度:小程序API传'wx',云开发API传'http_openapi'(必传)
24
+ * - 网关-环境/资源维度:必传
25
+ * - 留空则查询整个 namespace 的指标
26
+ */
27
+ ResourceID?: string;
28
+ /** 微信AppId,微信场景必传 */
29
+ WxAppId?: string;
30
+ /** 子资源信息,查询云托管相关指标的具体版本的监控数据,需传入 */
31
+ SubresourceID?: string;
32
+ /** 网关路由 */
33
+ ThirdResource?: string;
34
+ /**
35
+ * 统计周期(秒),仅支持 300 / 3600 / 86400
36
+ * 不传则根据时间范围自动选择:
37
+ * - 1天内:300
38
+ * - 1天~15天:3600
39
+ * - 15天~180天:86400
40
+ *
41
+ * 传入时需遵循以下约束:
42
+ * - 时间范围 ≤ 1天:可取 300 或 3600
43
+ * - 时间范围 > 1天且 ≤ 3天:可取 300、3600 或 86400
44
+ * - 时间范围 > 3天:可取 3600 或 86400
45
+ */
46
+ Period?: MetricPeriod;
47
+ }
48
+ /** DescribeCurveData 响应结果 */
49
+ export interface IDescribeCurveDataResponse {
50
+ /** 开始时间(会根据统计周期取整) */
51
+ StartTime: string;
52
+ /** 结束时间(会根据统计周期取整) */
53
+ EndTime: string;
54
+ /** 指标名 */
55
+ MetricName: string;
56
+ /** 统计周期(秒) */
57
+ Period: number;
58
+ /** 监控数据(整数),与 Time 一一对应 */
59
+ Values: number[];
60
+ /** 时间戳数组(Unix 时间戳,秒级),与 Values 一一对应 */
61
+ Time: number[];
62
+ /** 监控数据(浮点数),与 Time 一一对应 */
63
+ NewValues: number[];
64
+ /** 聚合方式:'last' | 'max' | 'avg' | 'sum' */
65
+ Statistics: string;
66
+ /** 请求ID */
67
+ RequestId: string;
68
+ }