Merge pull request #23 from kumina/kingpin_update
Refactored to kingpin and bugfix.
This commit is contained in:
commit
623a840f32
@ -3,14 +3,19 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "io"
|
import(
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/alecthomas/kingpin"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
type Journal struct {
|
type Journal struct {
|
||||||
io.Closer
|
io.Closer
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func systemdFlags(enable *bool, unit, slice, path *string) {}
|
func systemdFlags(enable *bool, unit, slice, path *string, app *kingpin.Application) {}
|
||||||
|
|
||||||
func NewJournal(unit, slice, path string) (*Journal, error) {
|
func NewJournal(unit, slice, path string) (*Journal, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/alecthomas/kingpin"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@ -238,11 +238,11 @@ func CollectBinaryShowqFromReader(file io.Reader, ch chan<- prometheus.Metric) e
|
|||||||
sizeHistogram.WithLabelValues(queue).Observe(size)
|
sizeHistogram.WithLabelValues(queue).Observe(size)
|
||||||
} else if key == "time" {
|
} else if key == "time" {
|
||||||
// Message time as a UNIX timestamp.
|
// Message time as a UNIX timestamp.
|
||||||
time, err := strconv.ParseFloat(value, 64)
|
utime, err := strconv.ParseFloat(value, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ageHistogram.WithLabelValues(queue).Observe(now - time)
|
ageHistogram.WithLabelValues(queue).Observe(now - utime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,16 +663,17 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
listenAddress = flag.String("web.listen-address", ":9154", "Address to listen on for web interface and telemetry.")
|
app = kingpin.New("postfix_exporter", "Prometheus metrics exporter for postfix")
|
||||||
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
|
listenAddress = app.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9154").String()
|
||||||
postfixShowqPath = flag.String("postfix.showq_path", "/var/spool/postfix/public/showq", "Path at which Postfix places its showq socket.")
|
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
|
||||||
postfixLogfilePath = flag.String("postfix.logfile_path", "/var/log/postfix_exporter_input.log", "Path where Postfix writes log entries. This file will be truncated by this exporter.")
|
postfixShowqPath = app.Flag("postfix.showq_path", "Path at which Postfix places its showq socket.").Default("/var/spool/postfix/public/showq").String()
|
||||||
|
postfixLogfilePath = app.Flag("postfix.logfile_path", "Path where Postfix writes log entries. This file will be truncated by this exporter.").Default("/var/log/postfix_exporter_input.log").String()
|
||||||
systemdEnable bool
|
systemdEnable bool
|
||||||
systemdUnit, systemdSlice, systemdJournalPath string
|
systemdUnit, systemdSlice, systemdJournalPath string
|
||||||
)
|
)
|
||||||
systemdFlags(&systemdEnable, &systemdUnit, &systemdSlice, &systemdJournalPath)
|
systemdFlags(&systemdEnable, &systemdUnit, &systemdSlice, &systemdJournalPath, app)
|
||||||
flag.Parse()
|
|
||||||
|
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||||
|
|
||||||
var journal *Journal
|
var journal *Journal
|
||||||
if systemdEnable {
|
if systemdEnable {
|
||||||
|
12
systemd.go
12
systemd.go
@ -3,12 +3,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/alecthomas/kingpin"
|
||||||
"github.com/coreos/go-systemd/sdjournal"
|
"github.com/coreos/go-systemd/sdjournal"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -88,11 +88,11 @@ func (j *Journal) NextMessage() (s string, c uint64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// systemdFlags sets the flags for use with systemd
|
// systemdFlags sets the flags for use with systemd
|
||||||
func systemdFlags(enable *bool, unit, slice, path *string) {
|
func systemdFlags(enable *bool, unit, slice, path *string, app *kingpin.Application) {
|
||||||
flag.BoolVar(enable, "systemd.enable", false, "Read from the systemd journal instead of log")
|
app.Flag("systemd.enable", "Read from the systemd journal instead of log").Default("false").BoolVar(enable)
|
||||||
flag.StringVar(unit, "systemd.unit", "postfix.service", "Name of the Postfix systemd unit.")
|
app.Flag("systemd.unit", "Name of the Postfix systemd unit.").Default("postfix.service").StringVar(unit)
|
||||||
flag.StringVar(slice, "systemd.slice", "", "Name of the Postfix systemd slice. Overrides the systemd unit.")
|
app.Flag("systemd.slice", "Name of the Postfix systemd slice. Overrides the systemd unit.").Default("").StringVar(slice)
|
||||||
flag.StringVar(path, "systemd.journal_path", "", "Path to the systemd journal")
|
app.Flag("systemd.journal_path", "Path to the systemd journal").Default("").StringVar(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectLogfileFromJournal Collects entries from the systemd journal.
|
// CollectLogfileFromJournal Collects entries from the systemd journal.
|
||||||
|
Loading…
Reference in New Issue
Block a user