Skip to content

Match Hashed Config

Florian Forster edited this page Nov 26, 2023 · 1 revision
Clone this wiki locally

This page contains some example configurations for the Hashed match. This page is meant as a cookbook, so if you have a configuration for an aspect not handled here please feel free to add anything that's useful for you.

Multiple Graphite servers

This exmaple assumed that you have multiple Graphite servers and you want to distribute the load evenly over these. The instance of collectd should receive metrics via the Network plugin and write them with Write Graphite plugin. It is meant as a complete example to show all that is necessary to use this match successfully.

 # Configure logging. This should always be done first.
 LoadPlugin logfile
 <Plugin logfile>
   LogLevel info
   File "/var/log/collectd.log"
   Timestamp true
   PrintSeverity true
 </Plugin>

 # Set up the three connections to graphite.
 LoadPlugin write_graphite
 <Plugin write_graphite>
   <Node "server0">
     Host "graphite0.example.com"
     Prefix "collectd."
     StoreRates true
   </Node>
   <Node "server1">
     Host "graphite1.example.com"
     Prefix "collectd."
     StoreRates true
   </Node>
   <Node "server2">
     Host "graphite2.example.com"
     Prefix "collectd."
     StoreRates true
   </Node>
 </Plugin>

 # Set up the receiving part.
 LoadPlugin network
 <Plugin network>
   # Listen on all interfaces.
   Listen "::"
   # statistics about the network plugin itself
   ReportStats true
 </Plugin>

 LoadPlugin match_hashed
 <Chain "PostCache">
   # Rule #0: Send 1/3 of values to server0.
   <Rule>
     <Match hashed>
       Match 0 3
     </Match>
     <Target write>
       Plugin "write_graphite/server0"
     </Target>
     Target stop
   </Rule>
   # Rule #1: Send 1/3 of values to server1.
   <Rule>
     <Match hashed>
       Match 1 3
     </Match>
     <Target write>
       Plugin "write_graphite/server1"
     </Target>
     Target stop
   </Rule>
   # Rule #2: Send 1/3 of values to server2.
   <Rule>
     <Match hashed>
       Match 2 3
     </Match>
     <Target write>
       Plugin "write_graphite/server2"
     </Target>
     Target stop
   </Rule>
 </Chain>