summaryrefslogtreecommitdiff
path: root/internal/io
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-02 10:46:47 +0300
committerPaul Buetow <paul@buetow.org>2021-10-02 12:26:36 +0300
commit764ef99a3d779a0db1fb60679292af52425ba2f6 (patch)
tree2547b3bd4472a4178173dfe1d8f4178af591c37e /internal/io
parent609921f9c783941eaa9019a92b78ec45b49d681c (diff)
add more default fields to MAPREDUCE
Diffstat (limited to 'internal/io')
-rw-r--r--internal/io/dlog/dlog.go38
-rw-r--r--internal/io/dlog/loggers/file.go1
2 files changed, 36 insertions, 3 deletions
diff --git a/internal/io/dlog/dlog.go b/internal/io/dlog/dlog.go
index 49533a5..bc9b2f8 100644
--- a/internal/io/dlog/dlog.go
+++ b/internal/io/dlog/dlog.go
@@ -3,7 +3,11 @@ package dlog
import (
"context"
"fmt"
+ "io/ioutil"
"os"
+ "path/filepath"
+ "runtime"
+ "strconv"
"strings"
"sync"
"time"
@@ -211,8 +215,38 @@ func (d *DLog) Raw(message string) string {
func (d *DLog) Mapreduce(table string, data map[string]interface{}) string {
args := make([]interface{}, len(data)+1)
- // TODO: mC compatible SERVER mapreduce fields, no MAPREDUCE keyword in CLIENT mode
- args[0] = fmt.Sprintf("%s:%s", "MAPREDUCE", strings.ToUpper(table))
+ if d.sourceProcess == SERVER {
+ // level|date-time|process|caller|cpus|goroutines|cgocalls|loadavg|uptime|MAPREDUCE:TABLE|key=value|...
+
+ var loadAvg string
+ if loadAvgBytes, err := ioutil.ReadFile("/proc/loadavg"); err == nil {
+ tmp := string(loadAvgBytes)
+ s := strings.SplitN(tmp, " ", 2)
+ loadAvg = s[0]
+ }
+
+ var uptime string
+ if uptimeBytes, err := ioutil.ReadFile("/proc/uptime"); err == nil {
+ tmp := string(uptimeBytes)
+ s := strings.SplitN(tmp, ".", 2)
+ i, _ := strconv.ParseInt(s[0], 10, 64)
+ t := time.Duration(i) * time.Second
+ uptime = fmt.Sprintf("%v", t)
+ }
+
+ _, file, line, _ := runtime.Caller(1)
+ args[0] = fmt.Sprintf("%d|%s:%d|%d|%d|%d|%s|%s|MAPREDUCE:%s",
+ os.Getpid(),
+ filepath.Base(file), line,
+ runtime.NumCPU(),
+ runtime.NumGoroutine(),
+ runtime.NumCgoCall(),
+ loadAvg,
+ uptime,
+ strings.ToUpper(table))
+ } else {
+ args[0] = fmt.Sprintf("STATS:%s", strings.ToUpper(table))
+ }
i := 1
for k, v := range data {
diff --git a/internal/io/dlog/loggers/file.go b/internal/io/dlog/loggers/file.go
index dcdd7d0..6e692a3 100644
--- a/internal/io/dlog/loggers/file.go
+++ b/internal/io/dlog/loggers/file.go
@@ -100,7 +100,6 @@ func (f *file) Pause() { f.pauseCh <- struct{}{} }
func (f *file) Resume() { f.resumeCh <- struct{}{} }
func (f *file) Flush() { f.flushCh <- struct{}{} }
-// TODO: Test that Rotate() actually works.
func (f *file) Rotate() { f.rotateCh <- struct{}{} }
func (*file) SupportsColors() bool { return false }