This commit is contained in:
phoenix
2024-12-26 23:12:28 +08:00
parent 5489440c79
commit d181b86f3c
11 changed files with 219 additions and 11 deletions
+59 -3
View File
@@ -16,6 +16,7 @@
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/router": "^19.0.0",
"axios": "^1.7.9",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
@@ -5388,6 +5389,12 @@
"dev": true,
"license": "MIT"
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/autoprefixer": {
"version": "10.4.20",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.20.tgz",
@@ -5426,6 +5433,17 @@
"postcss": "^8.1.0"
}
},
"node_modules/axios": {
"version": "1.7.9",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/babel-loader": {
"version": "9.2.1",
"resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-9.2.1.tgz",
@@ -6208,6 +6226,18 @@
"dev": true,
"license": "MIT"
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
@@ -6679,6 +6709,15 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -7572,7 +7611,6 @@
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"dev": true,
"funding": [
{
"type": "individual",
@@ -7606,6 +7644,20 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/form-data": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -9803,7 +9855,6 @@
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 0.6"
@@ -9813,7 +9864,6 @@
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
@@ -11381,6 +11431,12 @@
"node": ">= 0.10"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/prr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
+1
View File
@@ -18,6 +18,7 @@
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/router": "^19.0.0",
"axios": "^1.7.9",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
+13 -8
View File
@@ -1,12 +1,17 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { ResourceUsageComponent } from "./resource-usage/resource-usage.component";
import { KillProcessComponent } from "./kill-process/kill-process.component";
@Component({
selector: 'app-root',
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
template: `
<div>
<h1>Resource Monitor</h1>
<app-resource-usage></app-resource-usage>
<br>
<app-kill-process></app-kill-process>
</div>
`,
styleUrls: ['./app.component.scss'],
imports: [ResourceUsageComponent, KillProcessComponent]
})
export class AppComponent {
title = 'tower-app';
}
export class AppComponent { }
@@ -0,0 +1,6 @@
<div>
<h2>Kill Process</h2>
<input type="number" [(ngModel)]="processId" placeholder="Enter Process ID">
<button (click)="killProcess()">Kill Process</button>
<p *ngIf="message">{{ message }}</p>
</div>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { KillProcessComponent } from './kill-process.component';
describe('KillProcessComponent', () => {
let component: KillProcessComponent;
let fixture: ComponentFixture<KillProcessComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [KillProcessComponent]
})
.compileComponents();
fixture = TestBed.createComponent(KillProcessComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,28 @@
import { Component, OnInit } from '@angular/core';
import axios from 'axios';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-kill-process',
templateUrl: './kill-process.component.html',
styleUrls: ['./kill-process.component.scss'],
imports: [FormsModule,CommonModule]
})
export class KillProcessComponent implements OnInit {
processId: number = 0;
message: string = '';
constructor() { }
ngOnInit(): void {}
async killProcess() {
try {
const response = await axios.post('http://localhost:5000/api/kill-process', this.processId.toString());
this.message = response.data;
} catch (error) {
console.error('Error killing process:', error);
this.message = 'An error occurred while trying to kill the process.';
}
}
}
@@ -0,0 +1,39 @@
<div *ngIf="resourceData; else loading">
<h2>Resource Usage</h2>
<p>Current Time: {{ resourceData.CurrentTime }}</p>
<p>Computer Info:</p>
<div *ngIf="resourceData.ComputerInfo; else loading">
<ul>
<li>Machine Name: {{ resourceData.ComputerInfo.MachineName }}</li>
<li>OS Version: {{ resourceData.ComputerInfo.OSVersion }}</li>
<li>OS Architecture: {{ resourceData.ComputerInfo.OSArchitecture }}</li>
<li>Processor Count: {{ resourceData.ComputerInfo.ProcessorCount }}</li>
</ul>
</div>
<p>CPU Usage:</p>
<div *ngIf="resourceData.CPU; else loading">
<p>Usage: {{ resourceData.CPU.Usage }}%</p>
<ul>
<li *ngFor="let process of resourceData.CPU.Processes">
<strong>ID:</strong> {{ process.Id }}
<br>
<strong>Name:</strong> {{ process.Name }}
<br>
<strong>Total Processor Time:</strong> {{ process.TotalProcessorTime }}
<br>
<strong>Working Set (MB):</strong> {{ process.WorkingSet64 }}
</li>
</ul>
</div>
<p>RAM Usage: {{ resourceData.RAM }}%</p>
<p>GPU Usage:</p>
<div *ngIf="resourceData.GPU; else loading">
<p>Usage: {{ resourceData.GPU.Usage }}%</p>
<p>Temperature: {{ resourceData.GPU.Temperature }}</p>
<p>Fan Speed: {{ resourceData.GPU.FanSpeed }}</p>
</div>
</div>
<div *ngIf="!resourceData">
Loading...
</div>
<ng-template #loading>Loading...</ng-template>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ResourceUsageComponent } from './resource-usage.component';
describe('ResourceUsageComponent', () => {
let component: ResourceUsageComponent;
let fixture: ComponentFixture<ResourceUsageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ResourceUsageComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ResourceUsageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,27 @@
import { Component, OnInit } from '@angular/core';
import axios from 'axios';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-resource-usage',
templateUrl: './resource-usage.component.html',
styleUrls: ['./resource-usage.component.scss'],
imports: [CommonModule]
})
export class ResourceUsageComponent implements OnInit {
resourceData: any = {};
constructor() { }
ngOnInit(): void {
this.getResourceUsage();
}
async getResourceUsage() {
try {
const response = await axios.get('http://localhost:5000/api/resource-usage');
this.resourceData = response.data;
} catch (error) {
console.error('Error fetching resource usage data:', error);
}
}
}