func (w *PrometheusWriter) Close() error {
	logger.Debug.Printf("stopping HTTP server (%s)...\n", w.srv.Addr)
	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
	return w.srv.Shutdown(ctx)
}
Close close the metric writer
package writer
import (
	"context"
	"fmt"
	"net/http"
	"net/url"
	"strings"
	"time"
	"github.com/ncarlier/apimon/pkg/logger"
	"github.com/ncarlier/apimon/pkg/model"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)
var healthCheckStatusGauge = prometheus.NewGaugeVec(
	prometheus.GaugeOpts{
		Name: "http_health_check_status",
		Help: "HTTP health check status.",
	},
	[]string{"name"},
)
var healthCheckErrorCounter = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: "http_health_check_errors",
		Help: "HTTP health check errors.",
	},
	[]string{"name", "reason"},
)
var healthCheckResponseTimeGauge = prometheus.NewGaugeVec(
	prometheus.GaugeOpts{
		Name: "http_health_check_response_time",
		Help: "HTTP health check response time.",
	},
	[]string{"name"},
)
type PrometheusWriter struct {
	srv *http.Server
}
func newPrometheusWriter(uri string) (*PrometheusWriter, error) {
	u, err := url.ParseRequestURI(uri)
	if err != nil || u.Scheme != "http" {
		return nil, fmt.Errorf("invalid listen URL: %s", uri)
	}
	prometheus.MustRegister(healthCheckStatusGauge)
	prometheus.MustRegister(healthCheckResponseTimeGauge)
	prometheus.MustRegister(healthCheckErrorCounter)
	srv := &http.Server{Addr: u.Hostname() + ":" + u.Port()}
	http.Handle(u.Path, promhttp.Handler())
	go func() {
		logger.Debug.Printf("starting HTTP server (%s)...\n", srv.Addr)
		if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			logger.Error.Panicln("unable to create Prometheus server endpoint:", err)
		}
	}()
	return &PrometheusWriter{
		srv: srv,
	}, nil
}
func (w *PrometheusWriter) Write(metric model.Metric) error {
	duration := float64(metric.Duration / time.Millisecond)
	reason := ""
	if metric.Error != "" {
		reason = strings.SplitN(metric.Error, ":", 2)[0]
		reason = strings.ToLower(reason)
		healthCheckStatusGauge.With(prometheus.Labels{
			"name": metric.Name,
		}).Set(0)
		healthCheckErrorCounter.With(prometheus.Labels{
			"name":   metric.Name,
			"reason": reason,
		}).Inc()
	} else {
		healthCheckStatusGauge.With(prometheus.Labels{
			"name": metric.Name,
		}).Set(1)
	}
	healthCheckResponseTimeGauge.With(prometheus.Labels{
		"name": metric.Name,
	}).Set(duration)
	return nil
}