README.trace_services 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. -P[LUGINS] <string list> Plugins list for use with trace session; valid list separators: '\t', ',', ';'
  67. Connection parameters switches :
  68. -SE[RVICE] <string> Service name
  69. -U[SER] <string> User name
  70. -P[ASSWORD] <string> Password
  71. -FE[TCH] <string> Fetch password from file
  72. -T[RUSTED] Force trusted authentication
  73. Also, it prints usage screen if run without parameters.
  74. Examples
  75. I. Sample configuration files for user trace sessions:
  76. a) Trace prepare, free and execution of all statements within connection 12345
  77. database
  78. {
  79. enabled = true
  80. connection_id = 12345
  81. log_statement_prepare= true
  82. log_statement_free = true
  83. log_statement_start = true
  84. log_statement_finish = true
  85. time_threshold = 0
  86. }
  87. b) Trace all connections of given user to database mydatabase.fdb
  88. Log executed INSERT, UPDATE and DELETE statements, nested calls to procedures
  89. and triggers and show corresponding PLAN's and performance statistics.
  90. database = %[\\/]mydatabase.fdb
  91. {
  92. enabled = true
  93. include_filter = (%)(INSERT|UPDATE|DELETE)(%)
  94. log_statement_finish = true
  95. log_procedure_finish = true
  96. log_trigger_finish = true
  97. print_plan = true
  98. print_perf = true
  99. time_threshold = 0
  100. }
  101. c) Trace connections and transactions in all databases except of security database
  102. database
  103. {
  104. enabled = true
  105. log_connections = true
  106. log_transactions = true
  107. }
  108. database = security.db
  109. {
  110. enabled = false
  111. }
  112. II. Working with fbtracemgr :
  113. a) Start user trace named "My trace" using configuration file fbtrace.conf and read
  114. its output on the screen :
  115. fbtracemgr -se service_mgr -start -name "My trace" -config fbtrace.conf
  116. To stop this trace session press Ctrl+C at fbtracemgr console window. Or, in
  117. another console : list sessions and look for interesting session ID (b) and stop it
  118. using this found ID (e).
  119. b) List trace sessions
  120. fbtracemgr -se service_mgr -list
  121. c) Suspend trace session with ID 1
  122. fbtracemgr -se service_mgr -suspend -id 1
  123. d) Resume trace session with ID 1
  124. fbtracemgr -se service_mgr -resume -id 1
  125. e) Stop trace session with ID 1
  126. fbtracemgr -se service_mgr -stop -id 1
  127. There are three general use cases :
  128. 1. Constant audit of engine.
  129. This is served by system audit trace. Administrator edits (or creates new)
  130. trace configuration file, sets its name in firebird.conf (AuditTraceConfigFile
  131. setting) and restarts Firebird. Later, administrator could suspend\resume\stop
  132. this session without need to restart Firebird. To make audit configuration
  133. changes accepted by the engine, Firebird needs to be restarted.
  134. 2. On demand interactive trace of some (or all) activity in some (or all)
  135. databases.
  136. Application starts user trace session, reads its output and shows traced events
  137. to user in real time on the screen. User could suspend\resume trace and at last
  138. stop it.
  139. 3. Collect some engine activity for a relatively long period of time (few hours
  140. or even whole day) to analyse it later.
  141. Application starts user trace session and reads and saves trace output to a file
  142. (or set of files). Session must be stopped manually by the same application or
  143. by another one.