Git Product home page Git Product logo

sensu-aws's Introduction

Sensu Go AWS Plugin Collection

NOTE: this project is no longer actively maintained. Please see https://github.com/sensu/sensu-cloudwatch-check.

Overview

This Sensu Go plugin collection provides metric and status checks for monitoring AWS services with Sensu.

Usage examples

check-alb-target-group-health

  ./check-alb-target-group-health --aws_region=us-east-1

  ./check-alb-target-group-health --aws_region=us-east-1 --target_groups=target-group-1
  
  ./check-alb-target-group-health --aws_region=us-east-1 --target_groups=target-group-a,target-group-b
  

check-cloudwatch-alarm

  ./check-cloudwatch-alarm --aws_region=eu-west-1
   
  ./check-cloudwatch-alarm --state=ALARM

check-cloudwatch-alarms

  ./check-cloudwatch-alarms --exclude_alarms=CPUAlarmLow
  
  ./check-cloudwatch-alarms --aws_region=eu-west-1 --exclude_alarms=CPUAlarmLow
  
  ./check-cloudwatch-alarms --state=ALARM
      

check-cloudwatch-composite-metric

  ./check-cloudwatch-composite-metric --namespace AWS/ELB --dimensions="LoadBalancerName=test-elb" 
                                      --period=60 --statistics=Maximum --operator=equal --critical=0 

check-ebs-burst-limit

  ./check-ebs-burst-limit --aws_region=eu-west-1
  

check-ebs-snapshots

  ./check-ebs-snapshots --check_ignored=false
  

check-ec2-cpu_balance

  ./check-ec2-cpu_balance --critical=3
  
  ./check-ec2-cpu_balance --critical=1 --warning=5
  
  ./check-ec2-cpu_balance --critical=1 --warning=5 --tag=TESTING
  

check-ec2-filter

  ./check-ec2-filter --filters="{\"filters\" : [{\"name\" : \"instance-state-name\", \"values\": [\"running\"]}]}"
  
  ./check-ec2-filter --exclude_tags="{\"TAG_NAME\" : \"TAG_VALUE\"}" --compare=not
  

check-ec2-network

  ./check-ec2-network --instance_id=i-0f1626fsbfvbafa2 --direction=NetworkOut
  

metrics-ec2-count

  ./metrics-ec2-count --metric_type=status
  
  ./metrics-ec2-count --metric_type=instance
  

metrics-ec2-filter

  ./metric-ec2-filter --filters="{\"filters\" : [{\"name\" : \"instance-state-name\", \"values\": [\"running\"]}]}"
  

check-elb-certs

  ./check-elb-certs --aws_region=${your_region} --warning=${days_to_warn} -critical=${days_to_critical}
  

check-elb-health-fog

  ./check-elb-health-fog --aws_region=${you_region} --instances=${your_instance_ids} 
                         --elb_name=${your_elb_name} --verbose=true  

check-elb-health-sdk

  ./check-elb-health-sdk --aws_region=region
  
  ./check-elb-health-sdk --aws_region=region --elb_name=my-elb
  
  ./check-elb-health-sdk --aws_region=region --elb_name=my-elb --instances=instance1,instance2
  

check-elb-instance-inservice

  ./check-elb-instance-inservice --aws_region=${your_region}
  
  ./check-elb-instance-inservice --aws_region=${your_region} --elb_name=${LoadBalancerName}
  

check-elb-latency

  ./check-elb-latency --warning_over=1 --critical_over=3
  
  ./check-elb-latency --elb_names=app --critical_over=5 --statistics=maximum --period=3600
  

check-elb-nodes

  ./check-elb-nodes --warning=3 --critical=2 --load_balancer=#{your-load-balancer}

  ./check-elb-nodes --warning_percentage=50 --critical_percentage=25 --load_balancer=#{your-load-balancer}
  

elb-metrics

  ./elb-metrics --aws_region=${your_region}
  

check-rds

  ./check-rds --db_instance_id=sensu-admin-db --available_zone_severity=critical --available_zone=ap-northeast-1a
  
  ./check-rds --db_instance_id=sensu-admin-db --cpu_warning_over=80 --cpu_critical_over=90
  
  ./check-rds --db_instance_id=sensu-admin-db --cpu_critical_over=90 --statistics=maximum --period=3600
  
  ./check-rds --db_instance_id=sensu-admin-db --connections_critical_over=120 --connections_warning_over=100 
              --statistics=maximum --period=3600
              
  ./check-rds --db_instance_id=sensu-admin-db --iops_critical_over=200 --iops_warning_over=100 --period=300
  
  ./check-rds --db_instance_id=sensu-admin-db --memory_warning_over=80 --statistics=minimum --period=7200
  
  ./check-rds --db_instance_id=sensu-admin-db --disk_warning_over=80 --period=7200
  
  ./check-rds --db_instance_id=sensu-admin-db --cpu_warning_over=80 --cpu_critical_over=90 
              --memory_warning_over=60 --memory_critical_over=80
              

check-rds-events

 ./check-rds-events --aws_region=${your_region}  --db_instance_id=${your_rds_instance_id_name}
 
 ./check-rds-events.rb --aws_region=${your_region}
 

check-rds-pending

  ./check-rds-pending --aws_region=${you_region}

rds-metrics

 ./rds-metrics --aws_region=eu-west-1
 
 ./rds-metrics --aws_region=eu-west-1 --db_instance_id=sr2x8pbti0eon1
 

check-s3-bucket

 ./check-s3-bucket --bucket_name=mybucket
 

check-s3-bucket-visibility

 ./check-s3-bucket-visibility.go --exclude_buckets_regx=sensu --bucket_names=ssensu-ec2,sensu-ec3 
                                 --exclude_cuckets=sensu-ec3

check-s3-object

 ./check-s3-object --bucket_name=aws-testing --key_prefix=s3
 

check-s3-tag

 ./check-s3-tag --tag_keys=sensu
 

s3-metrics

 ./metrics-s3
 

Golang program locations

You can find the individual Golang programs in https://github.com/sensu/sensu-aws/tree/master/plugins. In that directory you'll find a listing of AWS services, with each service directory housing its respective checks.

Configuration

Asset registration

Assets are the best way to make use of this handler. If you're not using an asset, please consider doing so! If you're using Sensu 5.13 or later, you can use the following command to add the asset:

sensuctl asset add sensu/sensu-aws

If you're using an earlier version of Sensu, you can download the asset definition from this project's Bonsai Asset Index page.

Check definition

---
type: CheckConfig
api_version: core/v2
metadata:
  name: check-ec2-network
  namespace: default
spec:
  check_hooks: null
  command: check-ec2-network -instance_id i-1234567890
  env_vars: null
  handlers: []
  high_flap_threshold: 0
  interval: 10
  low_flap_threshold: 0
  output_metric_format: ""
  output_metric_handlers: null
  proxy_entity_name: ""
  publish: true
  round_robin: false
  runtime_assets:
  - sensu/sensu-aws
  stdin: false
  subdue: null
  subscriptions:
  - aws
  timeout: 0
  ttl: 0

On-disk configuration

This plugin requires on-disk configuration for any host that will run checks from this collection. See the Sample Credential Configuration below to create the file you need to operate this plugin.

Sample Credential Configuration:
[default]
aws_access_key_id=AGFGFHGFHHJGHJG
aws_secret_access_key=cdfedbfdjdjsbsjdgbjdsgbjdskg

Sample Config:
[default]
region=us-east-2
output=json

$ mkdir ~/.aws
$ cd ~/.aws
$ vi credentials - copy and paste the above sample credential and change the aws_access_key_id and aws_secret_access_key to some valid values. Save the file.
$ vi config - copy and paste the above sample config and change the region to some valid value. Save the file.

Installation from source

The preferred way to install and deploy this plugin is to use it as an asset. To compile and install the plugin from source or contribute to the plugin, download the latest version of the sensu-aws from releases or create an executable script from this source.

From the local path of the sensu-aws repository:

go build -o /usr/local/bin/sensu-aws main.go

Contributing

For more information about contributing to this plugin, see https://github.com/sensu/sensu-go/blob/master/CONTRIBUTING.md

sensu-aws's People

Contributors

ahmedsajid avatar amdprophet avatar asachs01 avatar echlebek avatar portertech avatar sreejita-biswas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensu-aws's Issues

Project needs a bit of cleanup

While the concept of a collection is great, it makes releasing improvements to the individual programs a bit of a pain. For example, if there's one executable that has an issue, do we need to wait on other improvements before we cut the collection? Also, have we considered the build time for this particular collection? The last release took about 16 minutes to build. While that's not that terribly long, it could be considerably shorter if we split the collection out. For example, we could split it along the lines of aws product groups and provide something like sensu/aws-elb, sensu/aws-ec2, etc. I think breaking this collection down into smaller component chunks would be beneficial.

check-rds not working

Hello,

I have an issue running check-rds check.

On Sensu written in ruby using { name: "sensu-plugins-aws", version: "18.4.0" } everything works OK.

$ sudo -u sensu -H /opt/sensu/embedded/bin/check-rds.rb --iops-critical-over 270 --iops-warning-over 210 --db-instance-id pg1-stg2-ir --aws-region eu-west-1 --period 1800
  CheckRDS OK:
$ echo $?
  0

But when trying to use sensu-aws_0.0.2_linux_amd64.tar.gz (https://github.com/sensu/sensu-aws/releases/download/0.0.2/sensu-aws_0.0.2_linux_amd64.tar.gz)

$ sudo -u sensu -H /opt/sensu-aws/check-rds --iops_critical_over=270 --iops_warning_over=210 --db_instance_id=pg1-stg2-ir --aws_region=eu-west-1 --period=1800
  Availabilty Zone for DB Instance pg1-stg2-ir is eu-west-1b
  UNKNOWN : DB INSTACE : pg1-stg2-ir : cpu usage : Requested time period did not return values from Cloudwatch. Try increasing your time period.
  UNKNOWN : DB INSTACE : pg1-stg2-ir : memory usage : Requested time period did not return values from Cloudwatch. Try increasing your time period.
  UNKNOWN : DB INSTACE : pg1-stg2-ir : disk usage : Requested time period did not return values from Cloudwatch. Try increasing your time period.
  UNKNOWN : DB INSTACE : pg1-stg2-ir : database connections usage : Requested time period did not return values from Cloudwatch. Try increasing your time period.
  UNKNOWN : DB INSTACE : pg1-stg2-ir : iops usage : Requested time period did not return values from Cloudwatch. Try increasing your time period.
$ echo $?
  0

# when I replace `--aws_region` to `--available_zone` did not find instance and still returns exit code 0
$ sudo -u sensu -H /opt/sensu-aws/check-rds --iops_critical_over=270 --iops_warning_over=210 --db_instance_id=pg1-stg2-ir --available_zone=eu-west-1b --period=1800
  UNKNOWN : pg1-stg2-ir instance not found
$ echo $?
  0

I get no metric data and script is still returning 0 exit code.

check-ec2-cpu_balance not working

Hello,

I am having an issue with this plugin which is not returning any output

$ ./check-ec2-cpu_balance --warning 3 --critical 1 --aws_region eu-west-1

$ echo $?
0

In the dashboard the Check Result detail says: "Check did not write to STDOUT."

Return correct status codes from all plugins

Most of the plugins are structured like this:

505 func main() {
506     rootCmd := configureRootCommand()
507     if err := rootCmd.Execute(); err != nil {
508         fmt.Fprintf(os.Stderr, "error: %v\n", err)
509         os.Exit(1)
510     }
511 }
512 
513 func run(cmd *cobra.Command, args []string) error {
514     if len(args) != 0 {
515         _ = cmd.Help()
516         return fmt.Errorf("invalid argument(s) received")    
517     }
518     checkRds() 
519     return nil 
520 }

The problem with this structure is that all of the business logic occurs in checkRds(), but checkRds() returns no errors. Therefore, the only way for this program to return a non-zero exit status is for argument parsing to fail.

The subroutine itself signals failure by outputting "CRITICAL:" or "WARNING:", but I doubt that every single error condition has been given this treatment. So, it seems fairly likely that there are several plugins that can silently fail. (See #3)

The checkRds function should be refactored to return structured errors that can be inspected by main(), so that the appropriate exit status can be written by os.Exit.

Write unit tests for each package in the project

The project contains zero unit tests. There are likely bugs, although that is not the primary concern about having an untested code base.

The project won't be maintainable going forward unless we expend significant effort in writing unit tests for the code already implemented. Without unit tests, developers won't know if their changes will produce a regression.

The good news is that the functionality is fairly basic, so it shouldn't be too difficult to tackle this. But, we should probably undertake this immediately after #9, so that the scope of the project doesn't keep growing, untested.

Need help with custom s3 path check

We are migrating from sensu core to sensu go . Can someone help
Sensu core ruby checks :--
check-s3-object.rb -b "bucket" -p "path/here/date --date="48 hour ago" +%Y/%m/%d/" --aws-region us-east-1 --ok-on-multiple-objects
to
./check-s3-object.go --bucket_name=bucket --key_prefix=path/here/?????

sorry i am newbie in GoLang
Thanks in advance

metric-rds go check is not working. here is the fix for it

  •   input.EndTime = aws.Time(time.Now())
    
  •   input.StartTime = aws.Time((input.EndTime).Add(time.Duration(-fetchAge/60) * time.Minute))
    

instead of

  •   input.EndTime = aws.Time(time.Now().Add(time.Duration(-fetchAge/60) * time.Minute))
    
  •   input.StartTime = aws.Time((*input.EndTime).Add(time.Duration(-period/60) * time.Minute))
    

  •    statisticsTypeMap["BurstBalance"] = statisticType
    

for Getting burst balance of the RDS


comment below lines as it is already declared

// cmd.Flags().StringVar(&awsRegion, "aws_region", "us-east-1", "AWS Region (defaults to us-east-1).")
// cmd.Flags().StringVar(&scheme, "scheme", "", "Metric naming scheme, text to prepend to metric")

instead of

  •   cmd.Flags().StringVar(&awsRegion, "aws_region", "us-east-1", "AWS Region (defaults to us-east-1).")
    
  •   cmd.Flags().StringVar(&scheme, "scheme", "", "Metric naming scheme, text to prepend to metric")
    

==========================

Fixed go file. attaching below

package main

/*

rds-metrics

DESCRIPTION:

Gets RDS metrics from CloudWatch and puts them in Graphite for longer term storage

OUTPUT:

metric-data

PLATFORMS:

MAC OS

USAGE:

./rds-metrics --aws_region=eu-west-1

./rds-metrics --aws_region=eu-west-1 --db_instance_id=sr2x8pbti0eon1

NOTES:

Returns all RDS statistics for all RDS instances in this account unless you specify --db_instance_id

LICENSE:

TODO

*/

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/sensu/sensu-aws/awsclient"

"github.com/aws/aws-sdk-go/aws"

"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/sensu/sensu-aws/aws_session"

)

var (
awsRegion string
rdsClient *rds.RDS
scheme string
dbInstanceId string
fetchAge int
period int64
//statistics string
cloudWatchClient *cloudwatch.CloudWatch
)

func metrics() {
var success bool
clusters := []*string{}
statisticsTypeMap := getStatisticTypes()
if len(dbInstanceId) > 0 {
clusters = []*string{&dbInstanceId}
}
awsSession := aws_session.CreateAwsSessionWithRegion(awsRegion)
success, rdsClient = awsclient.GetRDSClient(awsSession)
if !success {
return
}
dbInstances, err := getDBInstances(clusters)
if err != nil || dbInstances == nil {
return
}
for _, dbInstance := range dbInstances {
fullScheme := *dbInstance.DBInstanceIdentifier
if len(scheme) > 0 {
fullScheme = fmt.Sprintf("%s.%s", scheme, fullScheme)
}

	success, cloudWatchClient = awsclient.GetCloudWatchClient(awsSession)
	if !success {
		return
	}
	for metricName, statistic := range statisticsTypeMap {
		value, timestamp, err := getCloudWatchMetrics(metricName, statistic, fullScheme)
		if err != nil {
			fmt.Println("Error : ", err)
			return
		}
		if value == nil || timestamp == nil {
			continue
		}
		fmt.Println(fullScheme, ".", metricName, "  -  value :", value, ", timestamp:", timestamp)
	}
}

}

func getCloudWatchMetrics(metricname string, statistic string, rdsName string) (*float64, *time.Time, error) {
var input cloudwatch.GetMetricStatisticsInput
input.Namespace = aws.String("AWS/RDS")
input.MetricName = aws.String(metricname)
var dimensionFilter cloudwatch.Dimension
dimensionFilter.Name = aws.String("DBInstanceIdentifier")
dimensionFilter.Value = aws.String(rdsName)
input.Dimensions = []*cloudwatch.Dimension{&dimensionFilter}
input.EndTime = aws.Time(time.Now())
input.StartTime = aws.Time((input.EndTime).Add(time.Duration(-fetchAge/60) * time.Minute))
input.Period = aws.Int64(period)
input.Statistics = []*string{aws.String(statistic)}
metrics, err := cloudWatchClient.GetMetricStatistics(&input)
if err != nil {
return nil, nil, err
}
if metrics != nil && metrics.Datapoints != nil && len(metrics.Datapoints) > 1 {
var minimumTimeDifference float64
var timeDifference float64
var averageValue *float64
var timestamp *time.Time
minimumTimeDifference = -1
for _, datapoint := range metrics.Datapoints {
timeDifference = time.Since(*datapoint.Timestamp).Seconds()
if minimumTimeDifference == -1 {
minimumTimeDifference = timeDifference
averageValue = datapoint.Average
timestamp = datapoint.Timestamp
} else if timeDifference < minimumTimeDifference {
minimumTimeDifference = timeDifference
averageValue = datapoint.Average
timestamp = datapoint.Timestamp
}
}
return averageValue, timestamp, nil
}
return nil, nil, nil
}

func getStatisticTypes() map[string]string {
statisticType := "Average"
statisticsTypeMap := make(map[string]string)
statisticsTypeMap["CPUUtilization"] = statisticType
statisticsTypeMap["BurstBalance"] = statisticType
statisticsTypeMap["DatabaseConnections"] = statisticType
statisticsTypeMap["FreeStorageSpace"] = statisticType
statisticsTypeMap["ReadIOPS"] = statisticType
statisticsTypeMap["ReadLatency"] = statisticType
statisticsTypeMap["ReadThroughput"] = statisticType
statisticsTypeMap["WriteIOPS"] = statisticType
statisticsTypeMap["WriteLatency"] = statisticType
statisticsTypeMap["WriteThroughput"] = statisticType
statisticsTypeMap["ReplicaLag"] = statisticType
statisticsTypeMap["SwapUsage"] = statisticType
statisticsTypeMap["BinLogDiskUsage"] = statisticType
statisticsTypeMap["DiskQueueDepth"] = statisticType
return statisticsTypeMap
}

func getDBInstances(clusters []*string) ([]*rds.DBInstance, error) {
dbInstanceInput := &rds.DescribeDBInstancesInput{}
if len(clusters) > 0 {
filter := &rds.Filter{}
filter.Name = aws.String("db-instance-id")
filter.Values = clusters
dbInstanceInput.Filters = []*rds.Filter{filter}
}
dbClusterOutput, err := rdsClient.DescribeDBInstances(dbInstanceInput)

if err != nil {
	fmt.Println("An error occurred processing AWS RDS API DescribeDBInstances", err)
	return nil, err
}

if !(dbClusterOutput != nil && dbClusterOutput.DBInstances != nil && len(dbClusterOutput.DBInstances) > 0) {
	fmt.Println("UNKNOWN : DB Instance not found!")
	return nil, nil
}
return dbClusterOutput.DBInstances, nil

}

func main() {
rootCmd := configureRootCommand()
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

func run(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
_ = cmd.Help()
return fmt.Errorf("invalid argument(s) received")
}
metrics()
return nil
}

func configureRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "metrics-rds",
Short: "The Sensu Go Aws RDS handler for metric management",
RunE: run,
}

cmd.Flags().StringVarP(&awsRegion,
	"aws_region",
	"r",
	"us-east-1",
	"AWS Region")

cmd.Flags().StringVarP(&scheme,
	"scheme",
	"s",
	"",
	"Metric naming scheme, text to prepend to metric")

// cmd.Flags().StringVar(&awsRegion, "aws_region", "us-east-1", "AWS Region (defaults to us-east-1).")
// cmd.Flags().StringVar(&scheme, "scheme", "", "Metric naming scheme, text to prepend to metric")
cmd.Flags().StringVar(&dbInstanceId, "db_instance_id", "", "DB instance identifier")
cmd.Flags().IntVar(&fetchAge, "fetch_age", 0, "How long ago to fetch metrics from in seconds")
cmd.Flags().Int64Var(&period, "period", 60, "CloudWatch metric statistics period")
return cmd
}

Output:-
root# go run main.go --db_instance_id=cr1bjadfsrdafds --aws_region=eu-east-1 --period=60 --fetch_age 1800
cr1bjadfsrdafds . FreeStorageSpace - value : 0xc000311820 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . SwapUsage - value : 0xc00032b7c0 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . BinLogDiskUsage - value : 0xc00034efd0 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . DiskQueueDepth - value : 0xc000365768 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . ReadIOPS - value : 0xc0003a4ab8 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . ReadThroughput - value : 0xc00038f3d0 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . WriteIOPS - value : 0xc00034f0c8 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . WriteThroughput - value : 0xc00032a530 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . CPUUtilization - value : 0xc000311ce8 , timestamp: 2020-09-29 19:15:00 +0000 UTC
cr1bjadfsrdafds . BurstBalance - value : 0xc000300c90 , timestamp: 2020-09-29 19:05:00 +0000 UTC
cr1bjadfsrdafds . DatabaseConnections - value : 0xc0004528a8 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . ReadLatency - value : 0xc0003b5628 , timestamp: 2020-09-29 19:16:00 +0000 UTC
cr1bjadfsrdafds . WriteLatency - value : 0xc0003da6b8 , timestamp: 2020-09-29 19:16:00 +0000 UTC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.