本文整理汇总了Golang中bosun/org/slog.Infoln函数的典型用法代码示例。如果您正苦于以下问题:Golang Infoln函数的具体用法?Golang Infoln怎么用?Golang Infoln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infoln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendNotifications
func (s *Schedule) sendNotifications(silenced map[models.AlertKey]models.Silence) {
if s.Conf.Quiet {
slog.Infoln("quiet mode prevented", len(s.pendingNotifications), "notifications")
return
}
for n, states := range s.pendingNotifications {
for _, st := range states {
ak := st.AlertKey()
_, silenced := silenced[ak]
if st.Last().Status == StUnknown {
if silenced {
slog.Infoln("silencing unknown", ak)
continue
}
s.pendingUnknowns[n] = append(s.pendingUnknowns[n], st)
} else if silenced {
slog.Infoln("silencing", ak)
} else {
s.notify(st, n)
}
if n.Next != nil {
s.AddNotification(ak, n.Next, time.Now().UTC())
}
}
}
}
示例2: sendNotifications
func (s *Schedule) sendNotifications(silenced SilenceTester) {
if s.Conf.Quiet {
slog.Infoln("quiet mode prevented", len(s.pendingNotifications), "notifications")
return
}
for n, states := range s.pendingNotifications {
for _, st := range states {
ak := st.AlertKey
silenced := silenced(ak) != nil
if st.CurrentStatus == models.StUnknown {
if silenced {
slog.Infoln("silencing unknown", ak)
continue
}
s.pendingUnknowns[n] = append(s.pendingUnknowns[n], st)
} else if silenced {
slog.Infoln("silencing", ak)
} else {
s.notify(st, n)
}
if n.Next != nil {
s.QueueNotification(ak, n.Next, utcNow())
}
}
}
}
示例3: save
func (s *Schedule) save() {
if s.db == nil {
return
}
s.Lock("Save")
store := map[string]interface{}{
dbMetric: s.Search.Read.Metric,
dbTagk: s.Search.Read.Tagk,
dbTagv: s.Search.Read.Tagv,
dbMetricTags: s.Search.Read.MetricTags,
dbNotifications: s.Notifications,
dbSilence: s.Silence,
dbStatus: s.status,
dbMetadata: s.Metadata,
dbIncidents: s.Incidents,
}
tostore := make(map[string][]byte)
for name, data := range store {
f := new(bytes.Buffer)
gz := gzip.NewWriter(f)
cw := &counterWriter{w: gz}
enc := gob.NewEncoder(cw)
if err := enc.Encode(data); err != nil {
slog.Errorf("error saving %s: %v", name, err)
s.Unlock()
return
}
if err := gz.Flush(); err != nil {
slog.Errorf("gzip flush error saving %s: %v", name, err)
}
if err := gz.Close(); err != nil {
slog.Errorf("gzip close error saving %s: %v", name, err)
}
tostore[name] = f.Bytes()
slog.Infof("wrote %s: %v", name, conf.ByteSize(cw.written))
collect.Put("statefile.size", opentsdb.TagSet{"object": name}, cw.written)
}
s.Unlock()
err := s.db.Update(func(tx *bolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(dbBucket))
if err != nil {
return err
}
for name, data := range tostore {
if err := b.Put([]byte(name), data); err != nil {
return err
}
}
return nil
})
if err != nil {
slog.Errorf("save db update error: %v", err)
return
}
fi, err := os.Stat(s.Conf.StateFile)
if err == nil {
collect.Put("statefile.size", opentsdb.TagSet{"object": "total"}, fi.Size())
}
slog.Infoln("save to db complete")
}
示例4: CheckNotifications
// CheckNotifications processes past notification events. It returns the next time a notification is needed.
func (s *Schedule) CheckNotifications() time.Time {
silenced := s.Silenced()
s.Lock("CheckNotifications")
defer s.Unlock()
latestTime := utcNow()
notifications, err := s.DataAccess.Notifications().GetDueNotifications()
if err != nil {
slog.Error("Error getting notifications", err)
return utcNow().Add(time.Minute)
}
for ak, ns := range notifications {
if si := silenced(ak); si != nil {
slog.Infoln("silencing", ak)
continue
}
for name, t := range ns {
n := s.RuleConf.GetNotification(name)
if n == nil {
continue
}
//If alert is currently unevaluated because of a dependency,
//simply requeue it until the dependency resolves itself.
_, uneval := s.GetUnknownAndUnevaluatedAlertKeys(ak.Name())
unevaluated := false
for _, un := range uneval {
if un == ak {
unevaluated = true
break
}
}
if unevaluated {
s.QueueNotification(ak, n, t.Add(time.Minute))
continue
}
st, err := s.DataAccess.State().GetLatestIncident(ak)
if err != nil {
slog.Error(err)
continue
}
if st == nil {
continue
}
s.Notify(st, n)
}
}
s.sendNotifications(silenced)
s.pendingNotifications = nil
err = s.DataAccess.Notifications().ClearNotificationsBefore(latestTime)
if err != nil {
slog.Error("Error clearing notifications", err)
return utcNow().Add(time.Minute)
}
timeout, err := s.DataAccess.Notifications().GetNextNotificationTime()
if err != nil {
slog.Error("Error getting next notification time", err)
return utcNow().Add(time.Minute)
}
return timeout
}
示例5: recordSent
func recordSent(num int) {
if Debug {
slog.Infoln("sent", num)
}
slock.Lock()
sent += int64(num)
slock.Unlock()
}
示例6: Run
func (c *ProgramCollector) Run(dpchan chan<- *opentsdb.DataPoint) {
if c.Interval == 0 {
for {
next := time.After(DefaultFreq)
if err := c.runProgram(dpchan); err != nil {
slog.Infoln(err)
}
<-next
slog.Infoln("restarting", c.Path)
}
} else {
for {
next := time.After(c.Interval)
c.runProgram(dpchan)
<-next
}
}
}
示例7: RestoreState
// RestoreState restores notification and alert state from the file on disk.
func (s *Schedule) RestoreState() error {
defer func() {
bosunStartupTime = utcNow()
}()
slog.Infoln("RestoreState")
start := utcNow()
s.Lock("RestoreState")
defer s.Unlock()
s.Search.Lock()
defer s.Search.Unlock()
if err := migrateOldDataToRedis(s.db, s.DataAccess, s); err != nil {
return err
}
// delete metrictags if they exist.
deleteKey(s.db, "metrictags")
slog.Infoln("RestoreState done in", time.Since(start))
return nil
}
示例8: InitPrograms
func InitPrograms(cpath string) {
cdir, err := os.Open(cpath)
if err != nil {
slog.Infoln(err)
return
}
idirs, err := cdir.Readdir(0)
if err != nil {
slog.Infoln(err)
return
}
for _, idir := range idirs {
idirname := idir.Name()
i, err := strconv.Atoi(idirname)
if err != nil || i < 0 {
if idirname != "etc" && idirname != "lib" {
slog.Infoln("invalid collector folder name:", idirname)
}
continue
}
interval := time.Second * time.Duration(i)
dir, err := os.Open(filepath.Join(cdir.Name(), idirname))
if err != nil {
slog.Infoln(err)
continue
}
files, err := dir.Readdir(0)
if err != nil {
slog.Infoln(err)
continue
}
for _, file := range files {
if !isExecutable(file) {
continue
}
collectors = append(collectors, &ProgramCollector{
Path: filepath.Join(dir.Name(), file.Name()),
Interval: interval,
})
}
}
}
示例9: CheckNotifications
// CheckNotifications processes past notification events. It returns the
// duration until the soonest notification triggers.
func (s *Schedule) CheckNotifications() time.Duration {
silenced := s.Silenced()
s.Lock("CheckNotifications")
defer s.Unlock()
notifications := s.Notifications
s.Notifications = nil
for ak, ns := range notifications {
if _, present := silenced[ak]; present {
slog.Infoln("silencing", ak)
continue
}
for name, t := range ns {
n, present := s.Conf.Notifications[name]
if !present {
continue
}
remaining := t.Add(n.Timeout).Sub(time.Now())
if remaining > 0 {
s.AddNotification(ak, n, t)
continue
}
st := s.status[ak]
if st == nil {
continue
}
// If alert is currently unevaluated because of a dependency,
// simply requeue it until the dependency resolves itself.
if st.Unevaluated {
s.AddNotification(ak, n, t)
continue
}
s.Notify(st, n)
}
}
s.sendNotifications(silenced)
s.pendingNotifications = nil
timeout := time.Hour
now := time.Now()
for _, ns := range s.Notifications {
for name, t := range ns {
n, present := s.Conf.Notifications[name]
if !present {
continue
}
remaining := t.Add(n.Timeout).Sub(now)
if remaining < timeout {
timeout = remaining
}
}
}
return timeout
}
示例10: unotify
func (s *Schedule) unotify(name string, group models.AlertKeys, n *conf.Notification) {
subject := new(bytes.Buffer)
body := new(bytes.Buffer)
now := utcNow()
s.Group[now] = group
t := s.RuleConf.GetUnknownTemplate()
if t == nil {
t = defaultUnknownTemplate
}
data := s.unknownData(now, name, group)
if t.Body != nil {
if err := t.Body.Execute(body, &data); err != nil {
slog.Infoln("unknown template error:", err)
}
}
if t.Subject != nil {
if err := t.Subject.Execute(subject, &data); err != nil {
slog.Infoln("unknown template error:", err)
}
}
n.Notify(subject.String(), body.String(), subject.Bytes(), body.Bytes(), s.SystemConf, name)
}
示例11: Run
func (c *ProgramCollector) Run(dpchan chan<- *opentsdb.DataPoint, quit <-chan struct{}) {
if c.Interval == 0 {
for {
next := time.After(DefaultFreq)
if err := c.runProgram(dpchan); err != nil {
slog.Infoln(err)
}
<-next
slog.Infoln("restarting", c.Path)
}
} else {
for {
next := time.After(c.Interval)
c.runProgram(dpchan)
select {
case <-next:
case <-quit:
return
}
}
}
}
示例12: sendNotifications
func (s *Schedule) sendNotifications(silenced SilenceTester) {
if s.quiet {
slog.Infoln("quiet mode prevented", len(s.pendingNotifications), "notifications")
return
}
for n, states := range s.pendingNotifications {
for _, st := range states {
ak := st.AlertKey
alert := s.RuleConf.GetAlert(ak.Name())
if alert == nil {
continue
}
silenced := silenced(ak) != nil
if st.CurrentStatus == models.StUnknown {
if silenced {
slog.Infoln("silencing unknown", ak)
continue
}
s.pendingUnknowns[n] = append(s.pendingUnknowns[n], st)
} else if silenced {
slog.Infof("silencing %s", ak)
continue
} else if !alert.Log && (!st.Open || !st.NeedAck) {
slog.Errorf("Cannot notify acked or closed alert %s. Clearing.", ak)
if err := s.DataAccess.Notifications().ClearNotifications(ak); err != nil {
slog.Error(err)
}
continue
} else {
s.notify(st, n)
}
if n.Next != nil {
s.QueueNotification(ak, n.Next, utcNow())
}
}
}
}
示例13: fetchR53
//If there is Route53 data for this row, then populate the Route 53 item
func (b *billLineItem) fetchR53(awsBilling *awsBillingConfig) {
if b.ProductCode == "AmazonRoute53" { //Don't do anything if we don't have any R53 info to get
zoneID := strings.Split(b.ResourceID, "/")[1] //The billing ID has a huge resource ID, we only need the last part of it
cachedR53Zone, ok := awsBillingR53zones[zoneID] //Check if we have a copy of this zone in our local cache
if ok { //If we have a copy of the zone, then use that
b.Route53Zone = cachedR53Zone.HostedZone
return
}
//Otherwise we need to fetch it from Route 53
thisR53, fetchErr := awsBilling.r53svc.GetHostedZone(&route53.GetHostedZoneInput{
Id: aws.String(zoneID),
})
if fetchErr != nil {
slog.Infoln("Cannot fetch Route53 hosted zone", b.ResourceID, fetchErr)
}
awsBillingR53zones[zoneID] = *thisR53 //Store the fetched zone in the cache
b.Route53Zone = thisR53.HostedZone //And assign
}
}
示例14: c_bacula_status
func c_bacula_status(user, pass, dbase string) (opentsdb.MultiDataPoint, error) {
dsn := fmt.Sprintf("%s:%[email protected]/%s", user, pass, dbase)
db, err := sql.Open("mysql", dsn)
if err != nil {
slog.Error("Failed to connect to database")
return nil, err
}
defer db.Close()
var md opentsdb.MultiDataPoint
var name string
var value int
var tagSet opentsdb.TagSet
var rate metadata.RateType
var unit metadata.Unit
tagSet = nil
rate = metadata.Gauge
unit = metadata.Item
description := "Successful backup jobs in the last week"
rows, err := db.Query("SELECT DISTINCT(Name) from Job")
if err != nil {
slog.Error("Query Error: " + err.Error())
return nil, err
}
for rows.Next() {
rows.Scan(&name)
r := db.QueryRow("SELECT count(JobId) as value from Job where RealEndTime>SUBTIME(now(), '7 0:0:0') and JobStatus='T' and Name=?", name)
r.Scan(&value)
slog.Infoln(name, value)
Add(&md, "bacula."+name+".last_week", value, tagSet, rate, unit, description)
}
return md, nil
}
示例15: watch
func watch(root, pattern string, f func()) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
slog.Fatal(err)
}
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if matched, err := filepath.Match(pattern, info.Name()); err != nil {
slog.Fatal(err)
} else if !matched {
return nil
}
err = watcher.Add(path)
if err != nil {
slog.Fatal(err)
}
return nil
})
slog.Infoln("watching", pattern, "in", root)
wait := time.Now()
go func() {
for {
select {
case event := <-watcher.Events:
if wait.After(time.Now()) {
continue
}
if event.Op&fsnotify.Write == fsnotify.Write {
f()
wait = time.Now().Add(time.Second * 2)
}
case err := <-watcher.Errors:
slog.Errorln("error:", err)
}
}
}()
}