How to trace service firebird

早过忘川 提交于 2021-01-28 02:12:24

问题


How to trace all events for service firebird server with delphi xe10? This is my code:

my := TIBControlService.Create(Self);

my.ServerName := '127.0.0.1/3050';
my.Protocol := TProtocol.TCP;

my.LoginPrompt := false;
my.TraceFlags := [tfQPrepare, tfQExecute, tfQFetch, tfError, tfStmt, tfConnect, tfTransact, tfBlob, tfService, tfMisc];

my.Params.Add( 'user_name=SYSDBA' );
my.Params.Add( 'password=masterkey' );

// -----
mh := MonitorHook;
mh.TraceFlags := my.TraceFlags;

Self.IBSQLMonitor1.TraceFlags := my.TraceFlags;
mh.RegisterMonitor(Self.IBSQLMonitor1);

Self.IBSQLMonitor1.Enabled := true;
Memo1.Lines.Add( Format('GetMonitorCount: %d',[mh.GetMonitorCount]) );


my.Attach;

Memo1.Lines.Add( Format('Active: %s',[System.StrUtils.IfThen(my.Active,'yes','no')]) );

and

procedure TForm1.IBSQLMonitor1SQL(EventText: string; EventTime: TDateTime);
begin
    Memo1.Lines.Add(EventText);
end;

Result:

GetMonitorCount: 1
Active: yes

[Application:]
:[Attach]

[Application:]
:[Query]

But this result is only from my application. When I connecting from another proces (ex.isql) my application not show this event.


回答1:


  1. When talking about Interbase/Firebird the term EVENT has a very specific meaning, the specific SQL command that sends text constants to clients, who subscribed to those.

    See http://firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-psql-coding.html#fblangref25-psql-postevent

    However, the client should subscribe to the exactly the same text string, as posted by PSQL block. There were talks about enabling masks-based subscription, which would potentially made it possible to subscribe to all SQL events, like *.* matches all files in Windows, but for the best of my knowledge they never materialized.

    That is what "event" means in Firebird, but it does not seem that is what you mean, instead it looks you want to monitor all the kinds of activity flowing between the SQL server and all the applications, starting with SQL commands and more.

    If so, then there is no way to do it in general. You have to decide what exactly and why exactly do you want, and maybe there will be some partial solutions.

  2. Firebird 2.5 introduced the so called Trace API, which allows you to subscribe to SOME of actions and be notified of them. This tends to introduce a significant load on the engine though, depending on how vague your subscription filters would be and how many requests the server receives - it might increase RAM and CPU usage up to total unusability.

    • The kinds of activity that can be subscribed for are limited. For example the process of reading BLOBs is not monitored. When I asked - I was struggling with the infamous "Invalid BLOB id" that was triggered by Delphi dbExpress library quirk - i was told that "no one ever needed this, and you have little reasons to need it too. You made a demo project, sent it to us - and we explained the behavior for you". THAT time having BLOBs access tracing would help me a lot, but to be objective, that was one and the only case I really needed it.

    • You might take a look at what you can get in general with Firebird Trace Manager - a CLI utility that is part of FB distribution, starting with 2.5.

    • You might take a look at Firebird Profiler, a free simplistic GUI tool from http://fbprofiler.sf.net

    • Commercial DB IDEs for Firebird, like IBExpert or UpScene TraceManager and probably others too, usually have Trace API support.

    • You may do your own implementation, using Trace API, starting with Program Files\Firebird\Firebird_2_5\doc\README.trace_services.txt and Program Files\Firebird\Firebird_2_5\include\ibase.h. It may also happen that 3rd party libraries like Unified Interbase or IBObjects have translated the API to Delphi. I think i saw something about trace in UIB but i am not sure. I would not expect though such a library to be part of Delphi distribution: from Delphi standpoint Firebird is direct competitor to their Interbase and IBX library would hardly have interest to diverge from their own Interbase by supporting Firebird-only functions.

  3. Provided you only care about native applications like Delphi you might decide to make your own interposer fbclient.dll and install it on all the client computers instead of stock DLLs. Same for legacy-emulating GDS32.DLL, if used by your apps.

    • This DLL should totally provide all the API calls, both classic ones described in IB6 documentation at http://firebirdsql.org/en/reference-manuals/ with all the post-IB6 updates, and the new Firebird 3 "object oriented API".
    • It should log the calls in a way of your choosing, and then should proxy the call to the copy of original client DLL that you will hide for it with different file name. It should be installed instead of the standard client DLL on every computer you care to intercept and monitor.
    • It should not be very hard with the classic API, people were doing this, though did not publish. But the new ooAPI might be challenging.
    • It will only intercept applications, working through the fbclient.DLL interface. Java applications using Jaybird and C# applications using .Net Provider libraries would probably use underlying wire protocol skipping the fbclient.dll and thus your interposer too.


来源:https://stackoverflow.com/questions/61271433/how-to-trace-service-firebird

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!