MCPcopy Index your code
hub / github.com/google/mtail / WriteStatusHTML

Method WriteStatusHTML

internal/tailer/httpstatus.go:44–84  ·  view source on GitHub ↗

WriteStatusHTML emits the Tailer's state in HTML format to the io.Writer w.

(w io.Writer)

Source from the content-addressed store, hash-verified

42
43// WriteStatusHTML emits the Tailer's state in HTML format to the io.Writer w.
44func (t *Tailer) WriteStatusHTML(w io.Writer) error {
45 tpl, err := template.New("tailer").Parse(tailerTemplate)
46 if err != nil {
47 return err
48 }
49 t.logstreamsMu.RLock()
50 defer t.logstreamsMu.RUnlock()
51 t.globPatternsMu.RLock()
52 defer t.globPatternsMu.RUnlock()
53 data := struct {
54 LogStreams map[string]logstream.LogStream
55 Patterns map[string]struct{}
56 Opens map[string]string
57 Lines map[string]string
58 Errors map[string]string
59 Truncs map[string]string
60 }{
61 t.logstreams,
62 t.globPatterns,
63 make(map[string]string),
64 make(map[string]string),
65 make(map[string]string),
66 make(map[string]string),
67 }
68 for _, pair := range []struct {
69 k string
70 m map[string]string
71 }{
72 {"log_errors_total", data.Errors},
73 {"log_opens_total", data.Opens},
74 {"file_truncates_total", data.Truncs},
75 {"log_lines_total", data.Lines},
76 } {
77 pair := pair
78 v := expvar.Get(pair.k).(*expvar.Map)
79 v.Do(func(kv expvar.KeyValue) {
80 pair.m[kv.Key] = kv.Value.String()
81 })
82 }
83 return tpl.Execute(w, data)
84}

Callers 1

ServeHTTPMethod · 0.45

Calls 3

ParseMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected