Graphite Render API: Add custom functions for better metric formatting


(Michael Friedrich) #1

Author: @mfriedrich
Version: v0.1

Tested with:

  • Graphite 1.1.5 in Vagrant, requires #175


While reading a question about the Graphite web module integration and templates, I’ve found out that current versions of Graphite also allow to extend the Render API with custom functions.

This can be used to extend the Graphite API and use these functions from the web module’s templates.




Vagrant with Graphite

Take the Icinga Vagrant box “standalone” which provisions Graphite already.

git clone
cd icinga-vagrant/standalone
vagrant up

Inspect the Render API

Open Grafana and pick a metric from the dashboard. Then adopt this into a render API target like this:

Inspect existing Functions

Core function code is located in /opt/graphite/webapp/graphite/render/ and allows to understand the ideas, or copy something.


Custom Function to replace Underscores in Metric Names

Navigate into /opt/graphite/webapp/graphite/functions/custom and start your work.

vagrant ssh
sudo -i
cd /opt/graphite/webapp/graphite/functions/custom


from graphite.functions.params import Param, ParamTypes

def formatHostLegend(requestContext, seriesList):
        """Custom function that prints a pretty-fied legend name"""
        for series in seriesList:
                pos =".perfdata")
                first =[0:pos]
                second =[pos:]

       = first.replace('_', '.') + second

        return seriesList

# Define group = 'Custom'

# Define parameters for the callback
formatHostLegend.params = [
        Param('seriesList', ParamTypes.seriesList, required=True)

# Register the callback function
SeriesFunctions = {
        'formathostlegend': formatHostLegend

Restart Graphite Web / Apache

systemctl restart httpd

Verify the Function

Navigate to and search for the exported function.

Test the Function*checks.value)&title=count&width=1024&from=-1h

Your implementation?

Please share your custom functions and more with the Graphite Render API :slight_smile: