Skip to content

Commit b5aa95d

Browse files
committed
Refactor prometheus registry setup.
1 parent 1a5bbe6 commit b5aa95d

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

internal/mtail/mtail.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,7 @@ func (m *Server) initExporter() (err error) {
157157
if err != nil {
158158
return err
159159
}
160-
161-
expvarDescs := map[string]*prometheus.Desc{
162-
// internal/tailer/file.go
163-
"log_errors_total": prometheus.NewDesc("log_errors_total", "number of IO errors encountered per log file", []string{"logfile"}, nil),
164-
"log_rotations_total": prometheus.NewDesc("log_rotations_total", "number of log rotation events per log file", []string{"logfile"}, nil),
165-
"log_truncates_total": prometheus.NewDesc("log_truncates_total", "number of log truncation events log file", []string{"logfile"}, nil),
166-
"log_lines_total": prometheus.NewDesc("log_lines_total", "number of lines read per log file", []string{"logfile"}, nil),
167-
// internal/vm/loader.go
168-
"line_count": prometheus.NewDesc("line_count", "number of lines received by the program loader", nil, nil),
169-
"prog_loads_total": prometheus.NewDesc("prog_loads_total", "number of program load events by program source filename", []string{"prog"}, nil),
170-
"prog_load_errors": prometheus.NewDesc("prog_load_errors", "number of errors encountered when loading per program source filename", []string{"prog"}, nil),
171-
"prog_runtime_errors": prometheus.NewDesc("prog_runtime_errors", "number of errors encountered when executing programs per source filename", []string{"prog"}, nil),
172-
// internal/watcher/log_watcher.go
173-
"log_watcher_error_count": prometheus.NewDesc("log_watcher_error_count", "number of errors received from fsnotify", nil, nil),
174-
}
175-
m.reg.MustRegister(m.e,
176-
prometheus.NewGoCollector(),
177-
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
178-
// Prefix all expvar metrics with 'mtail_'
179-
prometheus.WrapRegistererWithPrefix("mtail_", m.reg).MustRegister(
180-
prometheus.NewExpvarCollector(expvarDescs))
160+
m.reg.MustRegister(m.e)
181161

182162
// Create mtail_build_info metric.
183163
version.Branch = m.buildInfo.Branch
@@ -251,6 +231,27 @@ func New(store *metrics.Store, w watcher.Watcher, options ...func(*Server) error
251231
// are not fully specified at startup.
252232
reg: prometheus.NewRegistry(),
253233
}
234+
235+
expvarDescs := map[string]*prometheus.Desc{
236+
// internal/tailer/file.go
237+
"log_errors_total": prometheus.NewDesc("log_errors_total", "number of IO errors encountered per log file", []string{"logfile"}, nil),
238+
"log_rotations_total": prometheus.NewDesc("log_rotations_total", "number of log rotation events per log file", []string{"logfile"}, nil),
239+
"log_truncates_total": prometheus.NewDesc("log_truncates_total", "number of log truncation events log file", []string{"logfile"}, nil),
240+
"log_lines_total": prometheus.NewDesc("log_lines_total", "number of lines read per log file", []string{"logfile"}, nil),
241+
// internal/vm/loader.go
242+
"line_count": prometheus.NewDesc("line_count", "number of lines received by the program loader", nil, nil),
243+
"prog_loads_total": prometheus.NewDesc("prog_loads_total", "number of program load events by program source filename", []string{"prog"}, nil),
244+
"prog_load_errors": prometheus.NewDesc("prog_load_errors", "number of errors encountered when loading per program source filename", []string{"prog"}, nil),
245+
"prog_runtime_errors": prometheus.NewDesc("prog_runtime_errors", "number of errors encountered when executing programs per source filename", []string{"prog"}, nil),
246+
// internal/watcher/log_watcher.go
247+
"log_watcher_error_count": prometheus.NewDesc("log_watcher_error_count", "number of errors received from fsnotify", nil, nil),
248+
}
249+
m.reg.MustRegister(
250+
prometheus.NewGoCollector(),
251+
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
252+
// Prefix all expvar metrics with 'mtail_'
253+
prometheus.WrapRegistererWithPrefix("mtail_", m.reg).MustRegister(
254+
prometheus.NewExpvarCollector(expvarDescs))
254255
if err := m.SetOption(options...); err != nil {
255256
return nil, err
256257
}

0 commit comments

Comments
 (0)