README.trace_services 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. Trace and audit services.
  2. Firebird 2.5 offers new trace and audit facilities. These new abilities allow
  3. to log various events performed inside the engine (such as statement execution,
  4. connect\disconnect etc) and to collect corresponding performance characteristics
  5. in real time. The base term is trace session. Each trace session has its own
  6. configuration, state and output.
  7. List of available events to trace is fixed and determined by the Firebird
  8. engine. List of events to trace, which data items to trace and placement of
  9. trace output is specified by trace configuration when trace session is created.
  10. There are two kinds of trace sessions : system audit and user trace.
  11. System audit session is started by the engine itself and obtains configuration
  12. from the text file. The name of this file is set via new setting in firebird.conf
  13. ("AuditTraceConfigFile") and by default has empty value, i.e. no system audit
  14. is configured. There may be only one system audit trace session, obviously.
  15. Configuration file contains list of traced events and placement of trace log(s).
  16. It is very flexible and allows to log different set of events for different
  17. databases into different log files. Example configuration file fbtrace.conf is
  18. placed in the Firebird root directory and contains full description of its
  19. format, rules and syntax.
  20. User trace session is managed by user via Services API. There are five new
  21. services for this purpose - to start, stop, suspend, resume trace session and
  22. to list all known trace sessions. See README.services_extension for details.
  23. When user application starts trace session it sets (optional) session name
  24. and (mandatory) session configuration. Session configuration is a text. Rules
  25. and syntax are the same as for configuration file mentioned above except of
  26. placement of trace output. Engine stores output of user session in set of
  27. temporary files (1MB each) and deletes it automatically when file was read
  28. completely. Maximum size of user session's output is limited and set via
  29. "MaxUserTraceLogSize" setting in firebird.conf. Default value is 10 MB.
  30. After application starts user trace session, it must read session's output
  31. from service (using isc_service_query). Session output could be produced by the
  32. engine faster than application is able to read it. When session output grows
  33. more than "MaxUserTraceLogSize" engine automatically suspends this trace
  34. session. When application reads part of the output so output size stay less than
  35. "MaxUserTraceLogSize" engine automatically resumes trace session.
  36. When application decides to stop its trace session it just does detach from
  37. service. Also there is ability to manage trace sessions (suspend\resume\stop).
  38. Administrators are allowed to manage any trace session while ordinary users are
  39. allowed to manage their own trace sessions only.
  40. If user trace session was created by ordinary user it will trace only
  41. connections established by this user.
  42. User trace sessions are not preserved when all Firebird processes are stopped.
  43. I.e. if user started trace session and Firebird SS or SC process is shut down,
  44. this session is stopped and will not be restarted with new Firebird process. For
  45. CS this is not the case as user trace session can't live without connection with
  46. service manager and dedicated CS process.
  47. There is new Trace API introduced for use with trace facilities. This API is
  48. not stable and will be changed in next Firebird releases, therefore it is not
  49. officially published. Trace API is a set of hooks which is implemented by external
  50. trace plugin module and called by the engine when any traced event happens. Trace
  51. plugin is responsible for logging these events in some form.
  52. There is "standard" implementation of trace plugin, fbtrace.dll (.so) located
  53. in \plugins folder.
  54. There is new specialized standalone utility to work with trace services :
  55. fbtracemgr. It has the following command line switches :
  56. Action switches :
  57. -STA[RT] Start trace session
  58. -STO[P] Stop trace session
  59. -SU[SPEND] Suspend trace session
  60. -R[ESUME] Resume trace session
  61. -L[IST] List existing trace sessions
  62. Action parameters switches :
  63. -N[AME] <string> Session name
  64. -I[D] <number> Session ID
  65. -C[ONFIG] <string> Trace configuration file name
  66. Connection parameters switches :
  67. -SE[RVICE] <string> Service name
  68. -U[SER] <string> User name
  69. -P[ASSWORD] <string> Password
  70. -FE[TCH] <string> Fetch password from file
  71. -T[RUSTED] <string> Force trusted authentication
  72. Also, it prints usage screen if run without parameters.
  73. Examples
  74. I. Sample configuration files for user trace sessions:
  75. a) Trace prepare, free and execution of all statements within connection 12345
  76. <database>
  77. enabled true
  78. connection_id 12345
  79. log_statement_prepare true
  80. log_statement_free true
  81. log_statement_start true
  82. log_statement_finish true
  83. time_threshold 0
  84. </database>
  85. b) Trace all connections of given user to database mydatabase.fdb
  86. Log executed INSERT, UPDATE and DELETE statements, nested calls to procedures
  87. and triggers and show corresponding PLAN's and performance statistics.
  88. <database %[\\/]mydatabase.fdb>
  89. enabled true
  90. include_filter (%)(INSERT|UPDATE|DELETE)(%)
  91. log_statement_finish true
  92. log_procedure_finish true
  93. log_trigger_finish true
  94. print_plan true
  95. print_perf true
  96. time_threshold 0
  97. </database>
  98. c) Trace connections and transactions in all databases except of security database
  99. <database>
  100. enabled true
  101. log_connections true
  102. log_transactions true
  103. </database>
  104. <database security2.fdb>
  105. enabled false
  106. </database>
  107. II. Working with fbtracemgr :
  108. a) Start user trace named "My trace" using configuration file fbtrace.conf and read
  109. its output on the screen :
  110. fbtracemgr -se service_mgr -start -name "My trace" -config fbtrace.conf
  111. To stop this trace session press Ctrl+C at fbtracemgr console window. Or, in
  112. another console : list sessions and look for interesting session ID (b) and stop it
  113. using this found ID (e).
  114. b) List trace sesions
  115. fbtracemgr -se service_mgr -list
  116. c) Suspend trace sesson with ID 1
  117. fbtracemgr -se service_mgr -suspend -id 1
  118. d) Resume trace sesson with ID 1
  119. fbtracemgr -se service_mgr -resume -id 1
  120. e) Stop trace sesson with ID 1
  121. fbtracemgr -se service_mgr -stop -id 1
  122. There are three general use cases :
  123. 1. Constant audit of engine.
  124. This is served by system audit trace. Administrator edits (or creates new)
  125. trace configuration file, sets its name in firebird.conf (AuditTraceConfigFile
  126. setting) and restarts Firebird. Later, administrator could suspend\resume\stop
  127. this session without need to restart Firebird. To make audit configuration
  128. changes accepted by the engine, Firebird needs to be restarted.
  129. 2. On demand interactive trace of some (or all) activity in some (or all)
  130. databases.
  131. Application starts user trace session, reads its output and shows traced events
  132. to user in real time on the screen. User could suspend\resume trace and at last
  133. stop it.
  134. 3. Collect some engine activity for a relatively long period of time (few hours
  135. or even whole day) to analyse it later.
  136. Application starts user trace session and reads and saves trace output to a file
  137. (or set of files). Session must be stopped manually by the same application or
  138. by another one.