Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMetricsSnapshotLines ¶
func HTTPMetricsSnapshotLines() string
HTTPMetricsSnapshot returns all colleted metrics in metrics Line protocol format. https://github.com/influxdata/influxdb/blob/master/tsdb/README.md
func ServeMetrics ¶
ServeMetrics starts Http server to provide current metrics in influxdb line protocol format. It takes port number and path as input.: example ServeMetrics(8081, "/metrics").
Types ¶
type HTTPRequestStatFunc ¶
HTTPRequestStatFunc function type to collect HTTP request metrics. An application can implement this function to provide custom implementation of request metrics collection.
type HTTPResponseStatCollector ¶
type HTTPResponseStatCollector interface {
http.ResponseWriter
Status() int
Size() int
Latency() time.Duration
}
HTTPResponseStatCollector interface provides methods to collect http response metrics.
type HTTPResponseStatFunc ¶
type HTTPResponseStatFunc func(w http.ResponseWriter, tags map[string]string)
HTTPResponseStatFunc function type to collect HTTP response metrics. An application can implement this function to provide custom implementation of response metrics collection.
type HTTPStats ¶
type HTTPStats struct {
GlobalTags map[string]string
LogRequestStat HTTPRequestStatFunc
LogResponseStat HTTPResponseStatFunc
}
HTTPStats to provide global tags to each metrics and configure custom request and response stats functions.
func NewHTTPStats ¶
NewHTTPStats provides new instance of HTTPStats
func (*HTTPStats) HTTPStatsHandler ¶
HTTPStatsHandler is a default provided HTTP middleware function to collect global http request and response stats.
func (*HTTPStats) ServeHTTP ¶
func (s *HTTPStats) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
ServeHTTP is Negroni compatible interface for httpStats middleware
type StatsWriter ¶
type StatsWriter struct {
Writer http.ResponseWriter
StartTime time.Time
// contains filtered or unexported fields
}
statsWriter implements HTTPResponseStatCollector and collects response code, size and latency.
func (*StatsWriter) Header ¶
func (l *StatsWriter) Header() http.Header
Header returns the header map that will be sent by WriteHeader. Changing the header after a call to WriteHeader (or Write) has no effect unless the modified headers were declared as trailers by setting the "Trailer" header before the call to WriteHeader (see example). To suppress implicit response headers, set their value to nil.
func (*StatsWriter) Latency ¶
func (l *StatsWriter) Latency() time.Duration
Latency provides response time.
func (*StatsWriter) Size ¶
func (l *StatsWriter) Size() int
Size function return current response size in bytes
func (*StatsWriter) Status ¶
func (l *StatsWriter) Status() int
Status function returns current http status code
func (*StatsWriter) Write ¶
func (l *StatsWriter) Write(b []byte) (int, error)
Write writes the data to the connection as part of an HTTP reply. If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK) before writing the data. If the Header does not contain a Content-Type line, Write adds a Content-Type set to the result of passing the initial 512 bytes of written data to DetectContentType.
func (*StatsWriter) WriteHeader ¶
func (l *StatsWriter) WriteHeader(s int)
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.