本文整理匯總了Golang中github.com/mozilla-services/reaper/reaperlog.Info函數的典型用法代碼示例。如果您正苦於以下問題:Golang Info函數的具體用法?Golang Info怎麽用?Golang Info使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Info函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetPrices
func GetPrices() {
// prevent shadowing
var err error
log.Info("Downloading prices")
pricesMap, err = prices.DownloadPricesMap(prices.Ec2PricingUrl)
if err != nil {
log.Error(fmt.Sprintf("Error getting prices: %s", err.Error()))
return
}
log.Info("Successfully downloaded prices")
}
示例2: getVolumes
func getVolumes() chan *reaperaws.Volume {
ch := make(chan *reaperaws.Volume)
go func() {
volumeCh := reaperaws.AllVolumes()
regionSums := make(map[reapable.Region]int)
volumeSizeSums := make(map[reapable.Region]map[int64]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for volume := range volumeCh {
// make the map if it is not initialized
if volumeSizeSums[volume.Region()] == nil {
volumeSizeSums[volume.Region()] = make(map[int64]int)
}
regionSums[volume.Region()]++
if isWhitelisted(volume) {
whitelistedCount[volume.Region()]++
}
volumeSizeSums[volume.Region()][*volume.Size]++
if matchesFilters(volume) {
filteredCount[volume.Region()]++
}
ch <- volume
}
for region, sum := range regionSums {
log.Info("Found %d total volumes in %s", sum, region)
}
go func() {
for region, regionMap := range volumeSizeSums {
for volumeType, volumeSizeSum := range regionMap {
err := reaperevents.NewStatistic("reaper.volumes.total",
float64(volumeSizeSum),
[]string{fmt.Sprintf("region:%s,volumesize:%d", region, volumeType)})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.volumes.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s,volumesize:%d", region, volumeType)})
if err != nil {
log.Error(err.Error())
}
}
err := reaperevents.NewStatistic("reaper.volumes.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region)})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例3: registerReapable
func registerReapable(a reaperevents.Reapable) {
// update the internal state
if time.Now().After(a.ReaperState().Until) {
// if we updated the state, mark it as having been updated
a.SetUpdated(a.IncrementState())
}
log.Info("Reapable resource discovered: %s.", a.ReapableDescription())
reapables.Put(a.Region(), a.ID(), a)
}
示例4: main
func main() {
// config and events are vars in the reaper package
// they NEED to be set before a reaper.Reaper can be initialized
reaper.SetConfig(&config)
reaperevents.SetEvents(&eventReporters)
if config.DryRun {
log.Info("Dry run mode enabled, no events will be triggered. Enable Extras in Notifications for per-event DryRun notifications.")
reaperevents.SetDryRun(config.DryRun)
}
// Ready() NEEDS to be called after BOTH SetConfig() and SetEvents()
// it uses those values to set individual EventReporter config values
// and to init the Reapables map
reaper.Ready()
// sets the config variable in Reaper's AWS package
// this also NEEDS to be set before a Reaper can be started
reaperaws.SetConfig(&config.AWS)
// single instance of reaper
reapRunner := reaper.NewReaper()
// Run the reaper process
reapRunner.Start()
// run the HTTP server
api := reaper.NewHTTPApi(config.HTTP)
if err := api.Serve(); err != nil {
log.Error(err.Error())
} else {
// HTTP server successfully started
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
// waiting for an Interrupt or Kill signal
// this channel blocks until it receives one
sig := <-c
log.Info("Got signal %s, stopping services", sig.String())
log.Info("Stopping HTTP")
api.Stop()
log.Info("Stopping reaper runner")
reapRunner.Stop()
}
}
示例5: Terminate
// Terminate is a method of reapable.Terminable, which is embedded in reapable.Reapable
func (a *AutoScalingGroup) Terminate() (bool, error) {
log.Info("Terminating AutoScalingGroup %s", a.ReapableDescriptionTiny())
as := autoscaling.New(session.New(&aws.Config{Region: aws.String(a.Region().String())}))
input := &autoscaling.DeleteAutoScalingGroupInput{
AutoScalingGroupName: aws.String(a.ID().String()),
}
_, err := as.DeleteAutoScalingGroup(input)
if err != nil {
log.Error("could not delete AutoScalingGroup ", a.ReapableDescriptionTiny())
return false, err
}
return true, nil
}
示例6: newReapableEvent
// newReapableEvent is a method of EventReporter
func (e *ReaperEvent) newReapableEvent(r Reapable, tags []string) error {
if e.Config.shouldTriggerFor(r) {
var err error
switch e.Config.Mode {
case "Stop":
_, err = r.Stop()
log.Info("ReaperEvent: Stopping ", r.ReapableDescriptionShort())
NewEvent("Reaper: Stopping ", r.ReapableDescriptionShort(), nil, []string{})
NewCountStatistic("reaper.reapables.stopped", []string{r.ReapableDescriptionTiny()})
case "Terminate":
_, err = r.Terminate()
log.Info("ReaperEvent: Terminating ", r.ReapableDescriptionShort())
NewEvent("Reaper: Terminating ", r.ReapableDescriptionShort(), nil, []string{})
NewCountStatistic("reaper.reapables.terminated", []string{r.ReapableDescriptionTiny()})
default:
log.Error(fmt.Sprintf("Invalid %s Mode %s", e.Config.Name, e.Config.Mode))
}
if err != nil {
return err
}
}
return nil
}
示例7: newReapableEvent
// newReapableEvent is a method of EventReporter
func (e *Tagger) newReapableEvent(r Reapable, tags []string) error {
if r.ReaperState().Until.IsZero() {
log.Warning("Uninitialized time value for %s!", r.ReapableDescription())
}
if e.Config.shouldTriggerFor(r) {
log.Info("Tagging %s with %s", r.ReapableDescriptionTiny(), r.ReaperState().State.String())
_, err := r.Save(r.ReaperState())
if err != nil {
return err
}
}
return nil
}
示例8: Terminate
// Terminate is a method of reapable.Terminable, which is embedded in reapable.Reapable
func (a *SecurityGroup) Terminate() (bool, error) {
log.Info("Terminating SecurityGroup ", a.ReapableDescriptionTiny())
api := ec2.New(sess, aws.NewConfig().WithRegion(string(a.Region())))
input := &ec2.DeleteSecurityGroupInput{
GroupName: aws.String(a.ID().String()),
}
_, err := api.DeleteSecurityGroup(input)
if err != nil {
log.Error("could not delete SecurityGroup ", a.ReapableDescriptionTiny())
return false, err
}
return false, nil
}
示例9: Terminate
// Terminate is a method of reapable.Terminable, which is embedded in reapable.Reapable
func (a *Cloudformation) Terminate() (bool, error) {
log.Info("Terminating Cloudformation %s", a.ReapableDescriptionTiny())
as := cloudformation.New(sess, aws.NewConfig().WithRegion(a.Region().String()))
input := &cloudformation.DeleteStackInput{
StackName: aws.String(a.ID().String()),
}
_, err := as.DeleteStack(input)
if err != nil {
log.Error("could not delete Cloudformation ", a.ReapableDescriptionTiny())
return false, err
}
return false, nil
}
示例10: getSecurityGroups
func getSecurityGroups() chan *reaperaws.SecurityGroup {
ch := make(chan *reaperaws.SecurityGroup)
go func() {
securityGroupCh := reaperaws.AllSecurityGroups()
regionSums := make(map[reapable.Region]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for sg := range securityGroupCh {
regionSums[sg.Region()]++
if isWhitelisted(sg) {
whitelistedCount[sg.Region()]++
}
if matchesFilters(sg) {
filteredCount[sg.Region()]++
}
ch <- sg
}
for region, sum := range regionSums {
log.Info("Found %d total SecurityGroups in %s", sum, region)
}
go func() {
for region, regionSum := range regionSums {
err := reaperevents.NewStatistic("reaper.securitygroups.total",
float64(regionSum),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.securitygroups.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.securitygroups.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例11: scaleToSize
func (a *AutoScalingGroup) scaleToSize(size int64, minSize int64) (bool, error) {
log.Info("Scaling AutoScalingGroup %s to size %d.", a.ReapableDescriptionTiny(), size)
as := autoscaling.New(session.New(&aws.Config{Region: aws.String(a.Region().String())}))
input := &autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: aws.String(a.ID().String()),
DesiredCapacity: &size,
MinSize: &minSize,
}
_, err := as.UpdateAutoScalingGroup(input)
if err != nil {
log.Error("could not update AutoScalingGroup ", a.ReapableDescriptionTiny())
return false, err
}
return true, nil
}
示例12: cloudformationResources
// cloudformationResources returns a chan of CloudformationResources, sourced from the AWS API
// there is rate limiting in the AWS API for CloudformationResources, so we delay
// this is skippable with the CLI flag -withoutCloudformationResources
func cloudformationResources(region, id string) chan *cloudformation.StackResource {
ch := make(chan *cloudformation.StackResource)
if config.WithoutCloudformationResources {
close(ch)
return ch
}
api := cloudformation.New(sess, aws.NewConfig().WithRegion(region))
go func() {
<-timeout
// this query can fail, so we retry
didRetry := false
input := &cloudformation.DescribeStackResourcesInput{StackName: &id}
// initial query
resp, err := api.DescribeStackResources(input)
for err != nil {
sleepTime := 2*time.Second + time.Duration(rand.Intn(2000))*time.Millisecond
if err != nil {
// this error is annoying and will come up all the time... so you can disable it
if strings.Split(err.Error(), ":")[0] == "Throttling" && log.Extras() {
log.Warning("StackResources: %s (retrying %s after %ds)", err.Error(), id, sleepTime*1.0/time.Second)
} else if strings.Split(err.Error(), ":")[0] != "Throttling" {
// any other errors
log.Error(fmt.Sprintf("StackResources: %s (retrying %s after %ds)", err.Error(), id, sleepTime*1.0/time.Second))
}
}
// wait a random amount of time... hopefully long enough to beat rate limiting
time.Sleep(sleepTime)
// retry query
resp, err = api.DescribeStackResources(input)
didRetry = true
}
if didRetry && log.Extras() {
log.Info("Retry succeeded for %s!", id)
}
for _, resource := range resp.StackResources {
ch <- resource
}
close(ch)
}()
return ch
}
示例13: getCloudformations
func getCloudformations() chan *reaperaws.Cloudformation {
ch := make(chan *reaperaws.Cloudformation)
go func() {
cfs := reaperaws.AllCloudformations()
regionSums := make(map[reapable.Region]int)
filteredCount := make(map[reapable.Region]int)
whitelistedCount := make(map[reapable.Region]int)
for cf := range cfs {
if isWhitelisted(cf) {
whitelistedCount[cf.Region()]++
}
regionSums[cf.Region()]++
if matchesFilters(cf) {
filteredCount[cf.Region()]++
}
ch <- cf
}
for region, sum := range regionSums {
log.Info("Found %d total Cloudformation Stacks in %s", sum, region)
}
go func() {
for region, regionSum := range regionSums {
err := reaperevents.NewStatistic("reaper.cloudformations.total",
float64(regionSum),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.cloudformations.filtered",
float64(filteredCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
err = reaperevents.NewStatistic("reaper.cloudformations.whitelistedCount",
float64(whitelistedCount[region]),
[]string{fmt.Sprintf("region:%s", region), config.EventTag})
if err != nil {
log.Error(err.Error())
}
}
}()
close(ch)
}()
return ch
}
示例14: Whitelist
// Whitelist is a method of reapable.Whitelistable, which is embedded in reapable.Reapable
func (a *AutoScalingGroup) Whitelist() (bool, error) {
log.Info("Whitelisting AutoScalingGroup %s", a.ReapableDescriptionTiny())
api := autoscaling.New(session.New(&aws.Config{Region: aws.String(a.Region().String())}))
createreq := &autoscaling.CreateOrUpdateTagsInput{
Tags: []*autoscaling.Tag{
&autoscaling.Tag{
ResourceId: aws.String(a.ID().String()),
ResourceType: aws.String("auto-scaling-group"),
PropagateAtLaunch: aws.Bool(false),
Key: aws.String(config.WhitelistTag),
Value: aws.String("true"),
},
},
}
_, err := api.CreateOrUpdateTags(createreq)
return err == nil, err
}
示例15: shouldTriggerFor
// this is a copy of the method from events.go EXCEPT
// that it triggers whether or not the state was updated this run
func (e *ReaperEventConfig) shouldTriggerFor(r Reapable) bool {
if e.DryRun {
if log.Extras() {
log.Info("DryRun: Not triggering %s for %s", e.Name, r.ReapableDescriptionTiny())
}
return false
}
triggering := false
// if the reapable's state is set to trigger this EventReporter
for _, trigger := range e.parseTriggers() {
// if the reapable's state should trigger this event
if trigger == r.ReaperState().State {
triggering = true
}
}
return triggering
}