本文整理汇总了Golang中github.com/prometheus/client_golang/prometheus.NewCounter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCounter函数的具体用法?Golang NewCounter怎么用?Golang NewCounter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewCounter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ExampleCounter
func ExampleCounter() {
pushCounter := prometheus.NewCounter(prometheus.CounterOpts{
Name: "repository_pushes", // Note: No help string...
})
err := prometheus.Register(pushCounter) // ... so this will return an error.
if err != nil {
fmt.Println("Push counter couldn't be registered, no counting will happen:", err)
return
}
// Try it once more, this time with a help string.
pushCounter = prometheus.NewCounter(prometheus.CounterOpts{
Name: "repository_pushes",
Help: "Number of pushes to external repository.",
})
err = prometheus.Register(pushCounter)
if err != nil {
fmt.Println("Push counter couldn't be registered AGAIN, no counting will happen:", err)
return
}
pushComplete := make(chan struct{})
// TODO: Start a goroutine that performs repository pushes and reports
// each completion via the channel.
for _ = range pushComplete {
pushCounter.Inc()
}
// Output:
// Push counter couldn't be registered, no counting will happen: descriptor Desc{fqName: "repository_pushes", help: "", constLabels: {}, variableLabels: []} is invalid: empty help string
}
示例2: newMetrics
func newMetrics(r prometheus.Registerer) *metrics {
m := &metrics{}
m.gcDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "alertmanager_nflog_gc_duration_seconds",
Help: "Duration of the last notification log garbage collection cycle.",
})
m.snapshotDuration = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "alertmanager_nflog_snapshot_duration_seconds",
Help: "Duration of the last notification log snapshot.",
})
m.queriesTotal = prometheus.NewCounter(prometheus.CounterOpts{
Name: "alertmanager_nflog_queries_total",
Help: "Number of notification log queries were received.",
})
m.queryErrorsTotal = prometheus.NewCounter(prometheus.CounterOpts{
Name: "alertmanager_nflog_query_errors_total",
Help: "Number notification log received queries that failed.",
})
m.queryDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "alertmanager_nflog_query_duration_seconds",
Help: "Duration of notification log query evaluation.",
})
if r != nil {
r.MustRegister(
m.gcDuration,
m.snapshotDuration,
m.queriesTotal,
m.queryErrorsTotal,
m.queryDuration,
)
}
return m
}
示例3: initPrometheusMetrics
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)
}
示例4: NewExporter
// NewExporter returns an initialized Exporter.
func NewExporter(apiKey, serverType string, hostURL *url.URL) *Exporter {
var gaugeDefs []gaugeDefinition
var counterVecDefs []counterVecDefinition
gaugeMetrics := make(map[int]prometheus.Gauge)
counterVecMetrics := make(map[int]*prometheus.CounterVec)
switch serverType {
case "recursor":
gaugeDefs = recursorGaugeDefs
counterVecDefs = recursorCounterVecDefs
case "authoritative":
gaugeDefs = authoritativeGaugeDefs
counterVecDefs = authoritativeCounterVecDefs
case "dnsdist":
gaugeDefs = dnsdistGaugeDefs
counterVecDefs = dnsdistCounterVecDefs
}
for _, def := range gaugeDefs {
gaugeMetrics[def.id] = newGaugeMetric(serverType, def.name, def.desc)
}
for _, def := range counterVecDefs {
counterVecMetrics[def.id] = newCounterVecMetric(serverType, def.name, def.desc, []string{def.label})
}
return &Exporter{
HostURL: hostURL,
ServerType: serverType,
ApiKey: apiKey,
up: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: serverType,
Name: "up",
Help: "Was the last scrape of PowerDNS successful.",
}),
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: serverType,
Name: "exporter_total_scrapes",
Help: "Current total PowerDNS scrapes.",
}),
jsonParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: serverType,
Name: "exporter_json_parse_failures",
Help: "Number of errors while parsing PowerDNS JSON stats.",
}),
gaugeMetrics: gaugeMetrics,
counterVecMetrics: counterVecMetrics,
gaugeDefs: gaugeDefs,
counterVecDefs: counterVecDefs,
}
}
示例5: New
// NewHandler constructs a new Handler.
func New(o *HandlerOptions) *Handler {
ctx, cancel := context.WithCancel(context.Background())
return &Handler{
queue: make(model.Alerts, 0, o.QueueCapacity),
ctx: ctx,
cancel: cancel,
more: make(chan struct{}, 1),
opts: o,
latency: prometheus.NewSummary(prometheus.SummaryOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "latency_seconds",
Help: "Latency quantiles for sending alert notifications (not including dropped notifications).",
}),
errors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "errors_total",
Help: "Total number of errors sending alert notifications.",
}),
sent: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "sent_total",
Help: "Total number of alerts successfully sent.",
}),
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),
),
}
}
示例6: NewExporter
// 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.",
}),
}
}
示例7: NewRedisExporter
func NewRedisExporter(addrs []string, namespace string) *Exporter {
e := Exporter{
addrs: addrs,
namespace: namespace,
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 redis scrapes.",
}),
scrapeErrors: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "exporter_last_scrape_error",
Help: "The last scrape error status.",
}),
}
e.initGauges()
return &e
}
示例8: NewPostgreSQLExporter
func NewPostgreSQLExporter(dsn string, cq []metrics.CustomQuery) *Exporter {
e := &Exporter{
dsn: dsn,
metrics: []metrics.Collection{
metrics.NewBufferMetrics(),
metrics.NewDBMetrics(strings.Split(*databases, ",")),
metrics.NewSlowQueryMetrics(*slow),
metrics.NewCustomQueryMetrics(cq),
},
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_scrapes_total",
Help: "Current total postgresql scrapes.",
}),
duration: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "exporter_last_scrape_duration_seconds",
Help: "The last scrape duration.",
}),
errors: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "exporter_last_scrape_error",
Help: "The last scrape error status.",
}),
}
if len(*tables) > 0 {
e.metrics = append(e.metrics, metrics.NewTableMetrics(strings.Split(*tables, ",")))
}
return e
}
示例9: NewExporter
// 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},
},
},
}
}
示例10: NewExporter
// NewExporter returns a new PostgreSQL exporter for the provided DSN.
func NewExporter(dsn string, userQueriesPath string) *Exporter {
return &Exporter{
dsn: dsn,
userQueriesPath: userQueriesPath,
duration: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: exporter,
Name: "last_scrape_duration_seconds",
Help: "Duration of the last scrape of metrics from PostgresSQL.",
}),
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: exporter,
Name: "scrapes_total",
Help: "Total number of times PostgresSQL was scraped for metrics.",
}),
error: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: exporter,
Name: "last_scrape_error",
Help: "Whether the last scrape of metrics from PostgreSQL resulted in an error (1 for error, 0 for success).",
}),
variableMap: nil,
metricMap: nil,
queryOverrides: nil,
}
}
示例11: NewRethinkDBExporter
func NewRethinkDBExporter(addr, auth, clusterName, namespace string) *Exporter {
return &Exporter{
addrs: strings.Split(addr, ","),
auth: auth,
clusterName: clusterName,
namespace: namespace,
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 rethinkdb scrapes.",
}),
scrapeError: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "exporter_last_scrape_error",
Help: "The last scrape error status.",
}),
metrics: map[string]*prometheus.GaugeVec{},
}
}
示例12: init
// Add prometheus logging to SkyDNS
func init() {
server.StatsForwardCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_forward_count",
Help: "Counter of DNS requests forwarded",
}))
server.StatsLookupCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_lookup_count",
Help: "Counter of DNS lookups performed",
}))
server.StatsRequestCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_request_count",
Help: "Counter of DNS requests made",
}))
server.StatsDnssecOkCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_dnssec_ok_count",
Help: "Counter of DNSSEC requests that were valid",
}))
server.StatsDnssecCacheMiss = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_dnssec_cache_miss_count",
Help: "Counter of DNSSEC requests that missed the cache",
}))
server.StatsNameErrorCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_name_error_count",
Help: "Counter of DNS requests resulting in a name error",
}))
server.StatsNoDataCount = newCounter(prometheus.NewCounter(prometheus.CounterOpts{
Name: "dns_no_data_count",
Help: "Counter of DNS requests that contained no data",
}))
}
示例13: NewExporter
// 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"},
),
}
}
示例14: NewAddsMetric
func (_ prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
adds := prometheus.NewCounter(prometheus.CounterOpts{
Subsystem: name,
Name: "adds",
Help: "Total number of adds handled by workqueue: " + name,
})
prometheus.Register(adds)
return adds
}
示例15: NewRetriesMetric
func (_ prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
retries := prometheus.NewCounter(prometheus.CounterOpts{
Subsystem: name,
Name: "retries",
Help: "Total number of retries handled by workqueue: " + name,
})
prometheus.Register(retries)
return retries
}