Skip to content

Instantly share code, notes, and snippets.

@remh
Last active January 12, 2021 06:13
Show Gist options
  • Save remh/86fda072722a6c9d23fffa8d6682b21b to your computer and use it in GitHub Desktop.
Save remh/86fda072722a6c9d23fffa8d6682b21b to your computer and use it in GitHub Desktop.
Feeding Datadog With Graphite

Deprecation notice

This method is deprecated, please reach out to the Datadog Support team if you have any questions.


Datadog can ingest Graphite data in real-time. dd-agent understands the relay graphite protocol and can be configured to accept connections from carbon-relay.

Disclaimer

Please note, the Graphite sink is intended to be used as a proof-of-concept to help users have an understanding of what their data looks like within Datadog, it's not intended to be used in production or at scale today. Currently, the Graphite sink is only capable of ingesting a limited number of metrics.

Furthermore, using the Graphite sink removes multiple benefits of Datadog such as our Integrations, agent resilience and tagging amongst other things. We strongly suggest reviewing the Datadog Agent coupled with DogStatsD in favor of longtime use of the Graphite sink.'

Step-by-step

  1. Install dd-agent version 2.2.1 or later. Detailed instructions are available here.
  2. Update /etc/dd-agent/datadog.conf and enable the graphite listener
[Main]
# ...
# ...
# Start a graphite listener on this port
graphite_listen_port: 17124
# ...
  1. Restart dd-agent
  2. Update relay-rules.conf to send part all your metrics to dd-agent. Assuming the agent runs on the same hosts as the carbon-relay daemon:
# You must have exactly one section with 'default = true'
[default]
default = true
destinations = 127.0.0.1:17124

If you already use carbon-relay, refer to the documentation for more details. 5. Update the relay section of carbon.conf

[relay]
...
destinations = 127.0.0.1:17124
  1. Restart carbon-relay and carbon-cache

If you run on Ubuntu and don't have graphite installed, you can follow these steps to get started.

Sending a Subset of Graphite Metrics to Datadog

If you only don't want all your graphite metrics to be sent to Datadog, you can easily tweak relay-rules.conf to that effect. In this example let us assume that you only want to send metrics that contain the word public.

[datadog]
pattern = ^.*public\..+
# dd-agent listens on port 17124
servers = 127.0.0.1:17124

[default]
default = true
destinations = my_carbon_cache:2004:a

Using graphite data in Datadog

Out of the Box

All graphite metrics will be transposed as-is into Datadog. Because graphite does not provide any metadata regarding the scope of the metric (e.g. where the data were captured), dd-agent will attach all the metrics to the host where it runs.

In other words if graphite captures a metric called my.graphite.metric.ABC.count and dd-agent runs on host GHI, you can get that metric on a Datadog graph defined by:

{
  "requests": [
    {
      "q": "my.graphite.metric.ABC.count{host:GHI}"
    }
  ],
  "events": [
    {
      "q": "events{host:ABC}"
    }
  ]
}

Note: in this scheme, the free-form aggregation of graphite are not available via Datadog. This can be an issue if other metrics of interest are attached to the ABC host, instead of GHI.

Adding Metadata to the Graphite feed

If the out-of-the-box behavior is not suitable for your application, you have the option to extract metadata from the graphite metric name on-the-fly before they are submitted to Datadog.

To do so, as of this writing, you need to write your own metric mapper. You can easily do that by updating graphite.py.

Using the example above, if you want to actually attach the metric to the host ABC you can update graphite.py's _parseMetric with the following code:

    def _parseMetric(self, metric):
        """Graphite does not impose a particular metric structure.
        So this is where you can insert logic to extract various bits
        out of the graphite metric name.

        For instance, if the hostname is in 4th position,
        you could use: host = components[3]
        """
    
        try:
            components = metric.split('.')

            host = self.hostname
            metric = metric

            # Special treatment for my.graphite.metric
            if metric.startswith("my.graphite.metric"):
                # host is in 3rd position
                host = components.pop(3)
                # Remove the host name from the metric
                metric = ".".join(components)

            device = "N/A"
    
            return metric, host, device
        except Exception, e:
            logging.exception("Unparsable metric: {0}".format(metric))
            return None, None, None

Once you have restarted the agent you can then graph the metric with the proper host:

{
  "requests": [
    {
      "q": "my.graphite.metric.count{host:ABC}"
    }
  ],
  "events": [
    {
      "q": "events{host:ABC}"
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment