API Reference

class flask_graphite.FlaskGraphite(app=None)[source]

Register a list of hooks meant to monitor a flask application

The configuration is read from the namespace FLASK_GRAPHITE_ of the application configuration.

The main options are:
  • FLASK_GRAPHITE_HOST: The Carbon host to send metrics
  • FLASK_GRAPHITE_PORT: The Carbon port to send metrics

You can read Configuring Flask-Graphite to learn about the other option configurations.

Parameters:app – The application to monitor
init_app(app)[source]

Read config and set the hooks in place to monitor the application

Parameters:app – The application to monitor
class flask_graphite.MetricHook(function, type='after_request')[source]

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
is_setup_hook

Property to test if a hook is a setup hook

register_into(obj)[source]

Register the hook as a request hook in obj

Can only be used on setup hooks. Bind the hook to a client for other types of hooks.

Parameters:
  • obj – Either an application or a blueprint
  • client – The client to use with this hook for this application
setup(function)[source]

Mark a function as a setup hook for this hook

A setup hook is a hook required to run before its main hook. It’s implemented as a before_request hook.

Parameters:function – The function used as setup hook
class flask_graphite.hooks.MetricHook(function, type='after_request')[source]

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
is_setup_hook

Property to test if a hook is a setup hook

register_into(obj)[source]

Register the hook as a request hook in obj

Can only be used on setup hooks. Bind the hook to a client for other types of hooks.

Parameters:
  • obj – Either an application or a blueprint
  • client – The client to use with this hook for this application
setup(function)[source]

Mark a function as a setup hook for this hook

A setup hook is a hook required to run before its main hook. It’s implemented as a before_request hook.

Parameters:function – The function used as setup hook
flask_graphite.request_hooks.request_count(response)

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.request_hooks.request_status_code(response)

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.request_hooks.request_status_type(response)

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.request_hooks.request_processing_time(response)

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.request_hooks.set_start_time()

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.request_hooks.response_size(response)

Represent a hook for flask requests

This hook decorates a function to make it a suitable Flask hook.

The function must return a 2-tuple which represents a metric name and it’s value.

Parameters:
  • function – The function used as hook
  • type – The type of hook (before_request, after_request or teardown_request)
flask_graphite.utils.get_request_metric_prefix()[source]

Turn the URI of the current request into a metric

Warning

You must be inside a Flask request context to call this function.