Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
140 additions
and
110 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,41 @@ | ||
package metrics | ||
|
||
type Counter interface { | ||
Add(v float64) | ||
} | ||
|
||
type Gauge interface { | ||
Counter | ||
} | ||
|
||
type Observer interface { | ||
Observe(v float64) | ||
} | ||
|
||
var ( | ||
_ Counter = noop{} | ||
_ Gauge = noop{} | ||
_ Observer = noop{} | ||
) | ||
|
||
type noop struct{} | ||
|
||
func (noop) Add(v float64) {} | ||
func (noop) Observe(v float64) {} | ||
|
||
func ListenAndServe(addr string) error { | ||
return listenAndServe(addr) | ||
} | ||
|
||
var ( | ||
ConnAccepted Counter = noop{} | ||
ConnError Counter = noop{} | ||
ConnOpen Gauge = noop{} | ||
ConnInsecure Counter = noop{} | ||
ConnOpenInsecure Gauge = noop{} | ||
ConnTLS Counter = noop{} | ||
ConnOpenTLS Gauge = noop{} | ||
ConnTLSHandshake Observer = noop{} | ||
ConnRx Counter = noop{} | ||
ConnTx Counter = noop{} | ||
) |
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,7 @@ | ||
// +build !metrics | ||
|
||
package metrics | ||
|
||
func listenAndServe(addr string) error { | ||
return nil | ||
} |
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,58 @@ | ||
// +build metrics | ||
|
||
package metrics | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
func listenAndServe(addr string) error { | ||
return http.ListenAndServe(addr, promhttp.Handler()) | ||
} | ||
|
||
func init() { | ||
ConnAccepted = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_accepted", | ||
Help: "The total number of accepted connections", | ||
}) | ||
ConnError = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_error", | ||
Help: "The total number of connections failed with an error", | ||
}) | ||
ConnOpen = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "dc_conn_open", | ||
Help: "The number of open connections", | ||
}) | ||
ConnInsecure = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_insecure", | ||
Help: "The total number of insecure connections", | ||
}) | ||
ConnOpenInsecure = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "dc_conn_insecure_open", | ||
Help: "The number of open insecure connections", | ||
}) | ||
ConnTLS = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_tls", | ||
Help: "The total number of TLS connections", | ||
}) | ||
ConnOpenTLS = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "dc_conn_tls_open", | ||
Help: "The number of open TLS connections", | ||
}) | ||
ConnTLSHandshake = promauto.NewHistogram(prometheus.HistogramOpts{ | ||
Name: "dc_conn_tls_handshake_sec", | ||
Help: "Time spent on TLS handshake", | ||
}) | ||
ConnRx = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_rx_bytes", | ||
Help: "Total bytes received from the client", | ||
}) | ||
ConnTx = promauto.NewCounter(prometheus.CounterOpts{ | ||
Name: "dc_conn_tx_bytes", | ||
Help: "Total bytes sent to the client", | ||
}) | ||
} |
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