func NewEventHandler(cf Config) (events.Handler, error) { h := &handler{listenAddr: cf.ListenAddr, errorSink: cf.ErrorSink} h.connections = prom.NewCounterVec(prom.CounterOpts{ Name: "flux_connections_total", Help: "Number of TCP connections established", }, []string{"individual", "group", "src", "dst", "protocol"}) httpLabels := []string{"individual", "group", "src", "dst", "method", "code"} h.http = prom.NewCounterVec(prom.CounterOpts{ Name: "flux_http_total", Help: "Number of HTTP request/response exchanges", }, httpLabels) h.httpRoundtrip = prom.NewSummaryVec(prom.SummaryOpts{ Name: "flux_http_roundtrip_usec", Help: "HTTP response roundtrip time in microseconds", }, httpLabels) h.httpTotal = prom.NewSummaryVec(prom.SummaryOpts{ Name: "flux_http_total_usec", Help: "HTTP total response time in microseconds", }, httpLabels) if cf.AdvertiseAddr != "" { var err error if h.advertiser, err = newAdvertiser(cf); err != nil { return nil, err } } return h, nil }
// NewExporter returns an initialized exporter func NewExporter(server string) *Exporter { return &Exporter{ mc: memcache.New(server), up: prometheus.NewGauge( prometheus.GaugeOpts{ Name: "up", Namespace: namespace, Help: "Are the servers up.", ConstLabels: prometheus.Labels{"server": server}, }, ), uptime: prometheus.NewCounter( prometheus.CounterOpts{ Name: "uptime", Namespace: namespace, Help: "The uptime of the server.", ConstLabels: prometheus.Labels{"server": server}, }, ), cache: prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "cache", Namespace: namespace, Help: "The cache hits/misses broken down by command (get, set, etc.).", ConstLabels: prometheus.Labels{"server": server}, }, []string{"command", "status"}, ), usage: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "usage", Namespace: namespace, Help: "Details the resource usage (items/connections) of the server, by time (current/total).", ConstLabels: prometheus.Labels{"server": server}, }, []string{"time", "resource"}, ), bytes: prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "bytes", Namespace: namespace, Help: "The bytes sent/received by the server.", ConstLabels: prometheus.Labels{"server": server}, }, []string{"direction"}, ), removals: prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "removal", Namespace: namespace, Help: "Number of items that have been evicted/expired (status), and if the were fetched ever or not.", ConstLabels: prometheus.Labels{"server": server}, }, []string{"status", "fetched"}, ), } }
// New constructs a neww Notifier. func New(o *Options) *Notifier { ctx, cancel := context.WithCancel(context.Background()) return &Notifier{ queue: make(model.Alerts, 0, o.QueueCapacity), ctx: ctx, cancel: cancel, more: make(chan struct{}, 1), opts: o, latency: prometheus.NewSummaryVec(prometheus.SummaryOpts{ Namespace: namespace, Subsystem: subsystem, Name: "latency_seconds", Help: "Latency quantiles for sending alert notifications (not including dropped notifications).", }, []string{alertmanagerLabel}, ), errors: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "errors_total", Help: "Total number of errors sending alert notifications.", }, []string{alertmanagerLabel}, ), sent: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "sent_total", Help: "Total number of alerts successfully sent.", }, []string{alertmanagerLabel}, ), dropped: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dropped_total", Help: "Total number of alerts dropped due to alert manager missing in configuration.", }), queueLength: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: subsystem, Name: "queue_length", Help: "The number of alert notifications in the queue.", }), queueCapacity: prometheus.MustNewConstMetric( prometheus.NewDesc( prometheus.BuildFQName(namespace, subsystem, "queue_capacity"), "The capacity of the alert notifications queue.", nil, nil, ), prometheus.GaugeValue, float64(o.QueueCapacity), ), } }
func initPrometheusMetrics() { TotalClientCounter = stat.NewGauge(stat.GaugeOpts{ Name: "total_clients", Help: "Total number of connected clients", }) TotalNodes = stat.NewGauge(stat.GaugeOpts{ Name: "meshnodes_total", Help: "Total number of Nodes", }) TotalNodeTrafficRx = stat.NewCounter(stat.CounterOpts{ Name: "total_traffic_rx", Help: "Total accumulated received traffic as reported by Nodes", }) TotalNodeTrafficTx = stat.NewCounter(stat.CounterOpts{ Name: "total_traffic_tx", Help: "Total accumulated transmitted traffic as reported by Nodes", }) TotalNodeMgmtTrafficRx = stat.NewCounter(stat.CounterOpts{ Name: "total_traffic_mgmt_rx", Help: "Total accumulated received management traffic as reported by Nodes", }) TotalNodeMgmtTrafficTx = stat.NewCounter(stat.CounterOpts{ Name: "total_traffic_mgmt_tx", Help: "Total accumulated transmitted management traffic as reported by Nodes", }) OnlineNodes = stat.NewGauge(stat.GaugeOpts{ Name: "meshnodes_online_total", Help: "All online nodes", }) NodesTrafficRx = stat.NewCounterVec(stat.CounterOpts{ Name: "meshnode_traffic_rx", Help: "Transmitted traffic from nodes", }, append(nodeLabels, "type")) NodesTrafficTx = stat.NewCounterVec(stat.CounterOpts{ Name: "meshnode_traffic_tx", Help: "Received traffic on nodes", }, append(nodeLabels, "type")) NodesUptime = stat.NewCounterVec(stat.CounterOpts{ Name: "meshnode_uptime", Help: "Uptime of meshnodes", }, nodeLabels) NodesClients = stat.NewGaugeVec(stat.GaugeOpts{ Name: "meshnode_clients", Help: "Clients on single meshnodes", }, nodeLabels) }
// Takes a prometheus registry and returns a new Collector exposing // Device stats. func NewDevstatCollector() (Collector, error) { return &devstatCollector{ bytes: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: devstatSubsystem, Name: "bytes_total", Help: "The total number of bytes in transactions.", }, []string{"device", "type"}, ), transfers: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: devstatSubsystem, Name: "transfers_total", Help: "The total number of transactions.", }, []string{"device", "type"}, ), duration: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: devstatSubsystem, Name: "duration_seconds_total", Help: "The total duration of transactions in seconds.", }, []string{"device", "type"}, ), busyTime: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: devstatSubsystem, Name: "busy_time_seconds_total", Help: "Total time the device had one or more transactions outstanding in seconds.", }, []string{"device"}, ), blocks: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: devstatSubsystem, Name: "blocks_transferred_total", Help: "The total number of blocks transferred.", }, []string{"device"}, ), }, nil }
func init() { prometheus.MustRegister(memAllocBytesGauge) prometheus.MustRegister(availFSGauge) prometheus.MustRegister(&cpuTimeMetric{prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: "process", Name: "cpu_nsec", Help: "CPU time spent in ns, split by user/system.", }, []string{"mode"}, )}) prometheus.MustRegister(&diskStatsMetric{ reads: prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: "system", Name: "disk_reads", Help: "Disk reads, per device name (e.g. xvda).", }, []string{"device"}, ), writes: prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: "system", Name: "disk_writes", Help: "Disk writes, per device name (e.g. xvda).", }, []string{"device"}, ), readbytes: prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: "system", Name: "disk_read_bytes", Help: "Bytes read from disk, per device name (e.g. xvda).", }, []string{"device"}, ), writtenbytes: prometheus.NewCounterVec( prometheus.CounterOpts{ Subsystem: "system", Name: "disk_written_bytes", Help: "Bytes written to disk, per device name (e.g. xvda).", }, []string{"device"}, ), }) }
// NewExporter returns a new MySQL exporter for the provided DSN. func NewExporter(dsn string) *Exporter { return &Exporter{ dsn: dsn, duration: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: exporter, Name: "last_scrape_duration_seconds", Help: "Duration of the last scrape of metrics from MySQL.", }), totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Subsystem: exporter, Name: "scrapes_total", Help: "Total number of times MySQL was scraped for metrics.", }), scrapeErrors: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: exporter, Name: "scrape_errors_total", Help: "Total number of times an error occurred scraping a MySQL.", }, []string{"collector"}), error: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: exporter, Name: "last_scrape_error", Help: "Whether the last scrape of metrics from MySQL resulted in an error (1 for error, 0 for success).", }), mysqldUp: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Name: "up", Help: "Whether the MySQL server is up.", }), } }
// NewMiddleware returns a new prometheus Middleware handler. func NewMiddleware(name string, buckets ...float64) *Middleware { var m Middleware m.reqs = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: reqsName, Help: "How many HTTP requests processed, partitioned by status code, method and HTTP path.", ConstLabels: prometheus.Labels{"service": name}, }, []string{"code", "method", "path"}, ) prometheus.MustRegister(m.reqs) if len(buckets) == 0 { buckets = dflBuckets } m.latency = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Name: latencyName, Help: "How long it took to process the request, partitioned by status code, method and HTTP path.", ConstLabels: prometheus.Labels{"service": name}, Buckets: buckets, }, []string{"code", "method", "path"}, ) prometheus.MustRegister(m.latency) return &m }
// Creates and returns a new Manager. func New() *Manager { refreshChannel := make(chan string, 10) quitChannel := make(chan int) refreshCounter := prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "proxym", Subsystem: "refresh", Name: "count", Help: "Number of refreshes triggered", }, []string{"result"}) prometheus.MustRegister(refreshCounter) var c Config envconfig.Process("proxym", &c) m := &Manager{ Config: &c, httpRouter: pat.New(), refresh: refreshChannel, refreshCounter: refreshCounter, quit: quitChannel, } m.httpRouter.Get("/metrics", prometheus.Handler()) return m }
// NewExporter returns an initialized Exporter. func NewExporter(uri string) *Exporter { return &Exporter{ URI: uri, scrapeFailures: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_scrape_failures_total", Help: "Number of errors while scraping nginx.", }), processedConnections: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Name: "connections_processed_total", Help: "Number of connections processed by nginx", }, []string{"stage"}, ), currentConnections: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "connections_current", Help: "Number of connections currently processed by nginx", }, []string{"state"}, ), client: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: *insecure}, }, }, } }
func TestToReader(t *testing.T) { cntVec := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "name", Help: "docstring", ConstLabels: prometheus.Labels{"constname": "constvalue"}, }, []string{"labelname"}, ) cntVec.WithLabelValues("val1").Inc() cntVec.WithLabelValues("val2").Inc() reg := prometheus.NewRegistry() reg.MustRegister(cntVec) want := `prefix.name.constname.constvalue.labelname.val1 1 1477043 prefix.name.constname.constvalue.labelname.val2 1 1477043 ` mfs, err := reg.Gather() if err != nil { t.Fatalf("error: %v", err) } now := model.Time(1477043083) var buf bytes.Buffer err = writeMetrics(&buf, mfs, "prefix", now) if err != nil { t.Fatalf("error: %v", err) } if got := buf.String(); want != got { t.Fatalf("wanted \n%s\n, got \n%s\n", want, got) } }
func ExampleCounterVec() { binaryVersion := flag.String("environment", "test", "Execution environment: test, staging, production.") flag.Parse() httpReqs := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "http_requests_total", Help: "How many HTTP requests processed, partitioned by status code and HTTP method.", ConstLabels: prometheus.Labels{"env": *binaryVersion}, }, []string{"code", "method"}, ) prometheus.MustRegister(httpReqs) httpReqs.WithLabelValues("404", "POST").Add(42) // If you have to access the same set of labels very frequently, it // might be good to retrieve the metric only once and keep a handle to // it. But beware of deletion of that metric, see below! m := httpReqs.WithLabelValues("200", "GET") for i := 0; i < 1000000; i++ { m.Inc() } // Delete a metric from the vector. If you have previously kept a handle // to that metric (as above), future updates via that handle will go // unseen (even if you re-create a metric with the same label set // later). httpReqs.DeleteLabelValues("200", "GET") // Same thing with the more verbose Labels syntax. httpReqs.Delete(prometheus.Labels{"method": "GET", "code": "200"}) }
func newMesosExporter(opts *exporterOpts) *periodicExporter { e := &periodicExporter{ errors: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "mesos_exporter", Name: "slave_scrape_errors_total", Help: "Current total scrape errors", }, []string{"slave"}, ), opts: opts, } e.slaves.urls = []string{e.opts.localURL} if e.opts.autoDiscover { log.Info("auto discovery enabled from command line flag.") // Update nr. of mesos slaves every 10 minutes e.updateSlaves() go runEvery(e.updateSlaves, 10*time.Minute) } // Fetch slave metrics every interval go runEvery(e.scrapeSlaves, e.opts.interval) return e }
func (c *netDevCollector) Update(ch chan<- prometheus.Metric) (err error) { netDev, err := getNetDevStats() if err != nil { return fmt.Errorf("couldn't get netstats: %s", err) } for direction, devStats := range netDev { for dev, stats := range devStats { for t, value := range stats { key := direction + "_" + t if _, ok := c.metrics[key]; !ok { c.metrics[key] = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, Subsystem: netDevSubsystem, Name: key, Help: fmt.Sprintf("%s %s from getifaddrs().", t, direction), }, []string{"device"}, ) } v, err := strconv.ParseFloat(value, 64) if err != nil { return fmt.Errorf("invalid value %s in netstats: %s", value, err) } c.metrics[key].WithLabelValues(dev).Set(v) } } } for _, m := range c.metrics { m.Collect(ch) } return err }
func TestPush(t *testing.T) { reg := prometheus.NewRegistry() cntVec := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "name", Help: "docstring", ConstLabels: prometheus.Labels{"constname": "constvalue"}, }, []string{"labelname"}, ) cntVec.WithLabelValues("val1").Inc() cntVec.WithLabelValues("val2").Inc() reg.MustRegister(cntVec) host := "localhost" port := ":56789" b, err := NewBridge(&Config{ URL: host + port, Gatherer: reg, Prefix: "prefix", }) if err != nil { t.Fatalf("error creating bridge: %v", err) } nmg, err := newMockGraphite(port) if err != nil { t.Fatalf("error creating mock graphite: %v", err) } defer nmg.Close() err = b.Push() if err != nil { t.Fatalf("error pushing: %v", err) } wants := []string{ "prefix.name.constname.constvalue.labelname.val1 1", "prefix.name.constname.constvalue.labelname.val2 1", } select { case got := <-nmg.readc: for _, want := range wants { matched, err := regexp.MatchString(want, got) if err != nil { t.Fatalf("error pushing: %v", err) } if !matched { t.Fatalf("missing metric:\nno match for %s received by server:\n%s", want, got) } } return case err := <-nmg.errc: t.Fatalf("error reading push: %v", err) case <-time.After(50 * time.Millisecond): t.Fatalf("no result from graphite server") } }
func counter(subsystem, name, help string, labels ...string) *prometheus.CounterVec { return prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "mesos", Subsystem: subsystem, Name: name, Help: help, }, labels) }
func main() { cfg, err := New() if err != nil { log.Fatalf("Failed to parse config: %s", err) return } runs := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "elasticsearch_backup_runs_total", Help: "Number of elasticsearch backup runs", }, []string{"status"}, ) runs = prometheus.MustRegisterOrGet(runs).(*prometheus.CounterVec) duration := prometheus.NewSummaryVec( prometheus.SummaryOpts{ Name: "elasticsearch_backup_duration", Help: "Duration of elasticsearch backup runs", }, []string{"operation"}, ) duration = prometheus.MustRegisterOrGet(duration).(*prometheus.SummaryVec) go listen() interval := time.Hour * time.Duration(cfg.Interval) for { t0 := time.Now() opFunc := func() error { return backupAndRemove(cfg) } logFunc := func(err error, wait time.Duration) { log.Warnf("Failed to connect to ES: %s. Retry in %s", err, wait) } bo := backoff.NewExponentialBackOff() bo.InitialInterval = time.Second bo.MaxInterval = 60 * time.Second bo.MaxElapsedTime = 15 * time.Minute log.Infof("Attempting Snapshot ...") err := backoff.RetryNotify(opFunc, bo, logFunc) if err != nil { runs.WithLabelValues("failed").Inc() log.Warnf("Failed to delete snapshots: %s", err) continue } runs.WithLabelValues("ok").Inc() d0 := float64(time.Since(t0)) / float64(time.Microsecond) duration.WithLabelValues("backup").Observe(d0) if interval < time.Second { break } log.Infof("Waiting %s until next run", interval.String()) time.Sleep(interval) } os.Exit(0) }
// Takes a prometheus registry and returns a new Collector exposing // Filesystems stats. func NewFilesystemCollector() (Collector, error) { subsystem := "filesystem" mountPointPattern := regexp.MustCompile(*ignoredMountPoints) filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes) sizeDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "size"), "Filesystem size in bytes.", filesystemLabelNames, nil, ) freeDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "free"), "Filesystem free space in bytes.", filesystemLabelNames, nil, ) availDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "avail"), "Filesystem space available to non-root users in bytes.", filesystemLabelNames, nil, ) filesDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "files"), "Filesystem total file nodes.", filesystemLabelNames, nil, ) filesFreeDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "files_free"), "Filesystem total free file nodes.", filesystemLabelNames, nil, ) roDesc := prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "readonly"), "Filesystem read-only status.", filesystemLabelNames, nil, ) devErrors := prometheus.NewCounterVec(prometheus.CounterOpts{ Name: prometheus.BuildFQName(Namespace, subsystem, "device_errors_total"), Help: "Total number of errors occurred when getting stats for device", }, filesystemLabelNames) return &filesystemCollector{ ignoredMountPointsPattern: mountPointPattern, ignoredFSTypesPattern: filesystemsTypesPattern, sizeDesc: sizeDesc, freeDesc: freeDesc, availDesc: availDesc, filesDesc: filesDesc, filesFreeDesc: filesFreeDesc, roDesc: roDesc, devErrors: devErrors, }, nil }
// return new empty exporter func NewMySQLExporter(dsn string) *Exporter { return &Exporter{ dsn: dsn, duration: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Name: "exporter_last_scrape_duration_seconds", Help: "The last scrape duration.", }), totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Name: "exporter_scrapes_total", Help: "Current total mysqld scrapes.", }), error: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Name: "exporter_last_scrape_error", Help: "The last scrape error status.", }), metrics: map[string]prometheus.Gauge{}, commands: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: globalStatus, Name: "commands_total", Help: "Number of executed mysql commands.", }, []string{"command"}), connectionErrors: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: globalStatus, Name: "connection_errors_total", Help: "Number of mysql connection errors.", }, []string{"error"}), innodbRows: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: globalStatus, Name: "innodb_rows_total", Help: "Mysql Innodb row operations.", }, []string{"operation"}), performanceSchema: prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: globalStatus, Name: "performance_schema_total", Help: "Mysql instrumentations that could not be loaded or created due to memory constraints", }, []string{"instrumentation"}), } }
func newMeasurer() grpcinstrument.Measurer { return &measurer{ registry: ®istry{ total: prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "grpc_calls_total", Help: "Number of gRPC calls received by the server being instrumented.", }, []string{"service", "method"}), errors: prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "grpc_calls_errors", Help: "Number of gRPC calls that returned an error.", }, []string{"service", "method"}), duration: prometheus.NewHistogramVec(prometheus.HistogramOpts{ Name: "grpc_calls_durations", Help: "Duration of gRPC calls.", }, []string{"service", "method"}), }, } }
func (p *prometheusExport) Prepare() { p.ProbeIsUp = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: *prometheusProbeNameSpace, Name: "up", Help: "Indicates success/failure of the probe. Value of 1 is a success while 0 is a failure. Value of -1 could be because of probe timeout/error.", }, labels) p.ProbeLatency = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: *prometheusProbeNameSpace, Name: "latency", Help: "The probe latency in milliseconds. Value of -1 could be because of probe timeout/error.", }, labels) p.ProbePayloadSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: *prometheusProbeNameSpace, Name: "payload_size", Help: "The probe response payload size in bytes. Value of -1 could be because of probe timeout/error.", }, labels) p.ProbeErrorCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: *prometheusProbeNameSpace, Name: "failure_count", Help: "The probe error count.", }, labels) p.ProbeTimeoutCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: *prometheusProbeNameSpace, Name: "timeout_count", Help: "The probe timeout count.", }, labels) p.ProbeCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: *prometheusProbeNameSpace, Name: "count", Help: "Total Probe count.", }, labels) prometheus.MustRegister(p.ProbeCount) prometheus.MustRegister(p.ProbeErrorCount) prometheus.MustRegister(p.ProbeTimeoutCount) prometheus.MustRegister(p.ProbeLatency) prometheus.MustRegister(p.ProbeIsUp) prometheus.MustRegister(p.ProbePayloadSize) }
func main() { var ( listen = flag.String("listen", ":7801", "Server listen address") delay = flag.Duration("delay", 0, "Delay for responses") logRequests = flag.Bool("log.request", false, "logs http request info as JSON to stdout") requests = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: namespace, Name: "requests_total", Help: "Number of received HTTP requests", }, labelNames, ) ) flag.Parse() if *listen == "" { flag.Usage() os.Exit(1) } prometheus.MustRegister(requests) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { defer func(began time.Time, r *http.Request) { labels := prometheus.Labels{ "method": strings.ToLower(r.Method), "path": r.URL.Path, "code": strconv.Itoa(http.StatusOK), } for name, hdr := range eagleHeaders { v := r.Header.Get(hdr) if len(v) == 0 { v = "unknown" } labels[name] = v } requests.With(labels).Inc() if *logRequests { logRequest(r, began) } }(time.Now(), r) time.Sleep(*delay) fmt.Fprint(w, "OK") }) http.Handle("/metrics", prometheus.Handler()) log.Printf("Starting server on %s", *listen) log.Fatal(http.ListenAndServe(*listen, nil)) }
func NewRejectedRcptMetric() *rejectedRcptMetric { return &rejectedRcptMetric{ counter: prometheus.NewCounterVec(prometheus.CounterOpts{ Name: exim_rejected_rcpt_total, Help: "Total number of rejected recipients, partitioned by error message.", }, []string{ "error_message", }), } }
func init() { restartCounter = promm.NewCounterVec( promm.CounterOpts{ Namespace: "warren", Name: "running_monitor_restarts_total", Help: "Number of times a running monitor has restarted. (count)", }, []string{"name"}, ) promm.MustRegister(restartCounter) }
func newQueueCounterVec(metricName string, docString string) *prometheus.CounterVec { return prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: namespace, Name: "queue_" + metricName, Help: docString, }, queueLabelNames, ) }
func NewAuthenticatorFailedMetric() *authenticatorFailedMetric { return &authenticatorFailedMetric{ counter: prometheus.NewCounterVec(prometheus.CounterOpts{ Name: exim_authenticator_failed_total, Help: "Total number of rejected authentication attempts.", }, []string{ "authenticator", "error_message", }), } }
// NewStorageQueueManager builds a new StorageQueueManager. func NewStorageQueueManager(tsdb StorageClient, queueCapacity int) *StorageQueueManager { constLabels := prometheus.Labels{ "type": tsdb.Name(), } return &StorageQueueManager{ tsdb: tsdb, queue: make(chan *clientmodel.Sample, queueCapacity), sendSemaphore: make(chan bool, maxConcurrentSends), drained: make(chan bool), samplesCount: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "sent_samples_total", Help: "Total number of processed samples to be sent to remote storage.", ConstLabels: constLabels, }, []string{result}, ), sendLatency: prometheus.NewSummary(prometheus.SummaryOpts{ Namespace: namespace, Subsystem: subsystem, Name: "sent_latency_milliseconds", Help: "Latency quantiles for sending sample batches to the remote storage.", ConstLabels: constLabels, }), sendErrors: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "sent_errors_total", Help: "Total number of errors sending sample batches to the remote storage.", ConstLabels: constLabels, }), queueLength: prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: subsystem, Name: "queue_length", Help: "The number of processed samples queued to be sent to the remote storage.", ConstLabels: constLabels, }), queueCapacity: prometheus.MustNewConstMetric( prometheus.NewDesc( prometheus.BuildFQName(namespace, subsystem, "queue_capacity"), "The capacity of the queue of samples to be sent to the remote storage.", nil, constLabels, ), prometheus.GaugeValue, float64(queueCapacity), ), } }
func NewMetricReporter() *MetricReporter { return &MetricReporter{ NewSummaryVec( "gogrinder_elapsed_ms", "Current time elapsed of gogrinder teststep in ms."), prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "gogrinder_error_count", Help: "Current error of gogrinder teststep.", }, []string{"teststep"}), } }
func newCounterVecMetric(serverType, metricName, docString string, labelNames []string) *prometheus.CounterVec { return prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: namespace, Subsystem: serverType, Name: metricName, Help: docString, }, labelNames, ) }
func defineMetrics(namespace, subsystem string) { requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dns_request_count_total", Help: "Counter of DNS requests made.", }, []string{"system"}) requestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dns_request_duration_seconds", Help: "Histogram of the time (in seconds) each request took to resolve.", Buckets: append([]float64{0.001, 0.003}, prometheus.DefBuckets...), }, []string{"system"}) responseSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dns_response_size_bytes", Help: "Size of the returns response in bytes.", Buckets: []float64{0, 512, 1024, 1500, 2048, 4096, 8192, 12288, 16384, 20480, 24576, 28672, 32768, 36864, 40960, 45056, 49152, 53248, 57344, 61440, 65536, }, }, []string{"system"}) errorCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dns_error_count_total", Help: "Counter of DNS requests resulting in an error.", }, []string{"system", "cause"}) cacheMiss = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: namespace, Subsystem: subsystem, Name: "dns_cachemiss_count_total", Help: "Counter of DNS requests that result in a cache miss.", }, []string{"cache"}) }