本文整理汇总了Golang中github.com/ctdk/goas/v2/logger.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ProcessBuffer
func (mStore MetricStore) ProcessBuffer(c <-chan metricdef.IndvMetric, workerId int) {
buf := make([]metricdef.IndvMetric, 0)
// flush buffer every second
t := time.NewTicker(time.Second)
for {
select {
case b := <-c:
if b.Name != "" {
logger.Debugf("worker %d appending to buffer", workerId)
buf = append(buf, b)
}
case <-t.C:
// A possibility: it might be worth it to hack up the
// carbon lib to allow batch submissions of metrics if
// doing them individually proves to be too slow
//copy contents of buffer
currentBuf := make([]metricdef.IndvMetric, len(buf))
copy(currentBuf, buf)
buf = nil
logger.Debugf("worker %d flushing %d items in buffer now", workerId, len(currentBuf))
for _, backend := range mStore.Backends {
if err := backend.SendMetrics(¤tBuf); err != nil {
logger.Errorf(err.Error())
} else {
logger.Debugf("worker %d flushed metrics buffer to %s backend", workerId, backend.Type())
}
}
}
}
}
示例2: processMetrics
func processMetrics(d *amqp.Delivery) error {
metrics := make([]*metricdef.IndvMetric, 0)
if err := json.Unmarshal(d.Body, &metrics); err != nil {
return err
}
logger.Debugf("The parsed out json: %v", metrics)
for _, m := range metrics {
logger.Debugf("processing %s", m.Name)
id := fmt.Sprintf("%d.%s", m.OrgId, m.Name)
if m.Id == "" {
m.Id = id
}
if err := metricDefs.CheckMetricDef(id, m); err != nil {
return err
}
if err := storeMetric(m); err != nil {
return err
}
}
if err := d.Ack(false); err != nil {
return err
}
return nil
}
示例3: DeleteHashes
// DeleteHashes deletes all the checksum hashes given from the filestore.
func DeleteHashes(fileHashes []string) {
if config.Config.UseMySQL {
deleteHashesMySQL(fileHashes)
} else if config.Config.UsePostgreSQL {
deleteHashesPostgreSQL(fileHashes)
} else {
for _, ff := range fileHashes {
delFile, err := Get(ff)
if err != nil {
logger.Debugf("Strange, we got an error trying to get %s to delete it.\n", ff)
logger.Debugf(err.Error())
} else {
_ = delFile.Delete()
}
// May be able to remove this. Check that it actually deleted
d, _ := Get(ff)
if d != nil {
logger.Debugf("Stranger and stranger, %s is still in the file store.\n", ff)
}
}
}
if config.Config.LocalFstoreDir != "" {
for _, fh := range fileHashes {
err := os.Remove(path.Join(config.Config.LocalFstoreDir, fh))
if err != nil {
logger.Errorf(err.Error())
}
}
}
}
示例4: ProcessQueue
// ProcessQueue creates a consumer queue on the given connection using the
// supplied exchange, exchange type, queue pattern, and number of workers. A
// function that satisfies the PayloadProcessor function type is also passed in
// to process the jobs off the queue, and if the payload processor should
// publish the results of its work a Publisher may be supplied. Otherwise nil
// for the Publisher is fine.
func ProcessQueue(conn *amqp.Connection, exchange, exchangeType, queueName, queuePattern string, durable, autoDelete, exclusive bool, errCh chan<- error, qprocessor PayloadProcessor, numWorkers int) error {
if numWorkers < 1 {
err := errors.New("numWorkers must be at least 1")
return err
}
for i := 0; i < numWorkers; i++ {
devs, err := CreateConsumer(conn, exchange, exchangeType, queueName, queuePattern, durable, autoDelete, exclusive)
if err != nil {
return nil
}
logger.Infof("starting queue %s for %s", exchange, queuePattern)
go func(i int, exchange string, devs <-chan amqp.Delivery) {
for d := range devs {
logger.Debugf("worker %s %d received delivery", exchange, i)
err := qprocessor(&d)
if err != nil {
errCh <- err
return
}
}
errCh <- nil
}(i, exchange, devs)
}
return nil
}
示例5: NewKairosdb
func NewKairosdb(host string) (*Kairosdb, error) {
logger.Debugf("initializing kairosdb client to %s", host)
return &Kairosdb{
client: &http.Client{Timeout: (10 * time.Second)},
host: host,
}, nil
}
示例6: GetStreamOutput
// GetStreamOutput gets all ShoveyRunStream objects associated with a ShoveyRun
// of the given output type.
func (sr *ShoveyRun) GetStreamOutput(outputType string, seq int) ([]*ShoveyRunStream, util.Gerror) {
if config.UsingDB() {
return sr.getStreamOutSQL(outputType, seq)
}
var streams []*ShoveyRunStream
ds := datastore.New()
for i := seq; ; i++ {
logger.Debugf("Getting %s", fmt.Sprintf("%s_%s_%s_%d", sr.ShoveyUUID, sr.NodeName, outputType, i))
s, found := ds.Get("shovey_run_stream", fmt.Sprintf("%s_%s_%s_%d", sr.ShoveyUUID, sr.NodeName, outputType, i))
if !found {
break
}
logger.Debugf("got a stream: %v", s)
streams = append(streams, s.(*ShoveyRunStream))
}
return streams, nil
}
示例7: indexMetric
func (m *MetricDefinition) indexMetric() error {
resp, err := es.Index("definitions", "metric", m.Id, nil, m)
logger.Debugf("response ok? %v", resp.Ok)
if err != nil {
return err
}
return nil
}
示例8: LogEvent
// LogEvent writes an event of the action type, performed by the given actor,
// against the given object.
func LogEvent(doer actor.Actor, obj util.GoiardiObj, action string) error {
if !config.Config.LogEvents {
logger.Debugf("Not logging this event")
return nil
}
logger.Debugf("Logging event")
var actorType string
if doer.IsUser() {
actorType = "user"
} else {
actorType = "client"
}
le := new(LogInfo)
le.Action = action
le.Actor = doer
le.ActorType = actorType
le.ObjectName = obj.GetName()
le.ObjectType = reflect.TypeOf(obj).String()
le.Time = time.Now()
extInfo, err := datastore.EncodeToJSON(obj)
if err != nil {
return err
}
le.ExtendedInfo = extInfo
actorInfo, err := datastore.EncodeToJSON(doer)
if err != nil {
return err
}
le.ActorInfo = actorInfo
if config.Config.SerfEventAnnounce {
qle := make(map[string]interface{}, 4)
qle["time"] = le.Time
qle["action"] = le.Action
qle["object_type"] = le.ObjectType
qle["object_name"] = le.ObjectName
go serfin.SendEvent("log-event", qle)
}
if config.UsingDB() {
return le.writeEventSQL()
}
return le.writeEventInMem()
}
示例9: UpdateDefCache
func (mdc *MetricDefCache) UpdateDefCache(mdef *MetricDefinition) error {
mdc.m.Lock()
defer mdc.m.Unlock()
md, ok := mdc.mdefs[mdef.Id]
if ok {
md.Lock()
defer md.Unlock()
logger.Debugf("metric %s found", mdef.Id)
if md.Def.LastUpdate >= mdef.LastUpdate {
logger.Debugf("%s is already up to date", mdef.Id)
return nil
}
mdc.mdefs[mdef.Id] = &MetricCacheItem{Def: mdef}
} else {
mdc.mdefs[mdef.Id] = &MetricCacheItem{Def: mdef}
}
return nil
}
示例10: NewFromMessage
func NewFromMessage(m *IndvMetric) (*MetricDefinition, error) {
logger.Debugf("incoming message: %+v", m)
id := m.Id
now := time.Now().Unix()
var ka int
switch k := m.Extra["keepAlives"].(type) {
case float64:
ka = int(k)
}
var state int8
switch s := m.Extra["state"].(type) {
case float64:
state = int8(s)
}
// input is now validated by json unmarshal
def := &MetricDefinition{Id: id,
Name: m.Name,
OrgId: m.OrgId,
Metric: m.Metric,
TargetType: m.TargetType,
Interval: m.Interval,
LastUpdate: now,
KeepAlives: ka,
State: state,
Unit: m.Unit,
Extra: m.Extra,
}
if t, exists := m.Extra["thresholds"]; exists {
thresh, _ := t.(map[string]interface{})
for k, v := range thresh {
switch k {
case "warnMin":
def.Thresholds.WarnMin = int(v.(float64))
case "warnMax":
def.Thresholds.WarnMax = int(v.(float64))
case "critMin":
def.Thresholds.CritMin = int(v.(float64))
case "critMax":
def.Thresholds.CritMax = int(v.(float64))
}
}
}
err := def.Save()
if err != nil {
return nil, err
}
return def, nil
}
示例11: searchTextCollection
func (ic *IdxCollection) searchTextCollection(term string, notop bool) (map[string]Document, error) {
results := make(map[string]Document)
ic.m.RLock()
defer ic.m.RUnlock()
l := len(ic.docs)
errCh := make(chan error, l)
resCh := make(chan *searchRes, l)
for k, v := range ic.docs {
go func(k string, v *IdxDoc) {
m, err := v.TextSearch(term)
if err != nil {
errCh <- err
resCh <- nil
} else {
errCh <- nil
if (m && !notop) || (!m && notop) {
r := &searchRes{k, v}
logger.Debugf("Adding result %s to channel", k)
resCh <- r
} else {
resCh <- nil
}
}
}(k, v)
}
for i := 0; i < l; i++ {
e := <-errCh
if e != nil {
return nil, e
}
}
for i := 0; i < l; i++ {
r := <-resCh
if r != nil {
logger.Debugf("adding result")
results[r.key] = Document(r.doc)
}
}
rsafe := safeSearchResults(results)
return rsafe, nil
}
示例12: searchRange
func (ic *IdxCollection) searchRange(field string, start string, end string, inclusive bool) (map[string]Document, error) {
results := make(map[string]Document)
ic.m.RLock()
defer ic.m.RUnlock()
l := len(ic.docs)
errCh := make(chan error, l)
resCh := make(chan *searchRes, l)
for k, v := range ic.docs {
go func(k string, v *IdxDoc) {
m, err := v.RangeSearch(field, start, end, inclusive)
if err != nil {
errCh <- err
resCh <- nil
} else {
errCh <- nil
if m {
r := &searchRes{k, v}
logger.Debugf("Adding result %s to channel", k)
resCh <- r
} else {
resCh <- nil
}
}
}(k, v)
}
for i := 0; i < l; i++ {
e := <-errCh
if e != nil {
return nil, e
}
}
for i := 0; i < l; i++ {
r := <-resCh
if r != nil {
logger.Debugf("adding result")
results[r.key] = Document(r.doc)
}
}
rsafe := safeSearchResults(results)
return rsafe, nil
}
示例13: SendEvent
// SendEvent sends a serf event out from goiardi.
func SendEvent(eventName string, payload interface{}) {
jsonPayload, err := json.Marshal(payload)
if err != nil {
logger.Errorf(err.Error())
return
}
err = Serfer.UserEvent(eventName, jsonPayload, true)
if err != nil {
logger.Debugf(err.Error())
}
return
}
示例14: GetMetricDefinition
func GetMetricDefinition(id string) (*MetricDefinition, error) {
// TODO: fetch from redis before checking elasticsearch
if v, err := rs.Get(id).Result(); err != nil && err != redis.Nil {
logger.Errorf("the redis client bombed: %s", err.Error())
return nil, err
} else if err == nil {
logger.Debugf("json for %s found in elasticsearch: %s", id)
def, err := DefFromJSON([]byte(v))
if err != nil {
return nil, err
}
return def, nil
}
logger.Debugf("getting %s from elasticsearch", id)
res, err := es.Get("definitions", "metric", id, nil)
logger.Debugf("res is: %+v", res)
if err != nil {
return nil, err
}
logger.Debugf("get returned %q", res.Source)
logger.Debugf("placing %s into redis", id)
if rerr := rs.SetEx(id, time.Duration(300)*time.Second, string(*res.Source)).Err(); err != nil {
logger.Debugf("redis err: %s", rerr.Error())
}
def, err := DefFromJSON(*res.Source)
if err != nil {
return nil, err
}
return def, nil
}
示例15: SendQuery
// SendQuery sends a basic, no frills query out over serf.
func SendQuery(queryName string, payload interface{}) {
jsonPayload, err := json.Marshal(payload)
if err != nil {
logger.Errorf(err.Error())
return
}
q := &serfclient.QueryParam{Name: queryName, Payload: jsonPayload}
err = Serfer.Query(q)
if err != nil {
logger.Debugf(err.Error())
}
return
}