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 Name | Type | Description |
---|---|---|
function.invocations | Counter | Count number of Lambda invocations |
function.cold_starts | Counter | Count number of cold starts |
function.errors | Counter | Count number of errors from underlying Lambda handler |
function.duration | Gauge | Milliseconds in execution time of underlying Lambda handler |
lambda包装器将以下维度添加到发送的所有数据点 发送到SignalFX:
Dimension | Description |
---|---|
lambda_arn | ARN of the Lambda function instance |
aws_region | AWS Region |
aws_account_id | AWS Account ID |
aws_function_name | AWS Function Name |
aws_function_version | AWS Function Version |
aws_function_qualifier | AWS Function Version Qualifier (version or version alias if it is not an event source mapping Lambda invocation) |
event_source_mappings | AWS Function Name (if it is an event source mapping Lambda invocation) |
aws_execution_env | AWS execution environment (e.g. AWS_Lambda_python3.6) |
function_wrapper_version | SignalFx function wrapper qualifier (e.g. signalfx_lambda_0.0.2) |
metric_source | The literal value of ‘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