audit.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. .. _monitor_audit:
  2. Audit Logging
  3. =============
  4. The history mode logs all requests into a database. This can put a very significant strain
  5. on the database and can lead to insertion issues as the request table begins to host
  6. millions of records.
  7. As an alternative to the history mode it's possible to enable the auditing logger, which will log
  8. the details of each request in a file, which is periodically rolled. Secondary applications can
  9. then process these log files and built ad-hoc summaries off line.
  10. Configuration
  11. -------------
  12. The ``monitor.properties`` file can contain the following items to enable and configure file auditing::
  13. audit.enabled=true
  14. audit.path=/path/to/the/logs/directory
  15. audit.roll_limit=20
  16. The ``audit.enable`` is used to turn on the logger (it is off by default).
  17. The ``audit.path`` is the directory where the log files will be created.
  18. The ``audit.roll_limit`` is the number of requests logged into a file before rolling happens.
  19. The files are also automatically rolled at the beginning of each day.
  20. In clustered installations with a shared data directory the audit path will need to be different
  21. for each node. In this case it's possible to specify the audit path by using a JVM system variable,
  22. add the following to the JVM startup options and it will override whatever is specified in
  23. ``monitor.properties``:
  24. -DGEOSERVER_AUDIT_PATH=/path/to/the/logs/directory
  25. Log Files
  26. ---------
  27. The log directory will contain a number of log files following the ``geoserver_audit_yyyymmdd_nn.log``
  28. pattern. The ``nn`` is increased at each roll of the file. The contents of the log directory will look like::
  29. geoserver_audit_20110811_2.log
  30. geoserver_audit_20110811_3.log
  31. geoserver_audit_20110811_4.log
  32. geoserver_audit_20110811_5.log
  33. geoserver_audit_20110811_6.log
  34. geoserver_audit_20110811_7.log
  35. geoserver_audit_20110811_8.log
  36. By default each log file contents will be a xml document looking like the following::
  37. <?xml version="1.0" encoding="UTF-8" ?>
  38. <Requests>
  39. <Request id="168">
  40. <Service>WMS</Service>
  41. <Version>1.1.1</Version>
  42. <Operation>GetMap</Operation>
  43. <SubOperation></SubOperation>
  44. <Resources>GeoSolutions:elba-deparea</Resources>
  45. <ResourcesProcessingTime>4</ResourcesProcessingTime>
  46. <LabelsProcessingTime>0</LabelsProcessingTime>
  47. <Path>/GeoSolutions/wms</Path>
  48. <QueryString>LAYERS=GeoSolutions:elba-deparea&amp;STYLES=&amp;FORMAT=image/png&amp;TILED=true&amp;TILESORIGIN=9.916,42.312&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;EXCEPTIONS=application/vnd.ogc.se_inimage&amp;SRS=EPSG:4326&amp;BBOX=9.58375,42.64425,9.916,42.9765&amp;WIDTH=256&amp;HEIGHT=256</QueryString>
  49. <HttpMethod>GET</HttpMethod>
  50. <StartTime>2011-08-11T20:19:28.277Z</StartTime>
  51. <EndTime>2011-08-11T20:19:28.29Z</EndTime>
  52. <TotalTime>13</TotalTime>
  53. <RemoteAddr>192.168.1.5</RemoteAddr>
  54. <RemoteHost>192.168.1.5</RemoteHost>
  55. <Host>demo1.geo-solutions.it</Host>
  56. <RemoteUser>admin</RemoteUser>
  57. <ResponseStatus>200</ResponseStatus>
  58. <ResponseLength>1670</ResponseLength>
  59. <ResponseContentType>image/png</ResponseContentType>
  60. <Failed>false</Failed>
  61. </Request>
  62. ...
  63. </Requests>
  64. Customizing Log Contents
  65. ------------------------
  66. The log contents are driven by three FreeMarker templates.
  67. ``header.ftl`` is used once when a new log file is created to form the first few lines of the file.
  68. The default header template is::
  69. <?xml version="1.0" encoding="UTF-8" ?>
  70. <Requests>
  71. ``content.ftl`` is used to write out the request details. The default template dumps all the known fields about the request::
  72. <#escape x as x?xml>
  73. <Request id="${id!""}">
  74. <Service>${service!""}</Service>
  75. <Version>${owsVersion!""}</Version>
  76. <Operation>${operation!""}</Operation>
  77. <SubOperation>${subOperation!""}</SubOperation>
  78. <Resources>${resourcesList!""}</Resources>
  79. <ResourcesProcessingTime>${resourcesProcessingTimeList!""}</ResourcesProcessingTime>
  80. <LabelsProcessingTime>${labellingProcessingTime!""}</LabelsProcessingTime>
  81. <Path>${path!""}</Path>
  82. <QueryString>${queryString!""}</QueryString>
  83. <#if bodyAsString??>
  84. <Body>
  85. ${bodyAsString}
  86. </Body>
  87. </#if>
  88. <HttpMethod>${httpMethod!""}</HttpMethod>
  89. <StartTime>${startTime?datetime?iso_utc_ms}</StartTime>
  90. <EndTime>${endTime?datetime?iso_utc_ms}</EndTime>
  91. <TotalTime>${totalTime}</TotalTime>
  92. <RemoteAddr>${remoteAddr!""}</RemoteAddr>
  93. <RemoteHost>${remoteHost!""}</RemoteHost>
  94. <Host>${host}</Host>
  95. <RemoteUser>${remoteUser!""}</RemoteUser>
  96. <ResponseStatus>${responseStatus!""}</ResponseStatus>
  97. <ResponseLength>${responseLength?c}</ResponseLength>
  98. <ResponseContentType>${responseContentType!""}</ResponseContentType>
  99. <CacheResult>${cacheResult!""}</CacheResult>
  100. <MissReason>${missReason!""}</MissReason>
  101. <#if error??>
  102. <Failed>true</Failed>
  103. <ErrorMessage>${errorMessage!""}</ErrorMessage>
  104. <#else>
  105. <Failed>false</Failed>
  106. </#if>
  107. </Request>
  108. </#escape>
  109. ``footer.ftl`` is executed just once when the log file is closed to build the last few lines of the file.
  110. The default footer template is::
  111. </Requests>
  112. The administrator is free to provide alternate templates, they can be placed in the same directory
  113. as ``monitor.properties``, with the same names as above. GeoServer will pick them up automatically.