func awsGetDiskOps(cw cloudwatch.CloudWatch, md *opentsdb.MultiDataPoint, instance *ec2.Instance) error { search := cloudwatch.GetMetricStatisticsInput{ StartTime: aws.Time(time.Now().UTC().Add(time.Second * -600)), EndTime: aws.Time(time.Now().UTC()), MetricName: aws.String("DiskReadOps"), Period: aws.Long(60), Statistics: []*string{aws.String("Average")}, Namespace: aws.String("AWS/EC2"), Unit: aws.String("Count"), Dimensions: []*cloudwatch.Dimension{{Name: aws.String("InstanceId"), Value: instance.InstanceID}}, } resp, err := cw.GetMetricStatistics(&search) if err != nil { return err } for _, datapoint := range resp.Datapoints { AddTS(md, awsEC2DiskOps, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"instance": *instance.InstanceID, "operation": "read"}, metadata.Gauge, metadata.Count, descAWSEC2DiskOps) } search.MetricName = aws.String("DiskWriteOps") resp, err = cw.GetMetricStatistics(&search) if err != nil { return err } for _, datapoint := range resp.Datapoints { AddTS(md, awsEC2DiskOps, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"instance": *instance.InstanceID, "operation": "write"}, metadata.Gauge, metadata.Count, descAWSEC2DiskOps) } return nil }
func ExampleELB_CreateLoadBalancerListeners() { svc := elb.New(nil) params := &elb.CreateLoadBalancerListenersInput{ Listeners: []*elb.Listener{ // Required &elb.Listener{ // Required InstancePort: aws.Long(1), // Required LoadBalancerPort: aws.Long(1), // Required Protocol: aws.String("Protocol"), // Required InstanceProtocol: aws.String("Protocol"), SSLCertificateID: aws.String("SSLCertificateId"), }, // More values... }, LoadBalancerName: aws.String("AccessPointName"), // Required } resp, err := svc.CreateLoadBalancerListeners(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleELB_ConfigureHealthCheck() { svc := elb.New(nil) params := &elb.ConfigureHealthCheckInput{ HealthCheck: &elb.HealthCheck{ // Required HealthyThreshold: aws.Long(1), // Required Interval: aws.Long(1), // Required Target: aws.String("HealthCheckTarget"), // Required Timeout: aws.Long(1), // Required UnhealthyThreshold: aws.Long(1), // Required }, LoadBalancerName: aws.String("AccessPointName"), // Required } resp, err := svc.ConfigureHealthCheck(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleCloudWatch_PutMetricAlarm() { svc := cloudwatch.New(nil) params := &cloudwatch.PutMetricAlarmInput{ AlarmName: aws.String("AlarmName"), // Required ComparisonOperator: aws.String("ComparisonOperator"), // Required EvaluationPeriods: aws.Long(1), // Required MetricName: aws.String("MetricName"), // Required Namespace: aws.String("Namespace"), // Required Period: aws.Long(1), // Required Statistic: aws.String("Statistic"), // Required Threshold: aws.Double(1.0), // Required ActionsEnabled: aws.Boolean(true), AlarmActions: []*string{ aws.String("ResourceName"), // Required // More values... }, AlarmDescription: aws.String("AlarmDescription"), Dimensions: []*cloudwatch.Dimension{ &cloudwatch.Dimension{ // Required Name: aws.String("DimensionName"), // Required Value: aws.String("DimensionValue"), // Required }, // More values... }, InsufficientDataActions: []*string{ aws.String("ResourceName"), // Required // More values... }, OKActions: []*string{ aws.String("ResourceName"), // Required // More values... }, Unit: aws.String("StandardUnit"), } resp, err := svc.PutMetricAlarm(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleELB_SetLoadBalancerPoliciesOfListener() { svc := elb.New(nil) params := &elb.SetLoadBalancerPoliciesOfListenerInput{ LoadBalancerName: aws.String("AccessPointName"), // Required LoadBalancerPort: aws.Long(1), // Required PolicyNames: []*string{ // Required aws.String("PolicyName"), // Required // More values... }, } resp, err := svc.SetLoadBalancerPoliciesOfListener(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func awsGetELBHostCounts(cw cloudwatch.CloudWatch, md *opentsdb.MultiDataPoint, loadBalancer *elb.LoadBalancerDescription) error { search := cloudwatch.GetMetricStatisticsInput{ StartTime: aws.Time(time.Now().UTC().Add(time.Second * -60)), EndTime: aws.Time(time.Now().UTC()), MetricName: aws.String("HealthyHostCount"), Period: aws.Long(60), Statistics: []*string{aws.String("Average")}, Namespace: aws.String("AWS/ELB"), Unit: aws.String("Count"), Dimensions: []*cloudwatch.Dimension{{Name: aws.String("LoadBalancerName"), Value: loadBalancer.LoadBalancerName}}, } resp, err := cw.GetMetricStatistics(&search) if err != nil { return err } for _, datapoint := range resp.Datapoints { AddTS(md, awsELBHostsHealthy, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount) } search.MetricName = aws.String("UnhealthyHostCount") resp, err = cw.GetMetricStatistics(&search) if err != nil { return err } if resp.Datapoints == nil { AddTS(md, awsELBHostsUnHealthy, time.Now().UTC().Unix(), 0, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount) } else { for _, datapoint := range resp.Datapoints { AddTS(md, awsELBHostsUnHealthy, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount) } } return nil }
func ExampleCloudWatch_DescribeAlarms() { svc := cloudwatch.New(nil) params := &cloudwatch.DescribeAlarmsInput{ ActionPrefix: aws.String("ActionPrefix"), AlarmNamePrefix: aws.String("AlarmNamePrefix"), AlarmNames: []*string{ aws.String("AlarmName"), // Required // More values... }, MaxRecords: aws.Long(1), NextToken: aws.String("NextToken"), StateValue: aws.String("StateValue"), } resp, err := svc.DescribeAlarms(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleCloudWatch_DescribeAlarmHistory() { svc := cloudwatch.New(nil) params := &cloudwatch.DescribeAlarmHistoryInput{ AlarmName: aws.String("AlarmName"), EndDate: aws.Time(time.Now()), HistoryItemType: aws.String("HistoryItemType"), MaxRecords: aws.Long(1), NextToken: aws.String("NextToken"), StartDate: aws.Time(time.Now()), } resp, err := svc.DescribeAlarmHistory(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleCloudWatch_DescribeAlarmsForMetric() { svc := cloudwatch.New(nil) params := &cloudwatch.DescribeAlarmsForMetricInput{ MetricName: aws.String("MetricName"), // Required Namespace: aws.String("Namespace"), // Required Dimensions: []*cloudwatch.Dimension{ &cloudwatch.Dimension{ // Required Name: aws.String("DimensionName"), // Required Value: aws.String("DimensionValue"), // Required }, // More values... }, Period: aws.Long(1), Statistic: aws.String("Statistic"), Unit: aws.String("StandardUnit"), } resp, err := svc.DescribeAlarmsForMetric(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func ExampleELB_ModifyLoadBalancerAttributes() { svc := elb.New(nil) params := &elb.ModifyLoadBalancerAttributesInput{ LoadBalancerAttributes: &elb.LoadBalancerAttributes{ // Required AccessLog: &elb.AccessLog{ Enabled: aws.Boolean(true), // Required EmitInterval: aws.Long(1), S3BucketName: aws.String("S3BucketName"), S3BucketPrefix: aws.String("AccessLogPrefix"), }, AdditionalAttributes: []*elb.AdditionalAttribute{ &elb.AdditionalAttribute{ // Required Key: aws.String("StringVal"), Value: aws.String("StringVal"), }, // More values... }, ConnectionDraining: &elb.ConnectionDraining{ Enabled: aws.Boolean(true), // Required Timeout: aws.Long(1), }, ConnectionSettings: &elb.ConnectionSettings{ IdleTimeout: aws.Long(1), // Required }, CrossZoneLoadBalancing: &elb.CrossZoneLoadBalancing{ Enabled: aws.Boolean(true), // Required }, }, LoadBalancerName: aws.String("AccessPointName"), // Required } resp, err := svc.ModifyLoadBalancerAttributes(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }
func awsGetELBLatency(cw cloudwatch.CloudWatch, md *opentsdb.MultiDataPoint, loadBalancer *elb.LoadBalancerDescription) error { search := cloudwatch.GetMetricStatisticsInput{ StartTime: aws.Time(time.Now().UTC().Add(time.Second * -4000)), EndTime: aws.Time(time.Now().UTC()), MetricName: aws.String("Latency"), Period: aws.Long(60), Statistics: []*string{aws.String("Average"), aws.String("Minimum"), aws.String("Maximum")}, Namespace: aws.String("AWS/ELB"), Unit: aws.String("Seconds"), Dimensions: []*cloudwatch.Dimension{{Name: aws.String("LoadBalancerName"), Value: loadBalancer.LoadBalancerName}}, } resp, err := cw.GetMetricStatistics(&search) if err != nil { return err } for _, datapoint := range resp.Datapoints { AddTS(md, awsELBLatencyMin, datapoint.Timestamp.Unix(), *datapoint.Minimum, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Second, descAWSELBLatency) AddTS(md, awsELBLatencyMax, datapoint.Timestamp.Unix(), *datapoint.Maximum, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Second, descAWSELBLatency) AddTS(md, awsELBLatencyAvg, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Second, descAWSELBLatency) } return nil }
func awsGetCPU(cw cloudwatch.CloudWatch, md *opentsdb.MultiDataPoint, instance *ec2.Instance) error { search := cloudwatch.GetMetricStatisticsInput{ StartTime: aws.Time(time.Now().UTC().Add(time.Second * -600)), EndTime: aws.Time(time.Now().UTC()), MetricName: aws.String("CPUUtilization"), Period: aws.Long(60), Statistics: []*string{aws.String("Average")}, Namespace: aws.String("AWS/EC2"), Unit: aws.String("Percent"), Dimensions: []*cloudwatch.Dimension{{Name: aws.String("InstanceId"), Value: instance.InstanceID}}, } resp, err := cw.GetMetricStatistics(&search) if err != nil { return err } tags := opentsdb.TagSet{ "instance": *instance.InstanceID, } for _, datapoint := range resp.Datapoints { AddTS(md, awsCPU, datapoint.Timestamp.Unix(), *datapoint.Average, tags, metadata.Gauge, metadata.Pct, descAWSEC2CPU) } return nil }
func ExampleELB_CreateLBCookieStickinessPolicy() { svc := elb.New(nil) params := &elb.CreateLBCookieStickinessPolicyInput{ LoadBalancerName: aws.String("AccessPointName"), // Required PolicyName: aws.String("PolicyName"), // Required CookieExpirationPeriod: aws.Long(1), } resp, err := svc.CreateLBCookieStickinessPolicy(params) if awsErr, ok := err.(awserr.Error); ok { // Generic AWS Error with Code, Message, and original error (if any) fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) if reqErr, ok := err.(awserr.RequestFailure); ok { // A service error occurred fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { fmt.Println(err.Error()) } // Pretty-print the response data. fmt.Println(awsutil.StringValue(resp)) }