本文整理汇总了Golang中github.com/prometheus/common/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("mysqld_exporter"))
os.Exit(0)
}
log.Infoln("Starting mysqld_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
var err error
if dsn, err = parseMycnf(*configMycnf); err != nil {
log.Fatal(err)
}
}
exporter := NewExporter(dsn)
prometheus.MustRegister(exporter)
http.Handle(*metricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(landingPage)
})
log.Infoln("Listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例2: watchConfig
func watchConfig(fileName string, mapper *metricMapper) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
err = watcher.WatchFlags(fileName, fsnotify.FSN_MODIFY)
if err != nil {
log.Fatal(err)
}
for {
select {
case ev := <-watcher.Event:
log.Infof("Config file changed (%s), attempting reload", ev)
err = mapper.initFromFile(fileName)
if err != nil {
log.Errorln("Error reloading config:", err)
configLoads.WithLabelValues("failure").Inc()
} else {
log.Infoln("Config reloaded successfully")
configLoads.WithLabelValues("success").Inc()
}
// Re-add the file watcher since it can get lost on some changes. E.g.
// saving a file with vim results in a RENAME-MODIFY-DELETE event
// sequence, after which the newly written file is no longer watched.
err = watcher.WatchFlags(fileName, fsnotify.FSN_MODIFY)
case err := <-watcher.Error:
log.Errorln("Error watching config:", err)
}
}
}
示例3: main
func main() {
flag.Parse()
if *printCollectors {
collectorNames := make(sort.StringSlice, 0, len(collector.Factories))
for n := range collector.Factories {
collectorNames = append(collectorNames, n)
}
collectorNames.Sort()
fmt.Printf("Available collectors:\n")
for _, n := range collectorNames {
fmt.Printf(" - %s\n", n)
}
return
}
collectors, err := loadCollectors()
if err != nil {
log.Fatalf("Couldn't load collectors: %s", err)
}
log.Infof("Enabled collectors:")
for n := range collectors {
log.Infof(" - %s", n)
}
nodeCollector := NodeCollector{collectors: collectors}
prometheus.MustRegister(nodeCollector)
sigUsr1 := make(chan os.Signal)
signal.Notify(sigUsr1, syscall.SIGUSR1)
handler := prometheus.Handler()
if *authUser != "" || *authPass != "" {
if *authUser == "" || *authPass == "" {
log.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth")
}
handler = &basicAuthHandler{
handler: prometheus.Handler().ServeHTTP,
user: *authUser,
password: *authPass,
}
}
http.Handle(*metricsPath, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress)
err = http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}
示例4: main
func main() {
var (
listenAddress = flag.String("web.listen-address", ":9101", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
haProxyScrapeURI = flag.String("haproxy.scrape-uri", "http://localhost/;csv", "URI on which to scrape HAProxy.")
haProxyServerMetricFields = flag.String("haproxy.server-metric-fields", serverMetrics.String(), "Comma-seperated list of exported server metrics. See http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#9.1")
haProxyTimeout = flag.Duration("haproxy.timeout", 5*time.Second, "Timeout for trying to get stats from HAProxy.")
haProxyPidFile = flag.String("haproxy.pid-file", "", "Path to haproxy's pid file.")
)
flag.Parse()
selectedServerMetrics, err := filterServerMetrics(*haProxyServerMetricFields)
if err != nil {
log.Fatal(err)
}
exporter := NewExporter(*haProxyScrapeURI, selectedServerMetrics, *haProxyTimeout)
prometheus.MustRegister(exporter)
if *haProxyPidFile != "" {
procExporter := prometheus.NewProcessCollectorPIDFn(
func() (int, error) {
content, err := ioutil.ReadFile(*haProxyPidFile)
if err != nil {
return 0, fmt.Errorf("Can't read pid file: %s", err)
}
value, err := strconv.Atoi(strings.TrimSpace(string(content)))
if err != nil {
return 0, fmt.Errorf("Can't parse pid file: %s", err)
}
return value, nil
}, namespace)
prometheus.MustRegister(procExporter)
}
log.Infof("Starting Server: %s", *listenAddress)
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Haproxy Exporter</title></head>
<body>
<h1>Haproxy Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例5: main
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("statsd_exporter"))
os.Exit(0)
}
if *addSuffix {
log.Warnln("Warning: Using -statsd.add-suffix is discouraged. We recommend explicitly naming metrics appropriately in the mapping configuration.")
}
log.Infoln("Starting StatsD -> Prometheus Exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
log.Infoln("Accepting StatsD Traffic on", *statsdListenAddress)
log.Infoln("Accepting Prometheus Requests on", *listenAddress)
go serveHTTP()
events := make(chan Events, 1024)
defer close(events)
listenAddr := udpAddrFromString(*statsdListenAddress)
conn, err := net.ListenUDP("udp", listenAddr)
if err != nil {
log.Fatal(err)
}
if *readBuffer != 0 {
err = conn.SetReadBuffer(*readBuffer)
if err != nil {
log.Fatal("Error setting UDP read buffer:", err)
}
}
l := &StatsDListener{conn: conn}
go l.Listen(events)
mapper := &metricMapper{}
if *mappingConfig != "" {
err := mapper.initFromFile(*mappingConfig)
if err != nil {
log.Fatal("Error loading config:", err)
}
go watchConfig(*mappingConfig, mapper)
}
exporter := NewExporter(mapper, *addSuffix)
exporter.Listen(events)
}
示例6: main
func main() {
config := createConfig()
log.Info("Create provisioner...")
provisioner, err := provisioner.NewProvisioner(config.Token)
if err != nil {
log.Fatal(err)
}
go backgroundRunner(provisioner)
log.Info("Create server...")
server := web.CreateServer(provisioner)
log.Infof("Listen on %s", config.Port)
log.Fatal(http.ListenAndServe(":"+config.Port, server))
}
示例7: udpAddrFromString
func udpAddrFromString(addr string) *net.UDPAddr {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
log.Fatal("Bad StatsD listening address", addr)
}
if host == "" {
host = "0.0.0.0"
}
ip, err := net.ResolveIPAddr("ip", host)
if err != nil {
log.Fatalf("Unable to resolve %s: %s", host, err)
}
port, err := strconv.Atoi(portStr)
if err != nil || port < 0 || port > 65535 {
log.Fatalf("Bad port %s: %s", portStr, err)
}
return &net.UDPAddr{
IP: ip.IP,
Port: port,
Zone: ip.Zone,
}
}
示例8: main
func main() {
var (
listenAddress = flag.String("listen-address", ":9120", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("metric-path", "/metrics", "Path under which to expose metrics.")
apiURL = flag.String("api-url", "http://localhost:8001/", "Base-URL of PowerDNS authoritative server/recursor API.")
apiKey = flag.String("api-key", "", "PowerDNS API Key")
)
flag.Parse()
hostURL, err := url.Parse(*apiURL)
if err != nil {
log.Fatalf("Error parsing api-url: %v", err)
}
server, err := getServerInfo(hostURL, *apiKey)
if err != nil {
log.Fatalf("Could not fetch PowerDNS server info: %v", err)
}
exporter := NewExporter(*apiKey, server.DaemonType, hostURL)
prometheus.MustRegister(exporter)
log.Infof("Starting Server: %s", *listenAddress)
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>PowerDNS Exporter</title></head>
<body>
<h1>PowerDNS Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例9: main
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("collectd_exporter"))
os.Exit(0)
}
log.Infoln("Starting collectd_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
c := newCollectdCollector()
prometheus.MustRegister(c)
startCollectdServer(context.Background(), c)
if *collectdPostPath != "" {
http.HandleFunc(*collectdPostPath, c.collectdPost)
}
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Collectd Exporter</title></head>
<body>
<h1>Collectd Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Infoln("Listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例10: main
func main() {
flag.Parse()
exporter := NewExporter(*scrapeURI)
prometheus.MustRegister(exporter)
log.Infof("Starting Server: %s", *listeningAddress)
http.Handle(*metricsEndpoint, prometheus.Handler())
log.Fatal(http.ListenAndServe(*listeningAddress, nil))
}
示例11: Listen
func (l *StatsDListener) Listen(e chan<- Events) {
buf := make([]byte, 65535)
for {
n, _, err := l.conn.ReadFromUDP(buf)
if err != nil {
log.Fatal(err)
}
l.handlePacket(buf[0:n], e)
}
}
示例12: main
func main() {
r := httprouter.New()
// r.GET("/overview", Overview)
r.GET("/graph/*importpath", Grapher)
r.ServeFiles("/static/*filepath", http.Dir("static/"))
log.Infoln("launching tracegraph on :8080")
log.Fatal(http.ListenAndServe(":8080", r))
}
示例13: main
func main() {
var (
listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
enabledCollectors = flag.String("collectors.enabled", filterAvailableCollectors(defaultCollectors), "Comma-separated list of collectors to use.")
printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.")
)
flag.Parse()
if *printCollectors {
collectorNames := make(sort.StringSlice, 0, len(collector.Factories))
for n := range collector.Factories {
collectorNames = append(collectorNames, n)
}
collectorNames.Sort()
fmt.Printf("Available collectors:\n")
for _, n := range collectorNames {
fmt.Printf(" - %s\n", n)
}
return
}
collectors, err := loadCollectors(*enabledCollectors)
if err != nil {
log.Fatalf("Couldn't load collectors: %s", err)
}
log.Infof("Enabled collectors:")
for n := range collectors {
log.Infof(" - %s", n)
}
nodeCollector := NodeCollector{collectors: collectors}
prometheus.MustRegister(nodeCollector)
handler := prometheus.Handler()
http.Handle(*metricsPath, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress)
err = http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}
示例14: main
func main() {
var (
bindURI = flag.String("bind.stats-url", "http://localhost:8053/", "HTTP XML API address of an Bind server.")
bindTimeout = flag.Duration("bind.timeout", 10*time.Second, "Timeout for trying to get stats from Bind.")
bindPidFile = flag.String("bind.pid-file", "", "Path to Bind's pid file to export process information.")
bindVersion = flag.String("bind.stats-version", "auto", "BIND statistics version. Can be detected automatically. Available: [xml.v2, xml.v3, auto]")
showVersion = flag.Bool("version", false, "Print version information.")
listenAddress = flag.String("web.listen-address", ":9119", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
groups = statisticGroups{bind.ServerStats, bind.ViewStats}
)
flag.Var(&groups, "bind.stats-groups", "Comma-separated list of statistics to collect. Available: [server, view, tasks]")
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("bind_exporter"))
os.Exit(0)
}
log.Infoln("Starting bind_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
log.Infoln("Configured to collect statistics", groups.String())
prometheus.MustRegister(NewExporter(*bindVersion, *bindURI, *bindTimeout, groups))
if *bindPidFile != "" {
procExporter := prometheus.NewProcessCollectorPIDFn(
func() (int, error) {
content, err := ioutil.ReadFile(*bindPidFile)
if err != nil {
return 0, fmt.Errorf("Can't read pid file: %s", err)
}
value, err := strconv.Atoi(strings.TrimSpace(string(content)))
if err != nil {
return 0, fmt.Errorf("Can't parse pid file: %s", err)
}
return value, nil
}, namespace)
prometheus.MustRegister(procExporter)
}
log.Info("Starting Server: ", *listenAddress)
http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Bind Exporter</title></head>
<body>
<h1>Bind Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例15: main
func main() {
flag.Parse()
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
var err error
if dsn, err = parseMycnf(*configMycnf); err != nil {
log.Fatal(err)
}
}
exporter := NewExporter(dsn)
prometheus.MustRegister(exporter)
http.Handle(*metricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(landingPage)
})
log.Infof("Starting Server: %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}