Documentation
¶
Index ¶
- func NewMetric(m *Metric, subsystem string) prometheus.Collector
- func SetPrometheusOutPut(r *gin.RouterGroup)
- type Loger
- func (l *Loger) Copy() *Loger
- func (l *Loger) Error(args ...interface{})
- func (l *Loger) Errorw(msg string, keysAndValues ...interface{})
- func (l *Loger) Info(args ...interface{})
- func (l *Loger) Infow(msg string, keysAndValues ...interface{})
- func (l *Loger) New() *Loger
- func (l *Loger) Warn(args ...interface{})
- func (l *Loger) Warnw(msg string, keysAndValues ...interface{})
- func (l *Loger) WithDuration(start time.Time) *Loger
- func (l *Loger) WithError(err error) *Loger
- func (l *Loger) WithKV(args ...interface{}) *Loger
- func (l *Loger) WithModule(name string) *Loger
- func (l *Loger) WithModule_ApiReq() *Loger
- func (l *Loger) WithModule_Db() *Loger
- func (l *Loger) WithReqId(c *gin.Context) *Loger
- type Metric
- type Prometheus
- func (p *Prometheus) HandlerFunc() gin.HandlerFunc
- func (p *Prometheus) SetListenAddress(address string)
- func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)
- func (p *Prometheus) SetMetricsPath(r *gin.RouterGroup)
- func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushIntervalSeconds time.Duration)
- func (p *Prometheus) SetPushGatewayJob(j string)
- func (p *Prometheus) Use(r *gin.RouterGroup)
- type PrometheusHook
- type PrometheusPushGateway
- type RequestCounterURLLabelMappingFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMetric ¶
func NewMetric(m *Metric, subsystem string) prometheus.Collector
NewMetric associates prometheus.Collector based on Metric.Type
func SetPrometheusOutPut ¶
func SetPrometheusOutPut(r *gin.RouterGroup)
Types ¶
type Loger ¶
type Loger struct {
// contains filtered or unexported fields
}
func (*Loger) WithModule ¶
func (*Loger) WithModule_ApiReq ¶
func (*Loger) WithModule_Db ¶
type Metric ¶
type Metric struct {
MetricCollector prometheus.Collector
ID string
Name string
Description string
Type string
Args []string
}
Metric is a definition for the name, description, type, ID, and prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric
type Prometheus ¶
type Prometheus struct {
Ppg PrometheusPushGateway
MetricsList []*Metric
MetricsPath string
ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn
// gin.Context string to use as a prometheus URL label
URLLabelFromContext string
// contains filtered or unexported fields
}
Prometheus contains the metrics gathered by the instance and its path
func NewPrometheus ¶
func NewPrometheus(subsystem string, customMetricsList ...[]*Metric) *Prometheus
NewPrometheus generates a new set of metrics with a certain subsystem name
func (*Prometheus) HandlerFunc ¶
func (p *Prometheus) HandlerFunc() gin.HandlerFunc
HandlerFunc defines handler function for middleware
func (*Prometheus) SetListenAddress ¶
func (p *Prometheus) SetListenAddress(address string)
SetListenAddress for exposing metrics on address. If not set, it will be exposed at the same address of the gin engine that is being used
func (*Prometheus) SetListenAddressWithRouter ¶
func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)
SetListenAddressWithRouter for using a separate router to expose metrics. (this keeps things like GET /metrics out of your content's access log).
func (*Prometheus) SetMetricsPath ¶
func (p *Prometheus) SetMetricsPath(r *gin.RouterGroup)
SetMetricsPath set metrics paths
func (*Prometheus) SetPushGateway ¶
func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushIntervalSeconds time.Duration)
SetPushGateway sends metrics to a remote pushgateway exposed on pushGatewayURL every pushIntervalSeconds. Metrics are fetched from metricsURL
func (*Prometheus) SetPushGatewayJob ¶
func (p *Prometheus) SetPushGatewayJob(j string)
SetPushGatewayJob job name, defaults to "gin"
func (*Prometheus) Use ¶
func (p *Prometheus) Use(r *gin.RouterGroup)
Use adds the middleware to a gin engine.
type PrometheusHook ¶
type PrometheusHook struct {
// contains filtered or unexported fields
}
PrometheusHook exposes Prometheus counters for each of logrus' log levels.
func MustNewPrometheusHook ¶
func MustNewPrometheusHook() *PrometheusHook
MustNewPrometheusHook creates a new instance of PrometheusHook which exposes Prometheus counters for various log levels. Contrarily to NewPrometheusHook, it does not return any error to the caller, but panics instead. Use MustNewPrometheusHook if you want a less verbose hook creation. Use NewPrometheusHook if you want more control.
func NewPrometheusHook ¶
func NewPrometheusHook() (*PrometheusHook, error)
NewPrometheusHook creates a new instance of PrometheusHook which exposes Prometheus counters for various log levels. Contrarily to MustNewPrometheusHook, it returns an error to the caller in case of issue. Use NewPrometheusHook if you want more control. Use MustNewPrometheusHook if you want a less verbose hook creation.
func (*PrometheusHook) Fire ¶
func (hook *PrometheusHook) Fire(entry *logrus.Entry) error
Fire increments the appropriate Prometheus counter depending on the entry's log level.
func (*PrometheusHook) Levels ¶
func (hook *PrometheusHook) Levels() []logrus.Level
Levels returns all supported log levels, i.e.: Debug, Info, Warn and Error, as there is no point incrementing a counter just before exiting/panicking.
type PrometheusPushGateway ¶
type PrometheusPushGateway struct {
// Push interval in seconds
PushIntervalSeconds time.Duration
// Push Gateway URL in format http://domain:port
// where JOBNAME can be any string of your choice
PushGatewayURL string
// Local metrics URL where metrics are fetched from, this could be ommited in the future
// if implemented using prometheus common/expfmt instead
MetricsURL string
// pushgateway job name, defaults to "gin"
Job string
}
PrometheusPushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)
type RequestCounterURLLabelMappingFn ¶
RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:
func(c *gin.Context) string {
url := c.Request.URL.Path
for _, p := range c.Params {
if p.Key == "name" {
url = strings.Replace(url, p.Value, ":name", 1)
break
}
}
return url
}
which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".