Documentation ¶
Overview ¶
Package metrics contains support for OpenCensus distributed metrics.
Index ¶
- Variables
- func AddPolicyCountCallback(service string, f func() int64)
- func AddRedisMetrics(stats func() *redis.PoolStats)
- func GRPCClientInterceptor(service string) grpc.UnaryClientInterceptor
- func HTTPMetricsHandler(getInstallationID func() string, service string) func(next http.Handler) http.Handler
- func HTTPMetricsRoundTripper(getInstallationID func() string, service string) func(next http.RoundTripper) http.RoundTripper
- func PrometheusHandler(envoyURL *url.URL, installationID string) (http.Handler, error)
- func RecordAutocertCertificates(certs []tls.Certificate)
- func RecordAutocertRenewal()
- func RecordIdentityManagerLastRefresh(ctx context.Context)
- func RecordIdentityManagerSessionRefresh(ctx context.Context, err error)
- func RecordIdentityManagerUserGroupRefresh(ctx context.Context, err error)
- func RecordIdentityManagerUserRefresh(ctx context.Context, err error)
- func RecordStorageOperation(ctx context.Context, tags *StorageOperationTags, duration time.Duration)
- func RegisterInfoMetrics()
- func SetBuildInfo(service, hostname, envoyVersion string)
- func SetConfigInfo(ctx context.Context, service, configName string, checksum uint64, success bool)
- func SetDBConfigInfo(ctx context.Context, service, configID string, version uint64, errCount int64)
- func SetDBConfigRejected(ctx context.Context, service, configID string, version uint64, err error)
- type GRPCServerMetricsHandler
- type ProcessCollector
- type StorageOperationTags
Constants ¶
This section is empty.
Variables ¶
var ( TagKeyHTTPMethod = tag.MustNewKey("http_method") TagKeyService = tag.MustNewKey("service") TagConfigID = tag.MustNewKey("config_id") TagKeyGRPCService = tag.MustNewKey("grpc_service") TagKeyGRPCMethod = tag.MustNewKey("grpc_method") TagKeyHost = tag.MustNewKey("host") TagKeyStorageOperation = tag.MustNewKey("operation") TagKeyStorageResult = tag.MustNewKey("result") TagKeyStorageBackend = tag.MustNewKey("backend") )
The following tags are applied to stats recorded by this package.
var ( DefaulHTTPSizeDistribution = view.Distribution( 1, 256, 512, 1024, 2048, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608) DefaultHTTPLatencyDistrubtion = view.Distribution( 1, 2, 5, 7, 10, 25, 500, 750, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000, 25000, 50000, 75000, 100000) DefaultMillisecondsDistribution = ocgrpc.DefaultMillisecondsDistribution )
Default distributions used by views in this package.
var ( // GRPCClientViews contains opencensus views for GRPC Client metrics. GRPCClientViews = []*view.View{ GRPCClientRequestCountView, GRPCClientRequestDurationView, GRPCClientResponseSizeView, GRPCClientRequestSizeView, } // GRPCServerViews contains opencensus views for GRPC Server metrics. GRPCServerViews = []*view.View{ GRPCServerRequestCountView, GRPCServerRequestDurationView, GRPCServerResponseSizeView, GRPCServerRequestSizeView, } // GRPCServerRequestCountView is an OpenCensus view which counts GRPC Server // requests by pomerium service, grpc service, grpc method, and status GRPCServerRequestCountView = &view.View{ Name: "grpc/server/requests_total", Measure: ocgrpc.ServerLatency, Description: "Total grpc Requests", TagKeys: []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService}, Aggregation: view.Count(), } // GRPCServerRequestDurationView is an OpenCensus view which tracks GRPC Server // request duration by pomerium service, grpc service, grpc method, and status GRPCServerRequestDurationView = &view.View{ Name: "grpc/server/request_duration_ms", Measure: ocgrpc.ServerLatency, Description: "grpc Request duration in ms", TagKeys: []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService}, Aggregation: DefaultMillisecondsDistribution, } // GRPCServerResponseSizeView is an OpenCensus view which tracks GRPC Server // response size by pomerium service, grpc service, grpc method, and status GRPCServerResponseSizeView = &view.View{ Name: "grpc/server/response_size_bytes", Measure: ocgrpc.ServerSentBytesPerRPC, Description: "grpc Server Response Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService}, Aggregation: grpcSizeDistribution, } // GRPCServerRequestSizeView is an OpenCensus view which tracks GRPC Server // request size by pomerium service, grpc service, grpc method, and status GRPCServerRequestSizeView = &view.View{ Name: "grpc/server/request_size_bytes", Measure: ocgrpc.ServerReceivedBytesPerRPC, Description: "grpc Server Request Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyGRPCMethod, ocgrpc.KeyServerStatus, TagKeyGRPCService}, Aggregation: grpcSizeDistribution, } // GRPCClientRequestCountView is an OpenCensus view which tracks GRPC Client // requests by pomerium service, target host, grpc service, grpc method, and status GRPCClientRequestCountView = &view.View{ Name: "grpc/client/requests_total", Measure: ocgrpc.ClientRoundtripLatency, Description: "Total grpc Client Requests", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus}, Aggregation: view.Count(), } // GRPCClientRequestDurationView is an OpenCensus view which tracks GRPC Client // request duration by pomerium service, target host, grpc service, grpc method, and status GRPCClientRequestDurationView = &view.View{ Name: "grpc/client/request_duration_ms", Measure: ocgrpc.ClientRoundtripLatency, Description: "grpc Client Request duration in ms", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus}, Aggregation: DefaultMillisecondsDistribution, } // GRPCClientResponseSizeView is an OpenCensus view which tracks GRPC Client // response size by pomerium service, target host, grpc service, grpc method, and status GRPCClientResponseSizeView = &view.View{ Name: "grpc/client/response_size_bytes", Measure: ocgrpc.ClientReceivedBytesPerRPC, Description: "grpc Client Response Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus}, Aggregation: grpcSizeDistribution, } // GRPCClientRequestSizeView is an OpenCensus view which tracks GRPC Client // request size by pomerium service, target host, grpc service, grpc method, and status GRPCClientRequestSizeView = &view.View{ Name: "grpc/client/request_size_bytes", Measure: ocgrpc.ClientSentBytesPerRPC, Description: "grpc Client Request Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyGRPCMethod, TagKeyGRPCService, ocgrpc.KeyClientStatus}, Aggregation: grpcSizeDistribution, } )
GRPC Views
var ( // HTTPClientViews contains opencensus views for HTTP Client metrics. HTTPClientViews = []*view.View{ HTTPClientRequestCountView, HTTPClientRequestDurationView, HTTPClientResponseSizeView, } // HTTPServerViews contains opencensus views for HTTP Server metrics. HTTPServerViews = []*view.View{ HTTPServerRequestCountView, HTTPServerRequestDurationView, HTTPServerRequestSizeView, HTTPServerResponseSizeView, } // HTTPServerRequestCountView is an OpenCensus View that tracks HTTP server // requests by pomerium service, host, method and status HTTPServerRequestCountView = &view.View{ Name: "http/server/requests_total", Measure: ochttp.ServerLatency, Description: "Total HTTP Requests", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: view.Count(), } // HTTPServerRequestDurationView is an OpenCensus view that tracks HTTP // server request duration by pomerium service, host, method and status HTTPServerRequestDurationView = &view.View{ Name: "http/server/request_duration_ms", Measure: ochttp.ServerLatency, Description: "HTTP Request duration in ms", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: DefaultHTTPLatencyDistrubtion, } // HTTPServerRequestSizeView is an OpenCensus view that tracks HTTP server // request size by pomerium service, host and method HTTPServerRequestSizeView = &view.View{ Name: "http/server/request_size_bytes", Measure: ochttp.ServerRequestBytes, Description: "HTTP Server Request Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod}, Aggregation: DefaulHTTPSizeDistribution, } // HTTPServerResponseSizeView is an OpenCensus view that tracks HTTP server // response size by pomerium service, host, method and status HTTPServerResponseSizeView = &view.View{ Name: "http/server/response_size_bytes", Measure: ochttp.ServerResponseBytes, Description: "HTTP Server Response Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: DefaulHTTPSizeDistribution, } // HTTPClientRequestCountView is an OpenCensus View that tracks HTTP client // requests by pomerium service, destination, host, method and status HTTPClientRequestCountView = &view.View{ Name: "http/client/requests_total", Measure: ochttp.ClientRoundtripLatency, Description: "Total HTTP Client Requests", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: view.Count(), } // HTTPClientRequestDurationView is an OpenCensus view that tracks HTTP // client request duration by pomerium service, destination, host, method and status HTTPClientRequestDurationView = &view.View{ Name: "http/client/request_duration_ms", Measure: ochttp.ClientRoundtripLatency, Description: "HTTP Client Request duration in ms", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: DefaultHTTPLatencyDistrubtion, } // HTTPClientResponseSizeView is an OpenCensus view that tracks HTTP client // esponse size by pomerium service, destination, host, method and status HTTPClientResponseSizeView = &view.View{ Name: "http/client/response_size_bytes", Measure: ochttp.ClientReceivedBytes, Description: "HTTP Client Response Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod, ochttp.StatusCode}, Aggregation: DefaulHTTPSizeDistribution, } // HTTPClientRequestSizeView is an OpenCensus view that tracks HTTP client // request size by pomerium service, destination, host and method HTTPClientRequestSizeView = &view.View{ Name: "http/client/response_size_bytes", Measure: ochttp.ClientSentBytes, Description: "HTTP Client Response Size in bytes", TagKeys: []tag.Key{TagKeyService, TagKeyHost, TagKeyHTTPMethod}, Aggregation: DefaulHTTPSizeDistribution, } )
HTTP Views
var ( // InfoViews contains opencensus views for informational metrics about // pomerium itself. InfoViews = []*view.View{ ConfigLastReloadView, ConfigLastReloadSuccessView, IdentityManagerLastRefreshView, IdentityManagerLastUserRefreshErrorTimestampView, IdentityManagerLastUserRefreshErrorView, IdentityManagerLastUserRefreshSuccessTimestampView, IdentityManagerLastUserRefreshSuccessView, IdentityManagerLastUserGroupRefreshErrorTimestampView, IdentityManagerLastUserGroupRefreshErrorView, IdentityManagerLastUserGroupRefreshSuccessTimestampView, IdentityManagerLastUserGroupRefreshSuccessView, IdentityManagerLastSessionRefreshErrorTimestampView, IdentityManagerLastSessionRefreshErrorView, IdentityManagerLastSessionRefreshSuccessTimestampView, IdentityManagerLastSessionRefreshSuccessView, ConfigDBVersionView, ConfigDBErrorsView, } // ConfigDBVersionView contains last databroker config version that was processed ConfigDBVersionView = &view.View{ Name: configDBVersion.Name(), Description: configDBVersion.Description(), Measure: configDBVersion, TagKeys: []tag.Key{TagKeyService, TagConfigID}, Aggregation: view.LastValue(), } // ConfigDBErrorsView contains list of errors encountered while parsing this databroker config ConfigDBErrorsView = &view.View{ Name: configDBErrors.Name(), Description: configDBErrors.Description(), Measure: configDBErrors, TagKeys: []tag.Key{TagKeyService, TagConfigID}, Aggregation: view.LastValue(), } // ConfigLastReloadView contains the timestamp the configuration was last // reloaded, labeled by service. ConfigLastReloadView = &view.View{ Name: configLastReload.Name(), Description: configLastReload.Description(), Measure: configLastReload, TagKeys: []tag.Key{TagKeyService}, Aggregation: view.LastValue(), } // ConfigLastReloadSuccessView contains the result of the last configuration // reload, labeled by service. ConfigLastReloadSuccessView = &view.View{ Name: configLastReloadSuccess.Name(), Description: configLastReloadSuccess.Description(), Measure: configLastReloadSuccess, TagKeys: []tag.Key{TagKeyService}, Aggregation: view.LastValue(), } // IdentityManagerLastRefreshView contains the timestamp the identity manager // was last refreshed, labeled by service. IdentityManagerLastRefreshView = &view.View{ Name: identityManagerLastRefresh.Name(), Description: identityManagerLastRefresh.Description(), Measure: identityManagerLastRefresh, Aggregation: view.LastValue(), } // IdentityManagerLastUserRefreshSuccessView contains successful user refresh counter IdentityManagerLastUserRefreshSuccessView = &view.View{ Name: identityManagerLastUserRefreshSuccess.Name(), Description: identityManagerLastUserRefreshSuccess.Description(), Measure: identityManagerLastUserRefreshSuccess, Aggregation: view.Count(), } // IdentityManagerLastUserRefreshErrorView contains user refresh errors counter IdentityManagerLastUserRefreshErrorView = &view.View{ Name: identityManagerLastUserRefreshError.Name(), Description: identityManagerLastUserRefreshError.Description(), Measure: identityManagerLastUserRefreshError, Aggregation: view.Count(), } // IdentityManagerLastUserRefreshSuccessTimestampView contains successful user refresh counter IdentityManagerLastUserRefreshSuccessTimestampView = &view.View{ Name: identityManagerLastUserRefreshSuccessTimestamp.Name(), Description: identityManagerLastUserRefreshSuccessTimestamp.Description(), Measure: identityManagerLastUserRefreshSuccessTimestamp, Aggregation: view.LastValue(), } // IdentityManagerLastUserRefreshErrorTimestampView contains user refresh errors counter IdentityManagerLastUserRefreshErrorTimestampView = &view.View{ Name: identityManagerLastUserRefreshErrorTimestamp.Name(), Description: identityManagerLastUserRefreshErrorTimestamp.Description(), Measure: identityManagerLastUserRefreshErrorTimestamp, Aggregation: view.LastValue(), } // IdentityManagerLastUserGroupRefreshSuccessView contains successful user group refresh counter IdentityManagerLastUserGroupRefreshSuccessView = &view.View{ Name: identityManagerLastUserGroupRefreshSuccess.Name(), Description: identityManagerLastUserGroupRefreshSuccess.Description(), Measure: identityManagerLastUserGroupRefreshSuccess, Aggregation: view.Count(), } // IdentityManagerLastUserGroupRefreshErrorView contains user group refresh errors counter IdentityManagerLastUserGroupRefreshErrorView = &view.View{ Name: identityManagerLastUserGroupRefreshError.Name(), Description: identityManagerLastUserGroupRefreshError.Description(), Measure: identityManagerLastUserGroupRefreshError, Aggregation: view.Count(), } // IdentityManagerLastUserGroupRefreshSuccessTimestampView contains successful user group refresh counter IdentityManagerLastUserGroupRefreshSuccessTimestampView = &view.View{ Name: identityManagerLastUserGroupRefreshSuccessTimestamp.Name(), Description: identityManagerLastUserGroupRefreshSuccessTimestamp.Description(), Measure: identityManagerLastUserGroupRefreshSuccessTimestamp, Aggregation: view.LastValue(), } // IdentityManagerLastUserGroupRefreshErrorTimestampView contains user group refresh errors counter IdentityManagerLastUserGroupRefreshErrorTimestampView = &view.View{ Name: identityManagerLastUserGroupRefreshErrorTimestamp.Name(), Description: identityManagerLastUserGroupRefreshErrorTimestamp.Description(), Measure: identityManagerLastUserGroupRefreshErrorTimestamp, Aggregation: view.LastValue(), } // IdentityManagerLastSessionRefreshSuccessView contains successful user refresh counter IdentityManagerLastSessionRefreshSuccessView = &view.View{ Name: identityManagerLastSessionRefreshSuccess.Name(), Description: identityManagerLastSessionRefreshSuccess.Description(), Measure: identityManagerLastSessionRefreshSuccess, Aggregation: view.Count(), } // IdentityManagerLastSessionRefreshErrorView contains user refresh errors counter IdentityManagerLastSessionRefreshErrorView = &view.View{ Name: identityManagerLastUserRefreshError.Name(), Description: identityManagerLastUserRefreshError.Description(), Measure: identityManagerLastUserRefreshError, Aggregation: view.Count(), } // IdentityManagerLastSessionRefreshSuccessTimestampView contains successful session refresh counter IdentityManagerLastSessionRefreshSuccessTimestampView = &view.View{ Name: identityManagerLastSessionRefreshSuccessTimestamp.Name(), Description: identityManagerLastSessionRefreshSuccessTimestamp.Description(), Measure: identityManagerLastSessionRefreshSuccessTimestamp, Aggregation: view.LastValue(), } // IdentityManagerLastSessionRefreshErrorTimestampView contains session refresh errors counter IdentityManagerLastSessionRefreshErrorTimestampView = &view.View{ Name: identityManagerLastSessionRefreshErrorTimestamp.Name(), Description: identityManagerLastSessionRefreshErrorTimestamp.Description(), Measure: identityManagerLastSessionRefreshErrorTimestamp, Aggregation: view.LastValue(), } )
var ( // StorageViews contains opencensus views for storage system metrics StorageViews = []*view.View{StorageOperationDurationView} // StorageOperationDurationView is an OpenCensus view that tracks storage client // latency by operation, result and backend StorageOperationDurationView = &view.View{ Name: storageOperationDuration.Name(), Description: storageOperationDuration.Description(), Measure: storageOperationDuration, TagKeys: []tag.Key{TagKeyStorageOperation, TagKeyStorageResult, TagKeyStorageBackend, TagKeyService}, Aggregation: DefaultMillisecondsDistribution, } )
var ( DefaultViews = [][]*view.View{ GRPCClientViews, GRPCServerViews, HTTPClientViews, HTTPServerViews, InfoViews, StorageViews, } )
DefaultViews are a set of default views to view HTTP and GRPC metrics.
Functions ¶
func AddPolicyCountCallback ¶
AddPolicyCountCallback sets the function to call when exporting the policy count metric. You must call RegisterInfoMetrics to have this exported
func AddRedisMetrics ¶ added in v0.7.0
AddRedisMetrics registers a metrics handler against a redis Client's PoolStats() method
func GRPCClientInterceptor ¶
func GRPCClientInterceptor(service string) grpc.UnaryClientInterceptor
GRPCClientInterceptor creates a UnaryClientInterceptor which updates the RPC context with metric tag metadata
TODO: This handler will NOT currently propagate B3 headers to upstream servers. See GRPCServerStatsHandler for changes required
func HTTPMetricsHandler ¶
func HTTPMetricsHandler(getInstallationID func() string, service string) func(next http.Handler) http.Handler
HTTPMetricsHandler creates a metrics middleware for incoming HTTP requests
func HTTPMetricsRoundTripper ¶
func HTTPMetricsRoundTripper(getInstallationID func() string, service string) func(next http.RoundTripper) http.RoundTripper
HTTPMetricsRoundTripper creates a metrics tracking tripper for outbound HTTP Requests
func PrometheusHandler ¶
PrometheusHandler creates an exporter that exports stats to Prometheus and returns a handler suitable for exporting metrics.
func RecordAutocertCertificates ¶ added in v0.14.0
func RecordAutocertCertificates(certs []tls.Certificate)
RecordAutocertCertificates records the next timestamp an autocert certificate will expire.
func RecordAutocertRenewal ¶ added in v0.14.0
func RecordAutocertRenewal()
RecordAutocertRenewal records an autocert renewal.
func RecordIdentityManagerLastRefresh ¶ added in v0.14.0
RecordIdentityManagerLastRefresh records that the identity manager refreshed users and groups.
func RecordIdentityManagerSessionRefresh ¶ added in v0.16.0
RecordIdentityManagerSessionRefresh updates timestamp and counter for session refresh
func RecordIdentityManagerUserGroupRefresh ¶ added in v0.16.0
RecordIdentityManagerUserGroupRefresh updates timestamp and counter for user group update
func RecordIdentityManagerUserRefresh ¶ added in v0.16.0
RecordIdentityManagerUserRefresh updates timestamp and counter for user refresh
func RecordStorageOperation ¶ added in v0.10.0
func RecordStorageOperation(ctx context.Context, tags *StorageOperationTags, duration time.Duration)
RecordStorageOperation records the duration of a storage operation with the corresponding tags
func RegisterInfoMetrics ¶
func RegisterInfoMetrics()
RegisterInfoMetrics registers non-view based metrics registry globally for export
func SetBuildInfo ¶
func SetBuildInfo(service, hostname, envoyVersion string)
SetBuildInfo records the pomerium build info. You must call RegisterInfoMetrics to have this exported
func SetConfigInfo ¶
SetConfigInfo records the status, checksum and timestamp of a configuration reload. You must register InfoViews or the related config views before calling
func SetDBConfigInfo ¶ added in v0.14.0
SetDBConfigInfo records status, databroker version and error count while parsing the configuration from a databroker
Types ¶
type GRPCServerMetricsHandler ¶ added in v0.9.0
type GRPCServerMetricsHandler struct {
// contains filtered or unexported fields
}
GRPCServerMetricsHandler implements a telemetry tagRPCHandler methods for metrics
func NewGRPCServerMetricsHandler ¶ added in v0.9.0
func NewGRPCServerMetricsHandler(service string) *GRPCServerMetricsHandler
NewGRPCServerMetricsHandler creates a new GRPCServerStatsHandler for a pomerium service
func (*GRPCServerMetricsHandler) TagRPC ¶ added in v0.9.0
func (h *GRPCServerMetricsHandler) TagRPC(ctx context.Context, tagInfo *grpcstats.RPCTagInfo) context.Context
TagRPC handles adding any metrics related values to the incoming context
type ProcessCollector ¶ added in v0.14.0
type ProcessCollector struct {
// contains filtered or unexported fields
}
A ProcessCollector collects stats about a process.
func NewProcessCollector ¶ added in v0.14.0
func NewProcessCollector(name string) *ProcessCollector
NewProcessCollector creates a new ProcessCollector.
func (*ProcessCollector) Measure ¶ added in v0.14.0
func (pc *ProcessCollector) Measure(ctx context.Context, pid int) error
Measure measures the stats for a process.
func (*ProcessCollector) Views ¶ added in v0.14.0
func (pc *ProcessCollector) Views() []*view.View
Views returns the views for the process collector.
type StorageOperationTags ¶ added in v0.10.0
StorageOperationTags contains tags to apply when recording a storage operation