Skip to content

Commit 1de492c

Browse files
committed
added monitor analytic
1 parent a8dda3b commit 1de492c

File tree

4 files changed

+215
-0
lines changed

4 files changed

+215
-0
lines changed

.changeset/great-peaches-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cloudways-js-client": patch
3+
---
4+
5+
added monitor analytics

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export * from "./services/operation";
66
export * from "./services/application";
77
export * from "./services/server";
88
export * from "./services/ssh-keys";
9+
export * from "./services/monitor-analytic";
10+
export * from "./services/knowledge-base";
911

1012
// export all the types
1113
export * from "./services/Lists/types";

src/services/knowledge-base/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { apiCall } from "../core";
2+
3+
/**
4+
* Search for queries in the Knowledge Base.
5+
* @param {string} query The string to search in the Knowledge Base.
6+
* @returns {Promise<{ articles: { guid: string, post_title: string }[], articles_found: number, status: number }>} A promise resolving with the search results.
7+
*/
8+
export function searchKnowledgeBase(query: string): Promise<{
9+
articles: { guid: string; post_title: string }[];
10+
articles_found: number;
11+
status: number;
12+
}> {
13+
const endpoint = `/kb/search?kb_title=${encodeURIComponent(query)}`;
14+
return apiCall(endpoint);
15+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import { apiCall } from "../core";
2+
import { HttpMethod } from "../core/types";
3+
4+
/**
5+
* Get server bandwidth usage or disk size per application.
6+
* @param {number} serverId Numeric id of the server.
7+
* @param {string} type Possible values are "bw" for bandwidth usage of the server or "db" for application size on disk.
8+
* @returns {Promise<{ name: string, datapoint: [number, number][], type: string }[]>} A promise resolving with the bandwidth usage or disk size per application.
9+
*/
10+
export function getServerSummary(
11+
serverId: number,
12+
type: string
13+
): Promise<{ name: string; datapoint: [number, number][]; type: string }[]> {
14+
const data = {
15+
server_id: serverId,
16+
type: type,
17+
};
18+
return apiCall("/server/monitor/summary", HttpMethod.GET, data).then(
19+
(response) => response.content
20+
);
21+
}
22+
23+
/**
24+
* Get server usage.
25+
* @param {number} serverId Numeric id of the server.
26+
* @returns {Promise<{ status: boolean, operation_id: string }>} A promise resolving with the operation id.
27+
*/
28+
export function getServerUsage(
29+
serverId: number
30+
): Promise<{ status: boolean; operation_id: string }> {
31+
const data = {
32+
server_id: serverId,
33+
};
34+
return apiCall("/server/analytics/serverUsage", HttpMethod.GET, data);
35+
}
36+
37+
/**
38+
* Get application disk usage.
39+
* @param {number} serverId Numeric id of the server.
40+
* @param {number} appId Numeric id of the app.
41+
* @param {string} type String type (summary, disk, db, etc.).
42+
* @returns {Promise<any>} A promise resolving with the application disk usage data.
43+
*/
44+
export function getApplicationDiskUsage(
45+
serverId: number,
46+
appId: number,
47+
type: string
48+
): Promise<any> {
49+
const data = {
50+
server_id: serverId,
51+
app_id: appId,
52+
type: type,
53+
};
54+
return apiCall("/app/monitor/summary", HttpMethod.GET, data);
55+
}
56+
57+
/**
58+
* Get application disk usage graph (Deprecated).
59+
* @param {number} serverId Numeric id of the server.
60+
* @param {string} appId System user of the application.
61+
* @param {string} timezone String of the server timezone.
62+
* @param {number} target String of the target (cpuiddle, memory, etc.).
63+
* @param {number} duration Integer of the duration.
64+
* @returns {Promise<any>} A promise resolving with the application disk usage graph data.
65+
*/
66+
export function getApplicationDiskUsageGraph(
67+
serverId: number,
68+
appId: string,
69+
timezone: string,
70+
target: number,
71+
duration: number
72+
): Promise<any> {
73+
const data = {
74+
server_id: serverId,
75+
app_id: appId,
76+
timezone: timezone,
77+
target: target,
78+
duration: duration,
79+
};
80+
return apiCall("/app/monitor/detail", HttpMethod.GET, data);
81+
}
82+
83+
/**
84+
* Get application traffic analytics.
85+
* @param {number} serverId Numeric id of the server.
86+
* @param {number} appId Numeric id of the app.
87+
* @param {string} duration String duration (e.g., "15m", "30m", "1h", "1d").
88+
* @param {string} resource String type ("top_ips", "top_bots", "top_urls", "top_statuses").
89+
* @returns {Promise<any>} A promise resolving with the application traffic analytics data.
90+
*/
91+
export function getApplicationTrafficAnalytics(
92+
serverId: number,
93+
appId: number,
94+
duration: string,
95+
resource: string
96+
): Promise<any> {
97+
const data = {
98+
server_id: serverId,
99+
app_id: appId,
100+
duration: duration,
101+
resource: resource,
102+
};
103+
return apiCall("/app/analytics/traffic", HttpMethod.GET, data);
104+
}
105+
106+
/**
107+
* Get application traffic details.
108+
* @param {number} serverId Numeric id of the server.
109+
* @param {number} appId Numeric id of the app.
110+
* @param {string} from Start time in the format "DD/MM/YYYY HH:mm".
111+
* @param {string} until End time in the format "DD/MM/YYYY HH:mm".
112+
* @param {string[]} resourceList Array of resources returned from the traffic call (e.g., ["127.0.0.1", "192.168.1.1"]).
113+
* @returns {Promise<any>} A promise resolving with the application traffic details.
114+
*/
115+
export function getApplicationTrafficDetail(
116+
serverId: number,
117+
appId: number,
118+
from: string,
119+
until: string,
120+
resourceList: string[]
121+
): Promise<any> {
122+
const data = {
123+
server_id: serverId,
124+
app_id: appId,
125+
from: from,
126+
until: until,
127+
resource_list: resourceList,
128+
};
129+
return apiCall("/app/analytics/trafficDetail", HttpMethod.GET, data);
130+
}
131+
132+
/**
133+
* Get PHP information.
134+
* @param {number} serverId Numeric id of the server.
135+
* @param {number} appId Numeric id of the app.
136+
* @param {string} duration String duration (e.g., "15m", "30m", "1h", "1d").
137+
* @param {string} resource String type ("url_durations", "processes", "slow_pages").
138+
* @returns {Promise<any>} A promise resolving with the PHP information.
139+
*/
140+
export function getPHPInformation(
141+
serverId: number,
142+
appId: number,
143+
duration: string,
144+
resource: string
145+
): Promise<any> {
146+
const data = {
147+
server_id: serverId,
148+
app_id: appId,
149+
duration: duration,
150+
resource: resource,
151+
};
152+
return apiCall("/app/analytics/php", HttpMethod.GET, data);
153+
}
154+
155+
/**
156+
* Get MySQL information.
157+
* @param {number} serverId Numeric id of the server.
158+
* @param {number} appId Numeric id of the app.
159+
* @param {string} duration String duration (e.g., "15m", "30m", "1h", "1d").
160+
* @param {string} resource String resource ("running_queries", "slow_queries").
161+
* @returns {Promise<any>} A promise resolving with the MySQL information.
162+
*/
163+
export function getMySQLInformation(
164+
serverId: number,
165+
appId: number,
166+
duration: string,
167+
resource: string
168+
): Promise<any> {
169+
const data = {
170+
server_id: serverId,
171+
app_id: appId,
172+
duration: duration,
173+
resource: resource,
174+
};
175+
return apiCall("/app/analytics/mysql", HttpMethod.GET, data);
176+
}
177+
178+
/**
179+
* Get application cron information.
180+
* @param {number} serverId Numeric id of the server.
181+
* @param {number} appId Numeric id of the app.
182+
* @returns {Promise<any>} A promise resolving with the application cron information.
183+
*/
184+
export function getApplicationCron(
185+
serverId: number,
186+
appId: number
187+
): Promise<any> {
188+
const data = {
189+
server_id: serverId,
190+
app_id: appId,
191+
};
192+
return apiCall("/app/analytics/cron", HttpMethod.GET, data);
193+
}

0 commit comments

Comments
 (0)