Up: Usage   [Contents][Index]


3.1 Pairing Actions with Metrics

Placing a call to openmetrics_incr before each action, as proposed above, is cumbersome and error-prone. To make sure metrics are increased upon executing each action, use the action mailfromd hook (see Mailfromd in Mailfromd Manual). For example:

prog action
do
  openmetrics_incr(milter_action_name($1))
done

This handler will be called before executing each action. Make sure to declare metric families for each mailfromd actions, like that:

prog startup
do
  openmetrics_declare("accept", openmetrics_counter, "Mails accepted")
  openmetrics_declare("continue", openmetrics_counter,
    "Flow continued to other handlers")
  openmetrics_declare("discard", openmetrics_counter, "Mails discarded")
  openmetrics_declare("reject", openmetrics_counter, "Mails rejected")
  openmetrics_declare("tempfail", openmetrics_counter, "Mails tempfailed")
  set openmetrics_safe 1
done

The action handler appeared in mailfromd version 8.16.90. If you run an earlier version, there is still a way to ensure that corresponding metrics are increased upon executing each action. This will require some preprocessor magic, though.

Define the following m4 macro:

m4_define(`ACTION',
 `openmetrics_incr("$1")
$1`'m4_ifelse(`$2',`',`',`(m4_shift($@))')')

Place this definition near the top of your mailfromd.mfl file and replace literal calls to milter actions with calls to this macro. For example, instead of

openmetrics_incr("accept")
accept

write just

ACTION(accept)

Similarly, instead of

openmetrics_incr("reject")
reject 550 5.1.0 "Sender validity not confirmed"

use

ACTION(reject, 550, 5.1.0, "Sender validity not confirmed")

This way calling an action will always increase the corresponding metric.