-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from rogerwelin/cloudwatch-metrics
Cloudwatch metrics
- Loading branch information
Showing
8 changed files
with
257 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: go | ||
go: | ||
- 1.13.x | ||
- 1.14.x | ||
os: | ||
- linux | ||
install: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/cloudwatch" | ||
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" | ||
) | ||
|
||
// PutCloudwatchMetrics exports metrics to AWS Cloudwatch | ||
func (c *Cassowary) PutCloudwatchMetrics(svc cloudwatchiface.CloudWatchAPI, metrics ResultMetrics) (*cloudwatch.PutMetricDataOutput, error) { | ||
resp, err := svc.PutMetricData(&cloudwatch.PutMetricDataInput{ | ||
Namespace: aws.String("Cassowary/Metrics"), | ||
MetricData: []*cloudwatch.MetricDatum{ | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("tcp_connect_mean"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.TCPStats.TCPMean), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("tcp_connect_median"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.TCPStats.TCPMedian), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("tcp_connect_95p"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.TCPStats.TCP95p), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("server_processing_mean"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ProcessingStats.ServerProcessingMean), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("server_processing_median"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ProcessingStats.ServerProcessingMedian), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("server_processing_95p"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ProcessingStats.ServerProcessing95p), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("content_transfer_mean"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ContentStats.ContentTransferMean), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("content_transfer_median"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ContentStats.ContentTransferMedian), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("content_transfer_95p"), | ||
Unit: aws.String("Milliseconds"), | ||
Value: aws.Float64(metrics.ContentStats.ContentTransfer95p), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("total_requests"), | ||
Unit: aws.String("Count"), | ||
Value: aws.Float64(float64(metrics.TotalRequests)), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("failed_requests"), | ||
Unit: aws.String("Count"), | ||
Value: aws.Float64(float64(metrics.FailedRequests)), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
&cloudwatch.MetricDatum{ | ||
MetricName: aws.String("requests_per_second"), | ||
Unit: aws.String("Count/Second"), | ||
Value: aws.Float64(metrics.RequestsPerSecond), | ||
Dimensions: []*cloudwatch.Dimension{ | ||
&cloudwatch.Dimension{ | ||
Name: aws.String("Site"), | ||
Value: aws.String(c.BaseURL), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package client | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudwatch" | ||
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface" | ||
) | ||
|
||
type mockCloudWatchClient struct { | ||
cloudwatchiface.CloudWatchAPI | ||
} | ||
|
||
func (m *mockCloudWatchClient) PutMetricData(input *cloudwatch.PutMetricDataInput) (*cloudwatch.PutMetricDataOutput, error) { | ||
// mock response/functionality | ||
return nil, nil | ||
} | ||
|
||
func TestPutCloudwatchMetrics(t *testing.T) { | ||
c := Cassowary{} | ||
metrics := ResultMetrics{ | ||
FailedRequests: 1, | ||
TotalRequests: 100, | ||
RequestsPerSecond: 100.10, | ||
TCPStats: tcpStats{ | ||
TCPMean: 10.0, | ||
TCPMedian: 10.0, | ||
TCP95p: 10.0, | ||
}, | ||
ProcessingStats: serverProcessingStats{ | ||
ServerProcessingMean: 1.0, | ||
ServerProcessingMedian: 1.0, | ||
ServerProcessing95p: 1.0, | ||
}, | ||
} | ||
mockSvc := &mockCloudWatchClient{} | ||
_, err := c.PutCloudwatchMetrics(mockSvc, metrics) | ||
|
||
if err != nil { | ||
t.Errorf("Wanted ok but got error: %v", err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters