Skip to content

collectors ExampleCollector

Rob Smith edited this page Oct 29, 2012 · 25 revisions

ExampleCollector

An example collector that verifies the answer to life, the universe, and everything does not change.

Dependencies

  • A sane universe

Customizing a collector

Diamond collectors run within the diamond process and collect metrics that can be published to a graphite server.

Collectors are subclasses of diamond.collector.Collector. In their simplest form, they need to implement a single method called "collect".

import diamond.collector

class ExampleCollector(diamond.collector.Collector):

    def collect(self):
        # Set Metric Name
        metric_name = "my.example.metric"

        # Set Metric Value
        metric_value = 42

        # Publish Metric
        self.publish(metric_name, metric_value)

To run this collector in test mode you can invoke the diamond server with the -r option and specify the collector path.

diamond -f -v -r path/to/ExampleCollector.py -c conf/diamond.conf.example

Diamond supports dynamic addition of collectors. Its configured to scan for new collectors on a regular interval (configured in diamond.cfg). If diamond detects a new collector, or that a collectors module has changed (based on the file's mtime), it will be reloaded.

Diamond looks for collectors in /usr/lib/diamond/collectors/ (on Ubuntu). By default diamond will invoke the collect method every 60 seconds.

Diamond collectors that require a separate configuration file should place a .cfg file in /etc/diamond/collectors/. The configuration file name should match the name of the diamond collector class. For example, a collector called examplecollector.ExampleCollector could have its configuration file placed in /etc/diamond/collectors/ExampleCollector.cfg.

Options

  • Generic Options
  • enabled: Enable collecting these metrics
  • byte_unit: Default numeric output(s)

Example Output

servers.hostname.example.my.example.metric 42
Clone this wiki locally