我们正在运行安装了 NewRelic Java 代理的 Elasticsearch。我们希望在不更改 ES 中的任何内容的情况下记录自定义指标。
我知道 NewRelic 建议的方法是 Steven Eksteens Elasticsearch Plugin,但它是基于 Ruby 的,我们尽量避免在我们的堆栈中添加另一种语言。我尝试使用 NewRelic Python 代理和 newrelic.agent.record_custom_metric 函数在 Python 中复制 Stevens 的工作:
import newrelic.agent
from time import sleep
import logging
logger = logging.getLogger()
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
# generate config file with 'newrelic-admin generate-config <apicode> newrelic.ini'
newrelic.agent.initialize('newrelic.ini')
application_str = dict(newrelic.agent.newrelic.core.config.global_settings())["app_name"]
application = newrelic.agent.register_application(application_str)
while True:
newrelic.agent.record_custom_metric('Custom/Value', 1, application)
sleep(10)
这工作正常。唯一的问题:如果配置为使用与现有 java-agent 控制的 App 相同的 app_name,它会在 NewRelic 中注册一个带有附录“(Python)”的新应用程序。我想要的是将指标添加到原始指标中。这可能吗?