Before moving ahead, read the following articles in the order presented to create a counter expert and policy (the examples will be used in this article):
Policy logging is the recording of the results of policy evaluation. A policy is evaluated every time the facts it uses changes.
We will add logging to the example policy created in the article, Creating a simple policy. This will log to a MySQL instance. If you are using a different database, change the settings below accordingly.
- Locate your policy. If you have closed it, navigate to your CEP Server > Policy_Managers > My_Policy_Manager > Policies. Right-click on Results and select Open.
- Stop the policy by clicking on the Stop icon . It will change to a start icon and the policy will stop and all indicators will change to gray.
- Right-click on Counter_Policy (at the very top) and select Properties or click on the Properties icon on the tool bar. The properties display will be presented. Select the Logging tab. While you can turn on and off logging at each sensor, you setup the database and table at the main policy level. The screen below is how this will be displayed by default.
Complete the fields as shown.
- Uncheck Exception based logging only
- Check Log sensor status to database
- Database: Select the database you are using
- Database server: Localhost:3306
- Database name: nastel_portal
- Database table: counter
- Database user ID: mysql_user
- Database password: nastel
Click Create Table when finished. A message similar to the below will display.
Click Apply to save the changes.
- Click Minutes_to_Complete on the left pane.
- Un-check Exception based logging only. If this option is checked, only exceptions are logged (warn, error, etc.). When unchecked, all.
- Check Log sensor status to database.
Leave all other settings as is - they are automatically copied from the base settings. Click Apply to save the changes. Close the Properties dialog window.
- Save the policy and then restart it. The policy will now log all evaluations to the database and table indicated above. To see the values, we will use one of the charting applications.
- There are three graph options in the Enterprise Manager for policies.
- Graphs which can be customized and updated automatically each time the sensor is updated or manually for historical data for each
- Charts which automatically update each second
- RealView charts which provide a spreadsheet view
For this section, we want to view historical data which is presented with graphs, click on the icon shown.
- The chart view will open at the bottom of the page. It should look like the one below. If Minutes_to_Complete is not shown on the chart, click on it and then on the Add icon on the graph.
- When Real time is selected, the chart will update each time the sensor is updated (every 3 seconds for this example). To switch to historical data (that is being recorded in the database), select History instead. You can also specify the History Period and end point (default is up to current time). In this example, it is 10 minutes, but this can also be set to hours or days depending on how much data is stored in the database.
- When completed, press the Update button. This will update the chart as shown below, depending on the amount of data that has been collected. In this case, the data is shown as constantly increasing, which is what the counter and our sensor are doing.