This repository was archived by the owner on Aug 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838 "@biomejs/biome" : " 1.9.4" ,
3939 "@its_4_nik/gitai" : " ^1.1.14" ,
4040 "@types/bun" : " latest" ,
41- "@types/dockerode" : " ^3.3.41 " ,
41+ "@types/dockerode" : " ^3.3.42 " ,
4242 "@types/js-yaml" : " ^4.0.9" ,
4343 "@types/node" : " ^22.15.32" ,
4444 "@types/split2" : " ^4.2.3" ,
Original file line number Diff line number Diff line change 1- import type { containerStatistics } from "~/typings/database" ;
1+ import type { container_stats } from "~/typings/database" ;
22import { db } from "./database" ;
33import { executeDbOperation } from "./helper" ;
44
@@ -9,44 +9,35 @@ const insert = db.prepare(`
99
1010const get = db . prepare ( "SELECT * FROM container_stats" ) ;
1111
12- export function addContainerStats (
13- id : string ,
14- hostId : string ,
15- name : string ,
16- image : string ,
17- status : string ,
18- state : string ,
19- cpu_usage : number ,
20- memory_usage : number ,
21- ) {
12+ export function addContainerStats ( stats : container_stats ) {
2213 return executeDbOperation (
2314 "Add Container Stats" ,
2415 ( ) =>
2516 insert . run (
26- id ,
27- hostId ,
28- name ,
29- image ,
30- status ,
31- state ,
32- cpu_usage ,
33- memory_usage ,
17+ stats . id ,
18+ stats . hostId ,
19+ stats . name ,
20+ stats . image ,
21+ stats . status ,
22+ stats . state ,
23+ stats . cpu_usage ,
24+ stats . memory_usage ,
3425 ) ,
3526 ( ) => {
3627 if (
37- typeof id !== "string" ||
38- typeof hostId !== "string " ||
39- typeof cpu_usage !== "number" ||
40- typeof memory_usage !== "number"
28+ typeof stats . id !== "string" ||
29+ typeof stats . hostId !== "number " ||
30+ typeof stats . cpu_usage !== "number" ||
31+ typeof stats . memory_usage !== "number"
4132 ) {
4233 throw new TypeError ( "Invalid container stats parameters" ) ;
4334 }
4435 } ,
4536 ) ;
4637}
4738
48- export function getContainerStats ( ) : containerStatistics [ ] {
39+ export function getContainerStats ( ) : container_stats [ ] {
4940 return executeDbOperation ( "Get Container Stats" , ( ) =>
5041 get . all ( ) ,
51- ) as containerStatistics [ ] ;
42+ ) as container_stats [ ] ;
5243}
Original file line number Diff line number Diff line change 11import Docker from "dockerode" ;
22import { logger } from "~/core/utils/logger" ;
3- import type { DockerHost } from "../../.. /typings/docker" ;
3+ import type { DockerHost } from "~ /typings/docker" ;
44
55export const getDockerClient = ( host : DockerHost ) : Docker => {
66 try {
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ async function startFor(host: DockerHost) {
6868 if ( event . Type === "container" ) {
6969 const containerInfo : ContainerInfo = {
7070 id : event . Actor ?. ID || event . id || "" ,
71- hostId : host . name ,
71+ hostId : host . id ,
7272 name : event . Actor ?. Attributes ?. name || "" ,
7373 image : event . Actor ?. Attributes ?. image || event . from || "" ,
7474 status : event . status || event . Actor ?. Attributes ?. status || "" ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { dbFunctions } from "~/core/database";
22import storeContainerData from "~/core/docker/store-container-stats" ;
33import storeHostData from "~/core/docker/store-host-stats" ;
44import { logger } from "~/core/utils/logger" ;
5- import type { config } from "../../.. /typings/database" ;
5+ import type { config } from "~ /typings/database" ;
66
77function convertFromMinToMs ( minutes : number ) : number {
88 return minutes * 60 * 1000 ;
Original file line number Diff line number Diff line change 55 calculateCpuPercent ,
66 calculateMemoryUsage ,
77} from "~/core/utils/calculations" ;
8+ import type { container_stats } from "~/typings/database" ;
89import { logger } from "../utils/logger" ;
910
1011async function storeContainerData ( ) {
@@ -68,16 +69,18 @@ async function storeContainerData() {
6869 } ,
6970 ) ;
7071
71- dbFunctions . addContainerStats (
72- containerInfo . Id ,
73- host . name ,
74- containerName ,
75- containerInfo . Image ,
76- containerInfo . Status ,
77- containerInfo . State ,
78- calculateCpuPercent ( stats ) ,
79- calculateMemoryUsage ( stats ) ,
80- ) ;
72+ const parsed : container_stats = {
73+ cpu_usage : calculateCpuPercent ( stats ) ,
74+ hostId : host . id ,
75+ id : containerInfo . Id ,
76+ image : containerInfo . Image ,
77+ memory_usage : calculateMemoryUsage ( stats ) ,
78+ name : containerName ,
79+ state : containerInfo . State ,
80+ status : containerInfo . Status ,
81+ } ;
82+
83+ dbFunctions . addContainerStats ( parsed ) ;
8184 } catch ( error ) {
8285 const errMsg =
8386 error instanceof Error ? error . message : String ( error ) ;
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export async function loadPlugins(pluginDir: string) {
4343 pluginManager . register ( plugin ) ;
4444 pluginCount ++ ;
4545 } catch ( error ) {
46- pluginManager . fail ( { name : file } ) ;
46+ pluginManager . fail ( { name : file , version : "0.0.0" } ) ;
4747 logger . error (
4848 `Error while registering plugin ${ absolutePath } : ${ error as string } ` ,
4949 ) ;
Original file line number Diff line number Diff line change 11import { EventEmitter } from "node:events" ;
2- import type { ContainerInfo } from "../../.. /typings/docker" ;
3- import type { Plugin , PluginInfo } from "../../.. /typings/plugin" ;
2+ import type { ContainerInfo } from "~ /typings/docker" ;
3+ import type { Plugin , PluginInfo } from "~ /typings/plugin" ;
44import { logger } from "../utils/logger" ;
55
66function getHooks ( plugin : Plugin ) {
@@ -52,29 +52,31 @@ class PluginManager extends EventEmitter {
5252 }
5353
5454 getPlugins ( ) : PluginInfo [ ] {
55- const loadedPlugins = Array . from ( this . plugins . values ( ) ) . map ( ( plugin ) => {
55+ const plugins : PluginInfo [ ] = [ ] ;
56+
57+ for ( const plugin of this . plugins . values ( ) ) {
5658 logger . debug ( `Loaded plugin: ${ plugin } ` ) ;
5759 const hooks = getHooks ( plugin ) ;
58- return {
60+ plugins . push ( {
5961 name : plugin . name ,
62+ version : plugin . version ,
6063 status : "active" ,
6164 usedHooks : hooks ,
62- } ;
63- } ) ;
64-
65- const failedPlugins = Array . from ( this . failedPlugins . values ( ) ) . map (
66- ( plugin ) => {
67- const hooks = getHooks ( plugin ) ;
68-
69- return {
70- name : plugin . name ,
71- status : "inactive" ,
72- usedHooks : hooks ,
73- } ;
74- } ,
75- ) ;
76-
77- return loadedPlugins . concat ( failedPlugins ) ;
65+ } ) ;
66+ }
67+
68+ for ( const plugin of this . failedPlugins . values ( ) ) {
69+ logger . debug ( `Loaded plugin: ${ plugin } ` ) ;
70+ const hooks = getHooks ( plugin ) ;
71+ plugins . push ( {
72+ name : plugin . name ,
73+ version : plugin . version ,
74+ status : "inactive" ,
75+ usedHooks : hooks ,
76+ } ) ;
77+ }
78+
79+ return plugins ;
7880 }
7981
8082 // Trigger plugin flows:
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export async function deployStack(stack_config: stacks_config): Promise<void> {
3535
3636 postToClient ( {
3737 type : "stack-status" ,
38+ timestamp : new Date ( ) ,
3839 data : {
3940 stack_id : stackId ,
4041 status : "pending" ,
@@ -66,6 +67,7 @@ export async function deployStack(stack_config: stacks_config): Promise<void> {
6667
6768 postToClient ( {
6869 type : "stack-status" ,
70+ timestamp : new Date ( ) ,
6971 data : {
7072 stack_id : stackId ,
7173 status : "deployed" ,
@@ -109,6 +111,7 @@ export async function deployStack(stack_config: stacks_config): Promise<void> {
109111
110112 postToClient ( {
111113 type : "stack-error" ,
114+ timestamp : new Date ( ) ,
112115 data : {
113116 stack_id : stackId ?? 0 ,
114117 action : "deploying" ,
@@ -210,6 +213,7 @@ export async function removeStack(stack_id: number): Promise<void> {
210213 logger . error ( errorMsg ) ;
211214 postToClient ( {
212215 type : "stack-error" ,
216+ timestamp : new Date ( ) ,
213217 data : {
214218 stack_id,
215219 action : "removing" ,
@@ -224,6 +228,7 @@ export async function removeStack(stack_id: number): Promise<void> {
224228
225229 postToClient ( {
226230 type : "stack-removed" ,
231+ timestamp : new Date ( ) ,
227232 data : {
228233 stack_id,
229234 message : "Stack removed successfully" ,
@@ -234,6 +239,7 @@ export async function removeStack(stack_id: number): Promise<void> {
234239 logger . error ( errorMsg ) ;
235240 postToClient ( {
236241 type : "stack-error" ,
242+ timestamp : new Date ( ) ,
237243 data : {
238244 stack_id,
239245 action : "removing" ,
Original file line number Diff line number Diff line change 1- import type { Stack } from "~/../typings/docker-compose" ;
21import { logger } from "~/core/utils/logger" ;
32import { postToClient } from "~/handlers/modules/live-stacks" ;
3+ import type { Stack } from "~/typings/docker-compose" ;
44import { getStackName , getStackPath } from "./stackHelpers" ;
55
66export function wrapProgressCallback ( progressCallback ?: ( log : string ) => void ) {
@@ -51,6 +51,7 @@ export async function runStackCommand<T>(
5151
5252 postToClient ( {
5353 type : "stack-progress" ,
54+ timestamp : new Date ( ) ,
5455 data : {
5556 stack_id,
5657 action,
@@ -77,6 +78,7 @@ export async function runStackCommand<T>(
7778 ) ;
7879 postToClient ( {
7980 type : "stack-error" ,
81+ timestamp : new Date ( ) ,
8082 data : {
8183 stack_id,
8284 action,
You can’t perform that action at this time.
0 commit comments