Wraps a metric-data-generating data source.
The data source APIs provide a way to generate metrics using a pull-style API rather than the push-style API implemented by record_custom_metric. For more about why and how to use data sources for custom metrics, see Custom metric data sources.
data_source_generator decorator is used to wrap a simple metric-data-generating data source that directly returns an iterable/generator with the metrics for each sample. The function the decorator is applied to must take no arguments. This would be used where there is no need to retain state information between calls to generate any metrics, and where the one instance of the data source can be used against multiple applications.
Optional. The name of the data source. This is used only for logging purposes. If not provided, it defaults to the callable name derived from the decorated function.
Optional. Any additional properties to pass to the data source factory.
The possible fields for a dictionary are:
Returns a function.
An example of using
data_source_generator to wrap a function that returns metric values:
import psutilimport email@example.com_source_generator(name='Memory Usage')def memory_metrics():pid = os.getpid()p = psutil.Process(os.getpid())m = p.get_memory_info()yield ('Custom/Memory/Physical', float(m.rss)/(1024*1024))yield ('Custom/Memory/Virtual', float(m.vms)/(1024*1024))
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.