审核日志记录

历史记录模式将所有请求记录到数据库中。这会给数据库带来非常大的压力,并在请求表开始承载数百万条记录时导致插入问题。

作为历史记录模式的替代方案,可以启用审计记录器,它将每个请求的详细信息记录在一个文件中,该文件定期滚动。然后,辅助应用程序可以离线处理这些日志文件和构建即席摘要。

配置

这个 monitor.properties 文件可以包含以下项以启用和配置文件审核:

audit.enabled=true
audit.path=/path/to/the/logs/directory
audit.roll_limit=20

这个 audit.enable 用于打开记录器(默认为关闭)。这个 audit.path 将在其中创建日志文件的目录。这个 audit.roll_limit 是在滚动发生之前登录到文件中的请求数。文件也会在每天开始时自动滚动。

在具有共享数据目录的群集安装中,每个节点的审核路径需要不同。在这种情况下,可以使用JVM系统变量指定审计路径,将以下内容添加到JVM启动选项中,它将覆盖 monitor.properties

-dgeoserver_audit_path=/path/to/the/logs/directory

日志文件

日志目录将包含以下多个日志文件 geoserver_audit_yyyymmdd_nn.log 模式。这个 nn 在每卷文件中增加。日志目录的内容如下:

geoserver_audit_20110811_2.log
geoserver_audit_20110811_3.log
geoserver_audit_20110811_4.log
geoserver_audit_20110811_5.log
geoserver_audit_20110811_6.log
geoserver_audit_20110811_7.log
geoserver_audit_20110811_8.log

默认情况下,每个日志文件内容都是一个XML文档,如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<Requests>
        <Request id="168">
           <Service>WMS</Service>
           <Version>1.1.1</Version>
           <Operation>GetMap</Operation>
           <SubOperation></SubOperation>
           <Resources>GeoSolutions:elba-deparea</Resources>
           <ResourcesProcessingTime>4</ResourcesProcessingTime>
           <LabelsProcessingTime>0</LabelsProcessingTime>
           <Path>/GeoSolutions/wms</Path>
           <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>
           <HttpMethod>GET</HttpMethod>
           <StartTime>2011-08-11T20:19:28.277Z</StartTime>
           <EndTime>2011-08-11T20:19:28.29Z</EndTime>
           <TotalTime>13</TotalTime>
           <RemoteAddr>192.168.1.5</RemoteAddr>
           <RemoteHost>192.168.1.5</RemoteHost>
           <Host>demo1.geo-solutions.it</Host>
           <RemoteUser>admin</RemoteUser>
           <ResponseStatus>200</ResponseStatus>
           <ResponseLength>1670</ResponseLength>
           <ResponseContentType>image/png</ResponseContentType>
           <Failed>false</Failed>
        </Request>
        ...
</Requests>

自定义日志内容

日志内容由三个FreeMarker模板驱动。

header.ftl 在创建新日志文件以形成文件的前几行时使用一次。默认头模板为:

<?xml version="1.0" encoding="UTF-8" ?>
<Requests>

content.ftl 用于写出请求的详细信息。默认模板转储有关请求的所有已知字段:

<#escape x as x?xml>
<Request id="${id!""}">
   <Service>${service!""}</Service>
   <Version>${owsVersion!""}</Version>
   <Operation>${operation!""}</Operation>
   <SubOperation>${subOperation!""}</SubOperation>
   <Resources>${resourcesList!""}</Resources>
   <ResourcesProcessingTime>${resourcesProcessingTimeList!""}</ResourcesProcessingTime>
   <LabelsProcessingTime>${labellingProcessingTime!""}</LabelsProcessingTime>
   <Path>${path!""}</Path>
   <QueryString>${queryString!""}</QueryString>
   <#if bodyAsString??>
   <Body>
   ${bodyAsString}
   </Body>
   </#if>
   <HttpMethod>${httpMethod!""}</HttpMethod>
   <StartTime>${startTime?datetime?iso_utc_ms}</StartTime>
   <EndTime>${endTime?datetime?iso_utc_ms}</EndTime>
   <TotalTime>${totalTime}</TotalTime>
   <RemoteAddr>${remoteAddr!""}</RemoteAddr>
   <RemoteHost>${remoteHost!""}</RemoteHost>
   <Host>${host}</Host>
   <RemoteUser>${remoteUser!""}</RemoteUser>
   <ResponseStatus>${responseStatus!""}</ResponseStatus>
   <ResponseLength>${responseLength?c}</ResponseLength>
   <ResponseContentType>${responseContentType!""}</ResponseContentType>
   <CacheResult>${cacheResult!""}</CacheResult>
   <MissReason>${missReason!""}</MissReason>
   <#if error??>
   <Failed>true</Failed>
   <ErrorMessage>${errorMessage!""}</ErrorMessage>
   <#else>
   <Failed>false</Failed>
   </#if>
</Request>
</#escape>

footer.ftl 只在关闭日志文件以生成文件的最后几行时执行一次。默认页脚模板为:

</Requests>

管理员可以免费提供备用模板,它们可以与 monitor.properties ,具有与上面相同的名称。GeoServer将自动接收它们。