|
1 |
| -# wavefront-lambda-go [](https://travis-ci.com/wavefrontHQ/wavefront-lambda-go) |
| 1 | +# wavefront-lambda-go |
2 | 2 |
|
3 |
| -This is a Wavefront Go wrapper for AWS Lambda to enable reporting standard lambda metrics and custom app metrics directly to wavefront. |
| 3 | +[](https://travis-ci.com/wavefrontHQ/wavefront-lambda-go) |
| 4 | +[](https://goreportcard.com/report/github.com/wavefrontHQ/wavefront-lambda-go) |
4 | 5 |
|
5 |
| -## Requirements |
6 |
| -Go 1.x |
| 6 | +A Go wrapper for AWS Lambda so you can monitor everything from your [Wavefront](https://wavefront.com) dashboard |
7 | 7 |
|
8 | 8 | ## Installation
|
9 |
| -``` |
| 9 | + |
| 10 | +Using `go get` |
| 11 | + |
| 12 | +```bash |
10 | 13 | go get github.com/wavefronthq/wavefront-lambda-go
|
11 | 14 | ```
|
12 | 15 |
|
13 |
| -## Environment variables |
14 |
| -WAVEFRONT_URL = https://\<INSTANCE>.wavefront.com |
15 |
| -WAVEFRONT_API_TOKEN = Wavefront API token with Direct Data Ingestion permission. |
16 |
| -REPORT_STANDARD_METRICS = Set to False or false to not report standard lambda metrics directly to wavefront. |
| 16 | +## Basic Usage |
17 | 17 |
|
18 |
| -## Usage |
| 18 | +To connect your Lambda functions to Wavefront, you'll need to set two environment variables, import this module, and wrap your AWS Lambda handler function with `wflambda.Wrapper(handler)`. The environment variables you'll need to set are: |
19 | 19 |
|
20 |
| -Wrap your AWS Lambda handler function with wavefront_lambda.Wrapper(LambdaHandler). |
| 20 | +* `WAVEFRONT_URL`: The URL of your Wavefront instance (like, `https://myinstance.wavefront.com`). |
| 21 | +* `WAVEFRONT_API_TOKEN`: Your Wavefront API token (see the [docs](https://docs.wavefront.com/wavefront_api.html) how to create an API token). |
21 | 22 |
|
22 | 23 | ```go
|
23 | 24 | package main
|
24 | 25 |
|
25 | 26 | import (
|
| 27 | + "github.com/aws/aws-lambda-go/events" |
26 | 28 | "github.com/aws/aws-lambda-go/lambda"
|
27 |
| - "github.com/rcrowley/go-metrics" |
28 |
| - "github.com/wavefronthq/go-metrics-wavefront" |
29 |
| - "github.com/wavefronthq/wavefront-lambda-go" |
| 29 | + wflambda "github.com/wavefronthq/wavefront-lambda-go" // Import this library |
30 | 30 | )
|
31 | 31 |
|
32 |
| -// Lambda handler function that includes the code which will be executed when lambda is invoked. |
33 |
| -func HandleLambdaRequest() { |
34 |
| - // your code |
| 32 | +func handler() (string, error){ |
| 33 | + return "Hello World", nil |
35 | 34 | }
|
36 | 35 |
|
37 | 36 | func main() {
|
38 |
| - // Wrap your Lambda Handler Function with wflambda.Wrapper |
39 |
| - lambda.Start(wflambda.Wrapper(HandleLambdaRequest)) |
| 37 | + // Wrap the handler with wflambda.Wrapper() |
| 38 | + lambda.Start(wflambda.Wrapper(handler)) |
40 | 39 | }
|
41 | 40 | ```
|
42 | 41 |
|
43 |
| -## Standard Lambda Metrics reported by Wavefront Lambda wrapper |
| 42 | +## Standard Point Tags |
| 43 | + |
| 44 | +Point tags are key-value pairs (strings) that are associated with a point. Point tags provide additional context for your data and allow you to fine-tune your queries so the output shows just what you need. The below point tags are sent to Wavefront for each metric. |
44 | 45 |
|
45 |
| -The Lambda wrapper sends the following standard lambda metrics to wavefront: |
| 46 | +| Point Tag | Description | |
| 47 | +| --------------------- | ------------------------------------------------------------------------------------------ | |
| 48 | +| LambdaArn | ARN (**Amazon Resource Name**) of the Lambda function. | |
| 49 | +| Region | AWS Region of the Lambda function. | |
| 50 | +| accountId | AWS Account ID from which the Lambda function was invoked. | |
| 51 | +| ExecutedVersion | The version of Lambda function. | |
| 52 | +| FunctionName | The name of Lambda function. | |
| 53 | +| Resource | The name and version/alias of Lambda function. (like `DemoLambdaFunc:aliasProd`) | |
| 54 | +| EventSourceMappings | AWS Event source mapping Id. (Set in case of Lambda invocation by AWS Poll-Based Services) | |
46 | 55 |
|
47 |
| -| Metric Name | Type | Description | |
48 |
| -| ----------------------------------|:------------------:| ----------------------------------------------------------------------- | |
49 |
| -| aws.lambda.wf.invocations.count | Delta Counter | Count of number of lambda function invocations aggregated at the server.| |
50 |
| -| aws.lambda.wf.errors.count | Delta Counter | Count of number of errors aggregated at the server. | |
51 |
| -| aws.lambda.wf.coldstarts.count | Delta Counter | Count of number of cold starts aggregated at the server. | |
52 |
| -| aws.lambda.wf.duration.value | Gauge | Execution time of the Lambda handler function in milliseconds. | |
| 56 | +## Standard Metrics |
53 | 57 |
|
54 |
| -The Lambda wrapper adds the following point tags to all metrics sent to wavefront: |
| 58 | +Based on the environment variable `REPORT_STANDARD_METRICS` the wrapper will send standard metrics to Wavefront. Set the variable to to `false` to not send the standard metrics. When the variable is not set, it will use the default value `true`. |
55 | 59 |
|
56 |
| -| Point Tag | Description | |
57 |
| -| --------------------- | ----------------------------------------------------------------------------- | |
58 |
| -| LambdaArn | ARN(Amazon Resource Name) of the Lambda function. | |
59 |
| -| Region | AWS Region of the Lambda function. | |
60 |
| -| accountId | AWS Account ID from which the Lambda function was invoked. | |
61 |
| -| ExecutedVersion | The version of Lambda function. | |
62 |
| -| FunctionName | The name of Lambda function. | |
63 |
| -| Resource | The name and version/alias of Lambda function. (Ex: DemoLambdaFunc:aliasProd) | |
64 |
| -| EventSourceMappings | AWS Event source mapping Id. (Set in case of Lambda invocation by AWS Poll-Based Services)| |
| 60 | +| Metric Name | Type | Description | |
| 61 | +| --------------------------------- | ------------- | ----------------------------------------------------------------------- | |
| 62 | +| aws.lambda.wf.invocations.count | Delta Counter | Count of number of lambda function invocations aggregated at the server.| |
| 63 | +| aws.lambda.wf.errors.count | Delta Counter | Count of number of errors aggregated at the server. | |
| 64 | +| aws.lambda.wf.coldstarts.count | Delta Counter | Count of number of cold starts aggregated at the server. | |
| 65 | +| aws.lambda.wf.duration.value | Gauge | Execution time of the Lambda handler function in milliseconds. | |
65 | 66 |
|
66 |
| -## Custom Lambda Metrics |
| 67 | +## Custom Metrics |
67 | 68 |
|
68 |
| -The wavefront Go lambda wrapper reports custom business metrics via API's provided by the [go-metrics-wavefront client] (https://github.com/wavefrontHQ/go-metrics-wavefront). |
69 |
| -Please refer to the below code sample which shows how you can send custom business metrics to wavefront from your lambda function. |
| 69 | +You can send custom business metrics to Wavefront using the [go-metrics-wavefront](https://github.com/wavefrontHQ/go-metrics-wavefront) client. The below code reports a _counter_, a _delta counter_, and two _gauges_. All metric names should be unique. If you have metrics that you want to track as both _counter_ and _delta counter_, you'll have to add a suffix to one of the metrics. Having the same metric name for any two types of metrics will result in only one time series at the server and thus cause collisions. |
70 | 70 |
|
71 |
| -### Code Sample |
| 71 | +The code below imported this module and wrapped the _handler_ function argument in _main_ with `wflambda.Wrapper(handler)`. During each execution four metrics are collected and sent to Wavefront with both the [standard point tags](#standard-point-tags) and the point tags created in the handler. |
72 | 72 |
|
73 | 73 | ```go
|
74 | 74 | package main
|
75 | 75 |
|
76 | 76 | import (
|
77 | 77 | "github.com/aws/aws-lambda-go/lambda"
|
78 | 78 | "github.com/rcrowley/go-metrics"
|
79 |
| - "github.com/wavefronthq/go-metrics-wavefront" |
80 |
| - "github.com/wavefronthq/wavefront-lambda-go" |
| 79 | + wavefront "github.com/wavefronthq/go-metrics-wavefront" |
| 80 | + wflambda "github.com/wavefronthq/wavefront-lambda-go" |
81 | 81 | )
|
82 | 82 |
|
83 |
| -// Lambda handler function that includes the code which will be executed when lambda is invoked. |
84 |
| -func HandleLambdaRequest() { |
| 83 | +func handler() { |
85 | 84 | // Point Tags
|
86 | 85 | appTags := map[string]string{
|
87 | 86 | "key2": "val1",
|
@@ -114,10 +113,6 @@ func HandleLambdaRequest() {
|
114 | 113 | }
|
115 | 114 |
|
116 | 115 | func main() {
|
117 |
| - //Wrapping with wflambda.Wrapper |
118 |
| - lambda.Start(wflambda.Wrapper(HandleLambdaRequest)) |
| 116 | + lambda.Start(wflambda.Wrapper(handler)) |
119 | 117 | }
|
120 | 118 | ```
|
121 |
| - |
122 |
| -Note: Having the same metric name for any two types of metrics will result in only one time series at the server and thus cause collisions. |
123 |
| -In general, all metric names should be different. In case you have metrics that you want to track as both a Counter and Delta Counter, consider adding a relevant suffix to one of the metrics to differentiate one metric name from another. |
0 commit comments