forked from argoproj/argo-cd
-
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.
feat: add redis metrics to application controller and api server (arg…
…oproj#3500) * add redis metrics to application controller and api server * fix failed test
- Loading branch information
Alexander Matyushentsev
authored
Apr 28, 2020
1 parent
14f1725
commit 842a3d1
Showing
5 changed files
with
96 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package metrics | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
type MetricsServer struct { | ||
*http.Server | ||
redisRequestCounter *prometheus.CounterVec | ||
} | ||
|
||
var ( | ||
redisRequestCounter = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "argocd_redis_request_total", | ||
Help: "Number of kubernetes requests executed during application reconciliation.", | ||
}, | ||
[]string{"initiator", "failed"}, | ||
) | ||
) | ||
|
||
// NewMetricsServer returns a new prometheus server which collects api server metrics | ||
func NewMetricsServer(port int) *MetricsServer { | ||
mux := http.NewServeMux() | ||
registry := prometheus.NewRegistry() | ||
mux.Handle("/metrics", promhttp.HandlerFor(prometheus.Gatherers{ | ||
registry, | ||
prometheus.DefaultGatherer, | ||
}, promhttp.HandlerOpts{})) | ||
|
||
registry.MustRegister(redisRequestCounter) | ||
|
||
return &MetricsServer{ | ||
Server: &http.Server{ | ||
Addr: fmt.Sprintf("0.0.0.0:%d", port), | ||
Handler: mux, | ||
}, | ||
redisRequestCounter: redisRequestCounter, | ||
} | ||
} | ||
|
||
func (m *MetricsServer) IncRedisRequest(failed bool) { | ||
m.redisRequestCounter.WithLabelValues("argocd-server", strconv.FormatBool(failed)).Inc() | ||
} |
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