-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ashleyprimo/v1.2.0-dev
Mini Refactor: * Allows metrics to be served on a separate socket/webserver endpoint * `address` changes to `host` * Code Tidy
- Loading branch information
Showing
10 changed files
with
150 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
|
||
"github.com/ashleyprimo/go-qr-generator/initialize" | ||
"github.com/ashleyprimo/go-qr-generator/initialize" | ||
) | ||
|
||
var ( | ||
versionExport = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: initialize.MetricNamespace, | ||
Name: "version", | ||
Help: "current running version", | ||
versionExport = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: initialize.MetricNamespace, | ||
Name: "version", | ||
Help: "current running version", | ||
ConstLabels: map[string]string{ | ||
"version": initialize.Version, | ||
}, | ||
}, | ||
) | ||
}, | ||
) | ||
) | ||
|
||
func metrics() { | ||
// Metrics Endpoint | ||
if *initialize.EnableMetrics { | ||
log.Debugf("Metrics Endpoint Enabled") | ||
if *initialize.MetricServer { | ||
log.Debugf("Metrics Server Enabled") | ||
log.Infof("Listening for metrics requests on %s:%s", *initialize.MetricServerHost, *initialize.MetricServerPort) | ||
go func() { | ||
mux := http.NewServeMux() | ||
mux.Handle("/metrics", promhttp.Handler()) | ||
srv := &http.Server{ | ||
Addr: fmt.Sprintf("%s:%s", *initialize.MetricServerHost, *initialize.MetricServerPort), | ||
Handler: mux, | ||
ReadTimeout: 30 * time.Second, | ||
WriteTimeout: 30 * time.Second, | ||
IdleTimeout: 3 * time.Minute, | ||
} | ||
log.Fatalf("Failed to start web server: %s", srv.ListenAndServe()) | ||
}() | ||
|
||
} else { | ||
http.Handle("/metrics", promhttp.Handler()) | ||
} | ||
} | ||
} |
Oops, something went wrong.