mirror of
https://github.com/prometheus-community/json_exporter
synced 2025-04-27 05:18:40 +00:00
Fix review comments
Signed-off-by: rustyclock <rustyclock@protonmail.com>
This commit is contained in:
parent
014e2df99b
commit
9a50f9d6ec
@ -34,7 +34,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
configFile = kingpin.Flag("config.file", "JSON exporter configuration file.").Default("config.yml").ExistingFile()
|
configFile = kingpin.Flag("config.file", "JSON exporter configuration file.").Default("config.yml").ExistingFile()
|
||||||
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":7979").String()
|
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":7979").String()
|
||||||
configCheck = kingpin.Flag("config.check", "If true validate the config file and then exit.").Default().Bool()
|
configCheck = kingpin.Flag("config.check", "If true validate the config file and then exit.").Default("false").Bool()
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
@ -58,7 +58,7 @@ func Run() {
|
|||||||
}
|
}
|
||||||
configJson, err := json.Marshal(config)
|
configJson, err := json.Marshal(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err) //nolint:errcheck
|
level.Error(logger).Log("msg", "Failed to marshal config to JSON", "err", err) //nolint:errcheck
|
||||||
}
|
}
|
||||||
level.Info(logger).Log("msg", "Loaded config file", "config", string(configJson)) //nolint:errcheck
|
level.Info(logger).Log("msg", "Loaded config file", "config", string(configJson)) //nolint:errcheck
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ func Run() {
|
|||||||
probeHandler(w, req, logger, config)
|
probeHandler(w, req, logger, config)
|
||||||
})
|
})
|
||||||
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
|
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
|
||||||
level.Error(logger).Log("msg", "failed to start the server", "err", err) //nolint:errcheck
|
level.Error(logger).Log("msg", "Failed to start the server", "err", err) //nolint:errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,6 @@ func LoadConfig(configPath string) (Config, error) {
|
|||||||
for i := 0; i < len(config.Metrics); i++ {
|
for i := 0; i < len(config.Metrics); i++ {
|
||||||
if config.Metrics[i].Type == "" {
|
if config.Metrics[i].Type == "" {
|
||||||
config.Metrics[i].Type = ValueScrape
|
config.Metrics[i].Type = ValueScrape
|
||||||
//config.Metrics[i].Type = "DefaultScrapeType"
|
|
||||||
}
|
}
|
||||||
if config.Metrics[i].Help == "" {
|
if config.Metrics[i].Help == "" {
|
||||||
config.Metrics[i].Help = config.Metrics[i].Name
|
config.Metrics[i].Help = config.Metrics[i].Name
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -66,7 +67,7 @@ func SanitizeValue(v *jsonpath.Result) (float64, error) {
|
|||||||
func parseValue(bytes []byte) (float64, error) {
|
func parseValue(bytes []byte) (float64, error) {
|
||||||
value, err := strconv.ParseFloat(string(bytes), 64)
|
value, err := strconv.ParseFloat(string(bytes), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1.0, fmt.Errorf("failed to parse value as float;value:<%s>", bytes)
|
return -1.0, fmt.Errorf("failed to parse value as float; value: %q; err: %w", bytes, err)
|
||||||
}
|
}
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
@ -156,9 +157,13 @@ func FetchJson(ctx context.Context, logger log.Logger, endpoint string, config c
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
defer func() {
|
||||||
|
io.Copy(ioutil.Discard, resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
if resp.StatusCode/100 != 2 {
|
||||||
return nil, errors.New(resp.Status)
|
return nil, errors.New(resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user