mirror of
https://github.com/openfaas/faas.git
synced 2025-06-15 11:46:46 +00:00
Extract magic variables for server
This commit is contained in:
parent
0b2d3ea6c0
commit
968002c15f
@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
// AttachSwarmWatcher adds a go-route to monitor the amount of service replicas in the swarm
|
// AttachSwarmWatcher adds a go-route to monitor the amount of service replicas in the swarm
|
||||||
// matching a 'function' label.
|
// matching a 'function' label.
|
||||||
func AttachSwarmWatcher(dockerClient *client.Client, metricsOptions MetricOptions) {
|
func AttachSwarmWatcher(dockerClient *client.Client, metricsOptions MetricOptions, label string) {
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ func AttachSwarmWatcher(dockerClient *client.Client, metricsOptions MetricOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
if len(service.Spec.TaskTemplate.ContainerSpec.Labels["function"]) > 0 {
|
if len(service.Spec.TaskTemplate.ContainerSpec.Labels[label]) > 0 {
|
||||||
metricsOptions.ServiceReplicasCounter.
|
metricsOptions.ServiceReplicasCounter.
|
||||||
WithLabelValues(service.Spec.Name).
|
WithLabelValues(service.Spec.Name).
|
||||||
Set(float64(*service.Spec.Mode.Replicated.Replicas))
|
Set(float64(*service.Spec.Mode.Replicated.Replicas))
|
||||||
|
@ -11,6 +11,8 @@ import (
|
|||||||
"github.com/alexellis/faas/gateway/metrics"
|
"github.com/alexellis/faas/gateway/metrics"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,15 +54,22 @@ func main() {
|
|||||||
|
|
||||||
metricsHandler := metrics.PrometheusHandler()
|
metricsHandler := metrics.PrometheusHandler()
|
||||||
r.Handle("/metrics", metricsHandler)
|
r.Handle("/metrics", metricsHandler)
|
||||||
metrics.AttachSwarmWatcher(dockerClient, metricsOptions)
|
|
||||||
|
// This could exist in a separate process - records the replicas of each swarm service.
|
||||||
|
functionLabel := "function"
|
||||||
|
metrics.AttachSwarmWatcher(dockerClient, metricsOptions, functionLabel)
|
||||||
|
|
||||||
r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods("GET")
|
r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods("GET")
|
||||||
|
|
||||||
|
readTimeout := 8 * time.Second
|
||||||
|
writeTimeout := 8 * time.Second
|
||||||
|
tcpPort := 8080
|
||||||
|
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: ":8080",
|
Addr: fmt.Sprintf(":%d", tcpPort),
|
||||||
ReadTimeout: 8 * time.Second,
|
ReadTimeout: readTimeout,
|
||||||
WriteTimeout: 8 * time.Second,
|
WriteTimeout: writeTimeout,
|
||||||
MaxHeaderBytes: 1 << 20,
|
MaxHeaderBytes: http.DefaultMaxHeaderBytes, // 1MB - can be overridden by setting Server.MaxHeaderBytes.
|
||||||
Handler: r,
|
Handler: r,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user