本文整理汇总了Golang中github.com/prometheus/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
}
exporter := NewExporter(dsn)
prometheus.MustRegister(exporter)
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(*metricPath, 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))
}
示例2: main
func main() {
flag.Parse()
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
}
exporter := NewMySQLExporter(dsn)
prometheus.MustRegister(exporter)
http.Handle(*metricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>MySQLd exporter</title></head>
<body>
<h1>MySQLd exporter</h1>
<p><a href='` + *metricPath + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Infof("Starting Server: %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例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() {
flag.Parse()
log.Println("Starting StatsD -> Prometheus Bridge...")
log.Println("Accepting StatsD Traffic on", *statsdListenAddress)
log.Println("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)
}
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)
}
bridge := NewBridge(mapper)
bridge.Listen(events)
}
示例5: Watch
func (w *fileWatcher) Watch(cb ReloadCallback) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
err = watcher.WatchFlags(w.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)
conf, err := LoadFromFile(w.fileName)
if err != nil {
log.Error("Error loading new config: ", err)
failedConfigReloads.Inc()
} else {
cb(&conf)
log.Info("Config reloaded successfully")
configReloads.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(w.fileName, fsnotify.FSN_MODIFY)
case err := <-watcher.Error:
log.Error("Error watching config: ", err)
}
}
}
示例6: 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.Printf("Config file changed (%s), attempting reload", ev)
err = mapper.initFromFile(fileName)
if err != nil {
log.Println("Error reloading config:", err)
configLoads.WithLabelValues("failure").Inc()
} else {
log.Println("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.Println("Error watching config:", err)
}
}
}
示例7: NewNewRelicApi
func NewNewRelicApi(server string, apikey string) *newRelicApi {
parsed, err := url.Parse(server)
if err != nil {
log.Fatal("Could not parse API URL: ", err)
}
if apikey == "" {
log.Fatal("Cannot continue without an API key.")
}
return &newRelicApi{
server: *parsed,
apiKey: apikey,
}
}
示例8: main
func main() {
flag.Parse()
handler := prometheus.Handler()
prometheus.MustRegister(watts)
prometheus.MustRegister(updatesPerPost)
prometheus.MustRegister(voltage)
http.Handle(*metricsPath, handler)
http.HandleFunc("/activate", activateHandler)
http.HandleFunc("/post", postHandler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>TED Exporter</title></head>
<body>
<h1>TED Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Infof("Starting ted_exporter v%s at %s", Version, *listenAddress)
err := http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}
示例9: startCollectdServer
func startCollectdServer(w api.Writer) {
if *collectdAddress == "" {
return
}
srv := network.Server{
Addr: *collectdAddress,
Writer: w,
}
if *collectdAuth != "" {
srv.PasswordLookup = network.NewAuthFile(*collectdAuth)
}
switch strings.ToLower(*collectdSecurity) {
case "", "none":
srv.SecurityLevel = network.None
case "sign":
srv.SecurityLevel = network.Sign
case "encrypt":
srv.SecurityLevel = network.Encrypt
default:
log.Fatalf("Unknown security level %q. Must be one of \"None\", \"Sign\" and \"Encrypt\".", *collectdSecurity)
}
go func() {
log.Fatal(srv.ListenAndWrite())
}()
}
示例10: 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,
}
}
示例11: main
func main() {
var (
listenAddress = flag.String("web.listen-address", ":9107", "Address to listen on for web interface and telemetry.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
consulServer = flag.String("consul.server", "localhost:8500", "HTTP API address of a Consul server or agent.")
kvPrefix = flag.String("kv.prefix", "", "Prefix from which to expose key/value pairs.")
kvFilter = flag.String("kv.filter", ".*", "Regex that determines which keys to expose.")
)
flag.Parse()
exporter := NewExporter(*consulServer, *kvPrefix, *kvFilter)
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>Consul Exporter</title></head>
<body>
<h1>Consul Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例12: main
func main() {
flag.Parse()
// Initialize Intel Edison
edisonAdaptor := edison.NewEdisonAdaptor("edison")
edisonAdaptor.Connect()
lightSensor := gpio.NewGroveLightSensorDriver(edisonAdaptor, "light", *sensorLightPin, *sensorPollingInterval)
lightSensor.Start()
gobot.On(lightSensor.Event("data"), func(data interface{}) {
raw := float64(data.(int))
// convert to lux
resistance := (1023.0 - raw) * 10.0 / raw * 15.0
light = 10000.0 / math.Pow(resistance, 4.0/3.0)
lightUpdated = time.Now()
log.Debugln("illuminance: ", light)
})
soundSensor := gpio.NewGroveSoundSensorDriver(edisonAdaptor, "sound", *sensorSoundPin, *sensorPollingInterval)
soundSensor.Start()
gobot.On(soundSensor.Event("data"), func(data interface{}) {
sound = float64(data.(int))
soundUpdated = time.Now()
log.Debugln("sound level: ", sound)
})
tempSensor := gpio.NewGroveTemperatureSensorDriver(edisonAdaptor, "temp", *sensorTempPin, *sensorPollingInterval)
tempSensor.Start()
gobot.On(tempSensor.Event("data"), func(data interface{}) {
celsius = data.(float64)
fahrenheit = celsius*1.8 + 32
tempUpdated = time.Now()
log.Debugln("temperature: ", celsius)
})
// Initialize prometheus exporter
exporter := NewExporter()
prometheus.MustRegister(exporter)
log.Infof("Listening on: %s", *listenAddress)
http.Handle(*metricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
<head>
<title>IoT Edison exporter</title>
</head>
<body>
<h1>Prometheus exporter for sensor metrics from Intel Edison</h1>
<p><a href='` + *metricPath + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例13: main
func main() {
flag.Parse()
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
}
if *databases == "" {
log.Fatal("please specify at least one database")
}
var err error
db, err = sql.Open("postgres", dsn)
if err != nil {
log.Fatal("error opening connection to database: ", err)
}
defer db.Close()
if err := db.Ping(); err != nil {
log.Fatal("error opening connection to database: ", err)
}
db.SetMaxIdleConns(5)
db.SetMaxOpenConns(5)
exporter := NewPostgreSQLExporter(dsn, parseQueries(*queries))
prometheus.MustRegister(exporter)
http.Handle(*metricPath, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>PostgreSQL exporter</title></head>
<body>
<h1>PostgreSQL exporter</h1>
<p><a href='` + *metricPath + `'>Metrics</a></p>
</body>
</html>
`))
})
log.Infof("Starting Server: %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
示例14: main
func main() {
flag.Parse()
dsn := os.Getenv("DATA_SOURCE_NAME")
if len(dsn) == 0 {
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
}
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))
}
示例15: main
func main() {
flag.Parse()
exporter := NewExporter(*nginxScrapeURI)
prometheus.MustRegister(exporter)
log.Printf("Starting Server: %s", *listeningAddress)
http.Handle(*metricsEndpoint, prometheus.Handler())
log.Fatal(http.ListenAndServe(*listeningAddress, nil))
}