Skip to content

Commit

Permalink
Improved publish debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
monicasarbu committed May 9, 2014
1 parent d18d64c commit 51122cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
4 changes: 4 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func DEBUG(selector string, format string, v ...interface{}) {
}
}

func IS_DEBUG(selector string) bool {
return _log.selectors[selector]
}

func INFO(format string, v ...interface{}) {
if _log.level >= syslog.LOG_INFO {
if _log.toSyslog {
Expand Down
47 changes: 35 additions & 12 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ type Topology struct {
Ip string `json:"ip"`
}

func PrintPublishEvent(event *Event) {
json, err := json.MarshalIndent(event, "", " ")
if err != nil {
ERR("json.Marshal: %s", err)
} else {
DEBUG("publish", "Publish: %s", string(json))
}
}

func (publisher *PublisherType) GetServerName(ip string) string {
// in case the IP is localhost, return current agent name
islocal, err := IsLoopback(ip)
Expand Down Expand Up @@ -109,14 +118,19 @@ func (publisher *PublisherType) PublishHttpTransaction(t *HttpTransaction) error
}
}

// add Http transaction
_, err := core.Index(index, "http", "", nil, Event{
event := Event{
t.ts, "http", t.Src.Ip, t.Src.Port, t.Src.Proc, src_country, src_server,
t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
t.ResponseTime, status, t.Request_raw, t.Response_raw,
nil, t.Http, nil})
nil, t.Http, nil}

if IS_DEBUG("publish") {
PrintPublishEvent(&event)
}

// add Http transaction
_, err := core.Index(index, "http", "", nil, event)

DEBUG("publish", "Sent Http transaction [%s->%s]:\n%s", t.Src.Proc, t.Dst.Proc, t.Http)
return err

}
Expand All @@ -136,14 +150,18 @@ func (publisher *PublisherType) PublishMysqlTransaction(t *MysqlTransaction) err
src_server := publisher.GetServerName(t.Src.Ip)
dst_server := publisher.GetServerName(t.Dst.Ip)

// add Mysql transaction
_, err := core.Index(index, "mysql", "", nil, Event{
event := Event{
t.ts, "mysql", t.Src.Ip, t.Src.Port, t.Src.Proc, "", src_server,
t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
t.ResponseTime, status, t.Request_raw, t.Response_raw,
t.Mysql, nil, nil})
t.Mysql, nil, nil}

DEBUG("publish", "Sent MySQL transaction [%s->%s]:\n%s", t.Src.Proc, t.Dst.Proc, t.Mysql)
if IS_DEBUG("publish") {
PrintPublishEvent(&event)
}

// add Mysql transaction
_, err := core.Index(index, "mysql", "", nil, event)

return err

Expand All @@ -161,14 +179,19 @@ func (publisher *PublisherType) PublishRedisTransaction(t *RedisTransaction) err
src_server := publisher.GetServerName(t.Src.Ip)
dst_server := publisher.GetServerName(t.Dst.Ip)

// add Redis transaction
_, err := core.Index(index, "redis", "", nil, Event{
event := Event{
t.ts, "redis", t.Src.Ip, t.Src.Port, t.Src.Proc, "", src_server,
t.Dst.Ip, t.Dst.Port, t.Dst.Proc, dst_server,
t.ResponseTime, status, t.Request_raw, t.Response_raw,
nil, nil, t.Redis})
nil, nil, t.Redis}

if IS_DEBUG("publish") {
PrintPublishEvent(&event)
}

// add Redis transaction
_, err := core.Index(index, "redis", "", nil, event)

DEBUG("publish", "Sent Redis transaction [%s->%s]:\n%s", t.Src.Proc, t.Dst.Proc, t.Redis)
return err

}
Expand Down

0 comments on commit 51122cc

Please sign in to comment.