signalfx lambda python包装器

signalfx-lambda的Python项目详细描述


signalfx python lambda包装器。

用法

signalfx python lambda包装器是aws lambda的包装器 python函数处理程序,用于检测函数的执行 向SignalFX发送度量和跟踪。

安装

从pypi安装

$ pip install signalfx_lambda

配置摄取端点

默认情况下,此函数包装器将发送到us0域。如果你是 不在此领域中,您将需要设置signalfx_inserte_endpoint环境 变量设置为正确的领域接收终结点(https://ingest.{realm}.signalfx.com)。 要确定您所处的领域,请检查SignalFX中的配置文件页 Web应用程序(单击右上角的虚拟形象,然后单击我的个人资料)。

环境变量

注意:环境变量signalfx_insert_endpoint和signalfx_auth_token已被弃用,在将来的版本中将不受支持。

SIGNALFX_ACCESS_TOKEN=access token

# endpoint for both metrics and tracer. Overridden by SIGNALFX_METRICS_URL
# and SIGNALFX_TRACING_URL if set
SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080

# optional metrics and tracing configuration

SIGNALFX_METRICS_URL=ingest endpoint [ default: https://pops.signalfx.com ]
SIGNALFX_SEND_TIMEOUT=timeout in seconds for sending datapoint [ default: 0.3 ]

SIGNALFX_TRACING_URL=tracing endpoint [ default: https://ingest.signalfx.com/v1/trace ]

signalfx_endpoint_url可用于为度量和 跟踪,使用智能网关转发时也是如此。路径/v1/traces 将自动添加到跟踪的终结点。

如果设置了signalfx_tracing_url或signalfx_metrics_url,它们将采用 在signalfx_endpoint_url上对其各自组件的优先级。

例如,如果只设置了signalfx_endpoint_url:

SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080

度量和跟踪都将发送到网关地址。

如果设置了signalfx_endpoint_url和signalfx_metrics_url:

SIGNALFX_METRICS_URL=https://pops.signalfx.com

SIGNALFX_ENDPOINT_URL=http://<my_gateway>:8080

跟踪将发送到网关,度量将通过POP。

包装函数

提供了两个包装。

对于度量,请使用@signalfx_lambda.emits_metrics装饰处理程序

import signalfx_lambda

@signalfx_lambda.emits_metrics
def handler(event, context):
    # your code

对于跟踪,请使用@signalfx_lambda.is_traced decorator

import signalfx_lambda

@signalfx_lambda.is_traced
def handler(event, context):
    # your code

装饰器可以单独使用,也可以一起使用。

度量包装器发送的度量和维度

lambda包装器向signalfx发送以下指标:

Metric NameTypeDescription
function.invocationsCounterCount number of Lambda invocations
function.cold_startsCounterCount number of cold starts
function.errorsCounterCount number of errors from underlying Lambda handler
function.durationGaugeMilliseconds in execution time of underlying Lambda handler

lambda包装器将以下维度添加到发送的所有数据点 发送到SignalFX:

DimensionDescription
lambda_arnARN of the Lambda function instance
aws_regionAWS Region
aws_account_idAWS Account ID
aws_function_nameAWS Function Name
aws_function_versionAWS Function Version
aws_function_qualifierAWS Function Version Qualifier (version or version alias if it is not an event source mapping Lambda invocation)
event_source_mappingsAWS Function Name (if it is an event source mapping Lambda invocation)
aws_execution_envAWS execution environment (e.g. AWS_Lambda_python3.6)
function_wrapper_versionSignalFx function wrapper qualifier (e.g. signalfx_lambda_0.0.2)
metric_sourceThe literal value of ‘lambda_wrapper’

跟踪包装器发送的跟踪和标记

跟踪包装器为包装器处理程序创建一个范围。此范围有以下标记:

TagDescription
aws_request_idAWS Request ID
lambda_arnARN of the Lambda function instance
aws_regionAWS Region
aws_account_idAWS Account ID
aws_function_nameAWS Function Name
aws_function_versionAWS Function Version
aws_function_qualifierAWS Function Version Qualifier (version or version alias if it is not an event source mapping Lambda invocation)
event_source_mappingsAWS Function Name (if it is an event source mapping Lambda invocation)
aws_execution_envAWS execution environment (e.g. AWS_Lambda_python3.6)
function_wrapper_versionSignalFx function wrapper qualifier (e.g. signalfx_lambda_0.0.2)
componentThe literal value of ‘python-lambda-wrapper’

从lambda函数发送自定义度量

import signalfx_lambda

# sending application_performance metric with value 100 and dimension abc:def
signalfx_lambda.send_gauge('application_performance', 100, {'abc':'def'})

# sending counter metric with no dimension
signalfx_lambda.send_counter('database_calls', 1)

向lambda函数添加手动跟踪

可以添加手动检测来跟踪处理程序的关键部分 功能。

import opentracing

tracer = opentracing.tracer

def some_function():
    with tracer.start_active_span("span_name", tags=tags) as scope:

        # do some work

        span = scope.span
        span.set_tag("example_tag", "example_value")

更多示例和使用信息可以在jaeger python tracer中找到 documentation

在本地测试

使用python lambda local

pip install python-lambda-local
python-lambda-local tests/test.py tests/event.json -a 'arn:aws:lambda:us-east-1:accountId:function:functionNamePython:$LATEST'

包装

python setup.py bdist_wheel --universal

许可证

apache软件许可证v2。版权所有©2014-2019 SignalFX

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java错误:无法找到或加载主类   Base85又名ASCI85 java项目   在Java oracle过程中创建Clob对象时引发AbstractMethodError   访问布尔Java时出现NullPointerException   在Java中压缩和解压缩字符串的调试程序   java了解JavaMail下未读消息的不同方法   java Vaadin 10网格样式基于内容的单个行   java使用Sparql查询识别实体的类别/分类   java如何在组件的设计阶段防止内存泄漏?   java使用共享首选项在应用程序上保存更改的语言   Spring数据jpa中具有复合PK的表的java本机查询   java复选框节点树