3.8. Example configurations

The following section contains some example configurations. The first three examples show examples of the three data-flows: on-demand, polling and event monitoring. The fourth example shows a more complicated example, which includes all three monitoring flows.

For simplicity, all examples are presented as a single file. This file could be /etc/monami.conf, or (with the default configuration) some file within the /etc/monami.d/ directory. With complex configuration, the monitoring targets, reporting targets, and sample or dispatch targets may be in separate files (as described in Section 3.2.3, “Auxiliary configuration file directories”). However the configuration is split between files, provided the targets are defined the examples will work.

3.8.1. On-demand monitoring example

This example shows how to configure MonAMI to monitor multiple targets: a local MySQL database, a local and remote Apache webservers with KSysGuard. The sample acts as an aggregator, allowing KSysGuard to see all three monitoring targets.

The results are cached for ten seconds by the sample target. This prevents the KSysGuard target from sampling too fast, whilst allowing other (undefined, here) monitoring activity to continue at faster rates.

# Our local MySQL instance
[mysql]
 user = monami
 password = monami-secret

# Our local Apache server
[apache]
 name = apache-test

# A remote Apache server
[apache]
 name = apache-public
 host = www.example.com

# Put together monitoring targets for ksysguard.
[sample]
 name = ksysguard-sample
 read = apache-test, apache-public, mysql
 cache = 10

[ksysguard]
 read = ksysguard-sample

3.8.2. Polling monitoring example

The following example configuration has MonAMI recording the Apache server's thread usage and a couple of MySQL parameters. The results are sent to Ganglia for recording and plotting. The Apache and MySQL monitoring occur at different rates (30 seconds and 1 minute respectively).

# Our local apache server
[apache]

# Our database
[mysql]
 user = monami
 password = monami-secret

# Every 30 seconds, send current thread usage to our internal
# ganglia.
[sample]
 interval = 30
 read = apache.Threads
 write = internal-ganglia

# Every minute, send some basic DB usage stats
[sample]
 interval = 1m
 read = mysql.Network.Connections.current, \
        mysql.Execution.Open.tables.current
 write = internal-ganglia

# Ganglia, making sure we send data to an internally connected NIC.
[ganglia]
 name = internal-ganglia
 multicast_if = eth1

3.8.3. Event monitoring example

The following example shows event-based monitoring. The apache target is configured to watch the access log file, which contains a log of accesses to the “public” virtual host.

The dispatch subscribes to those transfer requests that result in a HTTP 404 error code (“file not found”). Of the available datatree, only the referrer and user-agent are selected for forwarding to the public-404-logfile filelog target.

# Our local apache server
[apache]
  log = public_access : /var/log/apache/public/access.log [combined]

# Subscribe to those 404 events, sending them to the filelog
[dispatch]
  subscribe = apache.public_access.4xx.404
  select = referrer, user-agent
  send = public-404-logfile

#  Log these results.
[filelog]
  name = public-404-logfile
  filename = /var/log/apache/public/404.log

3.8.4. A more complex example

The following example combines all three previous monitoring flows in a single configuration file. Graphs of Apache thread usage and MySQL database statistics are produced with Ganglia, HTTP requests that result in a 404 error code are recorded and KSysGuard can connect to MonAMI (whenever the user decides) allowing more detailed monitoring either of the Apache or MySQL services.

Although this example groups similar sections together, this is mainly for readability: the order in which the targets are defined does not matter, and may be split over several files (see Section 3.2.3, “Auxiliary configuration file directories”).

##
##  Reader targets: sources of information.
##

[mysql]
  user     =  monami
  password =  monami-secret

[apache]
  log = public_access : /var/log/apache/public/access.log [combined]


##
##   Samples
##

# Every 30 seconds, send current thread usage to our ganglia.
[sample]
 interval = 30
 read = apache.Threads
 write = ganglia

# Every minute, send some basic DB usage stats
[sample]
 interval = 1m
 read = mysql.Network.Connections.current, \
        mysql.Execution.Open.tables.current
 write = ganglia

# Put together monitoring targets for ksysguard.
[sample]
 name = ksysguard-sample
 read = apache, mysql
 cache = 10


##
##    Dispatches: directing events to writer targets.
##

# Subscribe to those 404 events, sending them to the filelog
[dispatch]
  subscribe = apache.public_access.4xx.404
  select = referrer, user-agent
  send = public-404-logfile


##
##    Writer targets: those that accept data.
##

# Log for any 404s
[filelog]
  name = public-404-logfile
  filename = /var/log/apache/public/404.log

# Listen for ksysguard requests for data.
[ksysguard]
 read = ksysguard-sample

# Ganglia, making sure we send data to an internally connected NIC.
[ganglia]
 name = internal-ganglia
 multicast_if = eth1