Configuring the monitoring extension

In the previous recipe, we started to explore the monitoring extension. You managed to store information for some requests and created a chart showing the proportion of each operation for WMS.

We haven discussed yet where the information is stored. After viewing the chart, try to restart GeoServer and then open the reports section again. You'll be surprised that this time no data is shown; all the information previously collected is gone.

This happens because, by default, the monitoring extension uses the memory as a data repository, so information vanishes each time you restart GeoServer.

In this recipe, we'll configure a more robust approach for information storage, which is especially helpful if you need to save information over a wide range of time.

Getting ready

In this recipe, we're going to store information in an RDBMS. The monitoring extension supports different software, such as H2, PostgreSQL, or Oracle ™.

We'll use PostgreSQL, a powerful and open source software, which, with its extension PostGIS, is the most famous open spatial database. The installation is very easy; for Linux distro, the easiest way is to use binary packages from the official repository. On Debian-like distributions, you can use the apt package manager:

$ sudo apt-get install postgresql-9.1

This way you'll have the recent release up and running in a few seconds.

For Windows, a good choice is to download the binary package by Enterprise DB:

http://www.enterprisedb.com/products-services-training/pgdownload#windows

How to do it…

  1. Stop GeoServer.
  2. Open the db.properties file with a text editor and change its content. Comment the section for H2 and uncomment the PostgreSQL configuration. Please verify your settings and change the properties accordingly:
    driver=org.postgresql.Driver
    url=jdbc:postgresql://localhost:5432/gisdata
    username=gisuser
    password=gisuser
    defaultAutoCommit=false
  3. Save the file and open the hibernate.properties file located in the same folder. You need to change only the following two properties:
    # PostgreSQL dialect
    databasePlatform=org.hibernate.dialect.PostgreSQLDialect
    database=POSTGRESQL
  4. Open the monitor.properties file and change the storage settings to include the extension using the DB:
    storage=hibernate
  5. Restart GeoServer to have your configuration reloaded. After it starts, you can check that inside the PostgreSQL database, there are two new tables:
    $ psql –U gisuser –d gisdata
    gisdata=> dt req*
                  List of relations
     Schema |       Name        | Type  |  Owner
    --------+-------------------+-------+---------
     public | request           | table | gisuser
     public | request_resources | table | gisuser
    
  6. Open the GeoServer web interface and go to the Layer preview section. Open the OpenLayers preview for some of the configured layers and browse the maps by panning and zooming.
  7. After a while, turn back to the GeoServer web interface and go to the Monitor section. Open the Activity link, click on the Daily tab and you should see a graph showing the request number over time, as shown in the How to do it… section of the previous recipe.
  8. Connect to the database and check for records stored in the two new tables:
    gisdata=> select count(*) from request;
     count
    -------
        45
    gisdata=> select status, http_method, service, operation from request limit 5;
      status  | http_method | service | operation
    ----------+-------------+---------+-----------
     FINISHED | GET         | WMS     | GetMap
     FINISHED | GET         | WMS     | GetMap
     FINISHED | GET         | WMS     | GetMap
     FINISHED | GET         | WMS     | GetMap
     FINISHED | GET         | WMS     | GetMap
    

How it works…

Using an RDBMS is a robust way to persist information safely. An RDBMS is also a very flexible tool to retrieve information and elaborate it in order to prepare usage reports.

The monitoring extension configuration is based on four properties files. The one called monitor.properties holds the general settings.

The mode parameter sets how the information is collected and updated. By default, it is in the history mode, that is, information is stored after the request completion. The live mode makes GeoServer collect information in real time. In this mode, you can also use a real-time monitor from the GeoServer web interface.

The storage property controls where the monitoring information is stored. It can assume two values: memory, which is the default value, and hibernate.

We selected the hibernate mode, and hence GeoServer will search for a database acting as a repository. To connect to the database, more parameters are required. They are contained in the hibernate.properties and db.properties files. GeoServer reads them and uses the contained information to connect to the RDBMS and store information inside it.

Note

Hibernate is a Java ™ library to map objects contained in a relational database, such as PostgreSQL or Oracle, to an object-oriented model such as the one used by GeoServer internally.

It is widely used and you may find a lot of detailed information about it.

A good starting point is http://hibernate.org/.

In the first file, we instruct hibernate on what kind of database we're using, shown as follows:

# hibernate dialect
databasePlatform=org.hibernate.dialect.PostgreSQLDialect
database=POSTGRESQL

In the latter, we insert the connection parameters as follows:

# sample configuration for postgres
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/gisdata
username=gisuser
password=gisuser
defaultAutoCommit=false

We changed the default H2 database to PostgreSQL; you're already using it as a spatial repository for your data and it is a very powerful piece of software. It is also very interoperable with many reporting tools.

If your organization uses Oracle, you may as well be use it to monitor information storage. In hibernate.properties, insert the following code snippet:

# hibernate dialect
databasePlatform=org.hibernate.dialect.OracleDialect
database=ORACLE

Then, insert the following code snippet in the db.properties file:

driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:ORCL
username=gisuser
password=gisuser

Obviously, whatever RDBMS flavor you're using, the information stored is the same. You probably noted the crs field in the request table. Along with the minx, miny, maxx, and maxy fields, it records the envelope for each request:

gisdata=> select crs, round(minx::numeric,2) as minx, round(miny::numeric,2) as miny, round(maxx::numeric,2) as maxx, round(maxy::numeric,2) as maxy from request where crs is not null;
    crs    |     minx    |    miny    |    maxx    |     maxy   
-----------+-------------+------------+------------+------------
 EPSG:4326 |     -180.00 |     -90.00 |     180.00 |       90.00
 EPSG:4326 |      -17.84 |      28.48 |      40.17 |       57.48
 EPSG:4326 |       -4.09 |      36.12 |      24.92 |       50.63
 EPSG:4326 |        2.79 |      39.95 |      17.29 |       47.20

In the monitor.properties file, you can set the CRS used to log the envelopes, by default, WGS84 Lat Long, which is EPSG:4326. You may change it to another one, of course, being careful to select one that makes sense to all your data extent.

This is the output of requests to the NaturalEarth:blueMarble layer after changing the setting to EPSG:3857 in the monitor.properties file:

gisdata=> select crs, round(minx::numeric,2) as minx, round(miny::numeric,2) as miny, round(maxx::numeric,2) as maxx, round(maxy::numeric,2) as maxy from request where crs is not null;
    crs    |     minx    |    miny    |    maxx    |     maxy   
-----------+-------------+------------+------------+-------------
 EPSG:3857 | -5126784.36 | 1967710.95 | 7788015.94 | 13111054.46
 EPSG:3857 | -1966571.86 | 3704742.20 | 4490828.29 |  8524724.33
 EPSG:3857 |  -381573.65 | 4668514.96 | 2847126.43 |  7007058.96
 EPSG:3857 |  -381573.65 | 4668514.96 | 2847126.43 |  7007058.96

The last configuration file, filter.properties, controls what requests are monitored. By default, it contains some filters to avoid monitoring some requests:

/rest/monitor/**
/web
/web/**

All requests forwarded to the GeoServer web interface and the Monitor REST API are not collected. According to your needs, you can add more filters.

The syntax is quite simple to manage; you have to specify the complete URL after /geoserver and before the key pair values.

For instance, if you want to filter out all requests to a namespace, you can use a filter such as the following one:

NaturalEarth/ows

Now, WMS, WCS, and WFS requests such as the following will be ignored by the monitoring module, but obviously they will be processed by GeoServer:

http://localhost/geoserver/NaturalEarth/ows?service=WCS&version=1.0.0&request=DescribeCoverage&coverage=NaturalEarth:dem
http://localhost/geoserver/NaturalEarth/ows?service=WCS&version=1.0.0&request=GetCoverage&coverage=NaturalEarth:dem&crs= EPSG:4326&bbox=12.06,42.03,12.88,42.50&bands=1
http://localhost/geoserver/NaturalEarth/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=NaturalEarth:populatedplaces&bbox=-157.1484375,13.88671875,-41.1328125,71.89453125
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.83.151