From 2b1aedb7a0f0406a5030e5d6a679a68f521d0990 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 12 Oct 2015 22:29:36 -0700 Subject: [PATCH] Add prometheus metric exporting. Wrap existing mailstore with prometheus monitoring one. Add flags for IMAP & HTTP listen addresses. --- cmd/ximap/ximap.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/cmd/ximap/ximap.go b/cmd/ximap/ximap.go index 0ac2dfe..d703c64 100644 --- a/cmd/ximap/ximap.go +++ b/cmd/ximap/ximap.go @@ -1,21 +1,41 @@ package main import ( + "flag" "fmt" + "net/http" "os" + xprometheus "xinu.tv/imapstore/prometheus" + + "github.com/golang/glog" "github.com/jordwest/imap-server" "github.com/jordwest/imap-server/mailstore" + "github.com/prometheus/client_golang/prometheus" +) + +var ( + imapAddr = flag.String("imap", ":10143", "listen address for IMAP") + httpAddr = flag.String("http", ":10080", "listen address for HTTP") ) func main() { - store := mailstore.NewDummyMailstore() + flag.Parse() + defer glog.Flush() + + http.Handle("/metrics", prometheus.Handler()) + go func() { + glog.Fatal(http.ListenAndServe(*httpAddr, nil)) + }() + + var store mailstore.Mailstore + store = mailstore.NewDummyMailstore() + store = xprometheus.NewMailstore(store) s := imap.NewServer(store) s.Transcript = os.Stdout - s.Addr = ":10143" + s.Addr = *imapAddr - err := s.ListenAndServe() - if err != nil { + if err := s.ListenAndServe(); err != nil { fmt.Printf("Error creating test connection: %s\n", err) } }