![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
![]() ![]() Прогромма по разбору лог-файла: Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, ComCtrls, DateUtils; type TForm1 = class(TForm) Button1: TButton; StringGrid1: TStringGrid; OpenDialog1: TOpenDialog; ComboBox1: TComboBox; Label1: TLabel; DateTimePicker1: TDateTimePicker; DateTimePicker2: TDateTimePicker; Button3: TButton; Label2: TLabel; Label3: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ComboBox1Enter(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type code_http=record data,time,process,command,traffic:string; date:TDateTime; end; var Form1: TForm1; tabl:code_http; Words:TStringList;// Список процессов numb:integer; bool:boolean; summa:int64; year,Month,Day:Word; F:textfile; implementation {$R *.dfm} {$R resfile.res} Function GetWord(var S:string):string; { Вспомогательная функция для выделения очередного слова из строки } const // Множество символов слова: Letters: set of Char = [chr(33)..chr(255)]; begin Result:=''; // Удаляем в начале строки все символы, не относящиеся к слову while (S <> '') and not (S[1] in Letters) do Delete(S,1,1); // Формируем очередное слово while (S <> '') and (S[1] in Letters) do begin Result:=Result + S[1]; Delete(S,1,1); end; end; procedure TForm1.Button1Click(Sender: TObject); label 2; var i:integer;s1,s:string; begin // Готовим список Words: Words:=TStringList.Create; Words.Sorted:=True; // Сортируем строки Words.Duplicates := dupIgnore; // С помощью стандартного диалогового окна получаем имя файла if not(OpenDialog1.Execute) then begin // Файл нельзя открыть: ShowMessage('Невозможно открыть файл ' + OpenDialog1.FileName); Exit; end else begin AssignFile(F, OpenDialog1.FileName); if fileexists(OpenDialog1.FileName) then begin Reset(F); repeat 2:readln(F,S); s1:=GetWord(S);s1:=GetWord(S);s1:=GetWord(S); if (copy(s1,3,1)='/')or(copy(s1,1,1)<>'[') then goto 2 else s1:=copy(s1,2,pos(':',s1)-2); Words.Add(s1); Words.Add('все процессы'); until EOF(F); closefile(f); end;end; ComboBox1.Enabled:=true; DateTimePicker1.Enabled:=true; DateTimePicker2.Enabled:=true; Button3.Enabled:=true; end; procedure TForm1.FormCreate(Sender: TObject); begin bool:=false; StringGrid1.Cells[0,0]:='Дата'; StringGrid1.Cells[1,0]:='Время'; StringGrid1.Cells[2,0]:='Процесс'; StringGrid1.Cells[3,0]:='Событие'; StringGrid1.Cells[4,0]:='Трафик'; end; procedure TForm1.ComboBox1Enter(Sender: TObject); var i:integer; begin if bool=false then begin for i:=0 to Words.Count-1 do ComboBox1.Items.Add(Words[i]); bool:=true;end; end; procedure TForm1.Button3Click(Sender: TObject); label 1; var i,j:integer;S,stroka:string; begin StringGrid1.RowCount:=2; StringGrid1.Cells[0,1]:=''; StringGrid1.Cells[1,1]:=''; StringGrid1.Cells[2,1]:=''; StringGrid1.Cells[3,1]:=''; StringGrid1.Cells[4,1]:=''; // Пытаемся открыть файл AssignFile(F, OpenDialog1.FileName); if fileexists(OpenDialog1.FileName) then begin Reset(F); // Читаем файл по строкам i:=1;summa:=0; Screen.Cursor:=crHourGlass; repeat 1:readln(F,S); // Читаем очередную строк, // Выделяем из строки слова и заносим их в запись. stroka:=GetWord(S); Year:=strtoint(copy(stroka,1,pos('/',stroka)-1)); stroka:=copy(stroka,pos('/',stroka)+1,length(stroka)-pos('/',stroka)); Month:=strtoint(copy(stroka,1,pos('/',stroka)-1)); Day:=strtoint(copy(stroka,pos('/',stroka)+1,length(stroka)-pos('/',stroka))); tabl.date:=EncodeDate(Year,Month,Day); tabl.data:=FormatDateTime('dddddd',tabl.date); {tabl.data:=DateToStr(tabl.date); } tabl.time:=GetWord(S); tabl.process:=GetWord(S); if (copy(tabl.process,3,1)='/')or(copy(tabl.process,1,1)<>'[') then goto 1 else tabl.process:=copy(tabl.process,2,pos(':',tabl.process)-2); Words.Add(tabl.process); Words.Add('все процессы'); tabl.command:=GetWord(S); tabl.traffic:=GetWord(S); if not((copy(tabl.traffic,1,1)<>'f')) then goto 1; if ((CompareDate(DateTimePicker1.Date,tabl.date)=0)or(CompareDate(DateTimePicker1.D ate,tabl.date)=-1))and ((CompareDate(DateTimePicker2.Date,tabl.date)=0)or(CompareDate(DateTimePicker2.D ate,tabl.date)=1))and ((ComboBox1.Items.Strings[ComboBox1.ItemIndex]=tabl.process)or(ComboBox1.Items.S trings[ComboBox1.ItemIndex]='все процессы')) then begin StringGrid1.Cells[0,i]:=tabl.data; StringGrid1.Cells[1,i]:=tabl.time; StringGrid1.Cells[2,i]:=tabl.process; StringGrid1.Cells[3,i]:=tabl.command; StringGrid1.Cells[4,i]:=tabl.traffic; StringGrid1.RowCount:=StringGrid1.RowCount+1; summa:=summa+strtoint (tabl.traffic); i:=i+1; end; until EOF(F); end; numb:=i-1; Screen.Cursor:=crDefault; CloseFile(F); Screen.Cursor:=crDefault; if i>1 then StringGrid1.RowCount:=StringGrid1.RowCount-1; Label1.Visible:=true; summa:=(summa div 1024) div 1024; Label1.Caption:='Сумма: '+inttostr(summa)+' Мбайт'; end; end. Admin: Пользуемся тегами для оформления кода! Последний раз редактировалось Admin, 17.06.2008 в 10:29. |
#2
|
||||
|
||||
![]() Читайте правила
Что делать, когда сломался комп: 1. Если вы юзер - делать ноги. 2. Если ремонтник - делать деньги. 3. Если вы программист - делать вид, что так было задумано. |