diff --git a/config.go b/config.go
index c31d8c0..1ea818d 100644
--- a/config.go
+++ b/config.go
@@ -7,7 +7,6 @@ import (
"reflect"
"regexp"
- // "html/template"
"net/url"
"os"
"path/filepath"
@@ -15,9 +14,6 @@ import (
"text/template"
"time"
- // "github.com/Masterminds/sprig/v3"
- // "github.com/go-kit/log"
- // "github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v3"
@@ -276,7 +272,7 @@ func (c *Config) YAML() ([]byte, error) {
return yaml.Marshal(dc)
}
-// YAML marshals the config into YAML format.
+// JSON marshals the config into JSON format.
func (c *Config) JSON() ([]byte, error) {
type fullConf struct {
Config *dumpConfig `json:"config"`
diff --git a/content.go b/content.go
index aa9d28a..3cdde87 100644
--- a/content.go
+++ b/content.go
@@ -43,7 +43,7 @@ const (
-
+
@@ -178,6 +178,7 @@ func HomeHandlerFunc(metricsPath string, exporter Exporter) func(http.ResponseWr
})
}
}
+
func HealthHandlerfunc(metricsPath string, exporter Exporter) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
var status []byte
@@ -318,7 +319,6 @@ func LogLevelHandlerFunc(metricsPath string, exporter Exporter, reloadCh chan<-
return
}
}
-
}
// StatusHandlerFunc is the HTTP handler for the `/status` page. It outputs the status of exporter.
@@ -335,6 +335,7 @@ func StatusHandlerFunc(metricsPath string, exporter Exporter) func(http.Response
StartTime: exporter.GetStartTime(),
ReloadTime: exporter.GetReloadTime(),
}
+
accept_type := r.Header.Get(acceptHeader)
if strings.Contains(accept_type, applicationJSON) {
res, err := json.Marshal(vinfos)
diff --git a/promhttp.go b/promhttp.go
index a81b264..4f8552b 100644
--- a/promhttp.go
+++ b/promhttp.go
@@ -36,19 +36,18 @@ func ExporterHandlerFor(exporter Exporter) http.Handler {
target Target
tmp_t *TargetConfig
)
- params := req.URL.Query()
- tname := params.Get("target")
- if tname == "" {
+ params := req.URL.Query()
+ tname := strings.TrimSpace(params.Get("target"))
+ if tname == "" || tname == "template" {
err := errors.New("Target parameter is missing")
HandleError(http.StatusBadRequest, err, *metricsPath, exporter, w, req)
return
}
- tname = strings.TrimSpace(tname)
+
target, err = exporter.FindTarget(tname)
if err == ErrTargetNotFound {
- model := params.Get("model")
- model = strings.TrimSpace(model)
+ model := strings.TrimSpace(params.Get("model"))
if model == "" {
model = "default"
}
@@ -120,7 +119,7 @@ func ExporterHandlerFor(exporter Exporter) http.Handler {
if err := enc.Encode(mf); err != nil {
errs = append(errs, err)
exporter.Logger().Info(
- fmt.Sprintf("Error encoding metric family %q: %s", mf.GetName(), err))
+ fmt.Sprintf("Error encoding metric family %q: %s", mf.GetName(), err.Error()))
}
}
if closer, ok := writer.(io.Closer); ok {
@@ -149,7 +148,7 @@ func contextFor(req *http.Request, exporter Exporter, target Target) (context.Co
timeoutSeconds, err := strconv.ParseFloat(v, 64)
if err != nil {
exporter.Logger().Error(
- fmt.Sprintf("Failed to parse timeout (`%s`) from Prometheus header: %s", v, err))
+ fmt.Sprintf("Failed to parse timeout (`%s`) from Prometheus header: %s", v, err.Error()))
} else {
timeout = time.Duration(timeoutSeconds * float64(time.Second))