|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
удаленный мониторинг
надо написать программу для удаленного мониторинга 4 серверов. Все вопросы буду писать сюда.
1. Возможно ли использовать TClientSocket и TServerSocket для работы с 4 компами. 2. Как использовать readln и wtiteln чтобы не отправлять данные строку и потом не разбирать ее 3. не проще ли удалить код и начать писать заново? |
#2
|
|||
|
|||
сервер
Код:
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ScktComp, ComCtrls, ExtCtrls, Gauges, GraphBuilder, IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient; type TForm2 = class(TForm) ServerSocket1: TServerSocket; Memo1: TMemo; Button1: TButton; Timer1: TTimer; Gauge1: TGauge; Edit1: TEdit; Edit2: TEdit; Gauge2: TGauge; Button2: TButton; Edit3: TEdit; IdIcmpClient1: TIdIcmpClient; Memo2: TMemo; Label1: TLabel; procedure Timer1Timer(Sender: TObject); procedure IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); procedure Button1Click(Sender: TObject); procedure ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); procedure ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket); procedure ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; s:string; ProcGraph,pinggraph: TGraph; CPUUsageValue,pingUsagevalue:TValue; MemValue :TValue; ProcValuesCount,PingValuesCount:byte; stroka,delimeter: string; slovo:integer; cpu,memtot,memavail,memuse,ping,time: integer; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin serversocket1.Active:=false; serversocket1.Active:=true; end; procedure TForm2.FormCreate(Sender: TObject); var z,i:integer; v:TValue; begin ServerSocket1.Open; ProcValuesCount:=40; ProcGraph:=TGraph.Create(Form2); ProcGraph.SetBounds(100,304,(Form2.ClientWidth div 3)*2+4,(Form2.ClientHeight div 3)+22); ProcGraph.CellSize:=5; ProcGraph.FrameColor:=0; ProcGraph.BackColor:=clBlack; ProcGraph.VerticalAxesSignatures:=false; ProcGraph.HorizontalAxesSignatures:=false; ProcGraph.AxesColor:=RGB(0,150,0); ProcGraph.MaxY:=100; v.Value:=0; v.ValueDescription:=''; v.Visible:=true; for i:=1 to ProcValuesCount do begin ProcGraph.AddLastValue(v,false); end; // ProcGraph.PopupMenu:=PopupMenu1; // ProcGraph.OnClick:=OnGraphClick; //Form2.Color:=ProcGraph.BackColor; ProcGraph.Show; pinggraph:=Tgraph.Create(form2); pingGraph.SetBounds(0,3,(Form2.ClientWidth div 3)*2+4,(Form2.ClientHeight div 3)+22); pingGraph.CellSize:=5; pingGraph.FrameColor:=0; pingGraph.BackColor:=clBlack; pingGraph.VerticalAxesSignatures:=false; pingGraph.HorizontalAxesSignatures:=false; pingGraph.AxesColor:=RGB(0,150,0); pingGraph.MaxY:=100; v.Value:=0; v.ValueDescription:=''; v.Visible:=true; for i:=1 to ProcValuesCount do begin pingGraph.AddLastValue(v,false); end; // ProcGraph.PopupMenu:=PopupMenu1; // ProcGraph.OnClick:=OnGraphClick; //Form2.Color:=ProcGraph.BackColor; pingGraph.Show; form2.IdIcmpClient1.Host:=''; IdIcmpClient1.Ping(); end; procedure TForm2.FormDestroy(Sender: TObject); begin ServerSocket1.Close(); end; procedure TForm2.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); begin ping:=areplystatus.MsRoundTripTime; Memo2.Lines.Add ('Reply:'+IntToStr(areplystatus.MsRoundTripTime));// (AReplyStatus.MsRoundTripTime)); Memo2.Lines.Add ('Host:'+form2.IdIcmpClient1.Host); end; procedure TForm2.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); begin Memo1.Lines.Add('Клиент соединился'); end; procedure TForm2.ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket); begin Memo1.Lines.Add('Клиент oтсоединился'); end; procedure TForm2.ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket); var CPUUsageValue:TValue; PingUsageValue:Tvalue; begin //s:=Socket.ReceiveText; CPUUsageValue.Value:=Round(Abs((cpu))); CPUUsageValue.Visible:=true; if ProcGraph<>nil then begin if ProcGraph.ValuesCount=ProcValuesCount then ProcGraph.DeleteValue(0,false); ProcGraph.AddLastValue(CPUUsageValue,true); PingUsageValue.Value:=(ping); PingUsageValue.Visible:=true; if PingGraph<>nil then begin if PingGraph.ValuesCount=PingValuesCount then PingGraph.DeleteValue(0,false); PingGraph.AddLastValue(PingUsageValue,true); end; s:=(UTF8Decode(WideString(Socket.ReceiveText))); with TStringList.Create do begin Delimiter:='/'; DelimitedText:=s; for slovo := 0 to Count - 1 do edit2.Text:=(strings[2])+' Доступно Mb'; edit1.Text:=(strings[1])+' Всего Mb'; cpu:=strtoint(strings[0]); memuse:=strtoint(strings[3]); // time:=strtoint([4]); Free; //edit3.Text:=(s); end; gauge1.Progress:=(cpu); gauge2.progress:=(memuse); end; end; procedure TForm2.Timer1Timer(Sender: TObject); begin begin try IdIcmpClient1.Ping(); except Memo1.Lines.Add ('WiFi не включен'); end; //Label1.Caption := 'Продолжительность работы компа: '+Time; end; end; end. |
#3
|
|||
|
|||
клиент
Код:
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ScktComp,Processor, ComCtrls,GraphBuilder,Tlhelp32, ExtCtrls, WinSock; type TForm2 = class(TForm) ClientSocket1: TClientSocket; Edit1: TEdit; Button1: TButton; Timer1: TTimer; Edit2: TEdit; Memo1: TMemo; Label1: TLabel; procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; CPU : Integer; Processor: TProcessor; memtot, memavail,memuse: integer; s:string; Co:BOOL; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin clientsocket1.Active:=false; clientsocket1.Active:=true; end; procedure TForm2.FormCreate(Sender: TObject); var MemoryStatus: TMemoryStatus; begin ClientSocket1.Open; Processor:=TProcessor.Create(Application); Processor.Init; MemoryStatus.dwLength := SizeOf(MemoryStatus) ; GlobalMemoryStatus(MemoryStatus) ; with MemoryStatus do begin memtot:= (dwTotalPhys div 1048576); memavail:=(dwAvailPhys div 1048576); memuse:= (dwMemoryLoad); end; end; procedure TForm2.FormDestroy(Sender: TObject); begin ; ClientSocket1.Close; FreeAndNil(Processor); end; { function TimeWorks: String; var Hours, Minutes, TheLength: Integer; begin TheLength:=GetTickCount; Hours:=TheLength div 3600000; Minutes:=(TheLength mod 3600000) div 60000; // ShowWindow (Application.handle, SW_HIDE); result := IntToStr(Hours)+' часов '+IntToStr(Minutes)+' минут '; end; } procedure TForm2.Timer1Timer(Sender: TObject); var MemoryStatus: TMemoryStatus; ProcUsege:integer; begin ProcUsege:=Processor.CPUUsageNow; // time:= TimeWorks; s:=inttostr(ProcUsege);//+'/'+ (inttostr(memtot))+'/'+ inttostr(memavail)+'/' +inttostr(memuse); //edit1.Text:=inttostr(memtot); ClientSocket1.Socket.SendText(s); MemoryStatus.dwLength := SizeOf(MemoryStatus) ; GlobalMemoryStatus(MemoryStatus) ; with MemoryStatus do begin memtot:= (dwTotalPhys div 1048576); memavail:=(dwAvailPhys div 1048576); memuse:= (dwMemoryLoad); end; end; end. |