本文整理汇总了Golang中github.com/prometheus/common/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: initMesh
func initMesh(addr, hwaddr, nickname string) *mesh.Router {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
log.Fatalf("mesh address: %s: %v", addr, err)
}
port, err := strconv.Atoi(portStr)
if err != nil {
log.Fatalf("mesh address: %s: %v", addr, err)
}
name, err := mesh.PeerNameFromString(hwaddr)
if err != nil {
log.Fatalf("invalid hardware address %q: %v", hwaddr, err)
}
return mesh.NewRouter(mesh.Config{
Host: host,
Port: port,
ProtocolMinVersion: mesh.ProtocolMinVersion,
Password: []byte(""),
ConnLimit: 64,
PeerDiscovery: true,
TrustedSubnets: []*net.IPNet{},
}, name, nickname, mesh.NullOverlay{}, stdlog.New(ioutil.Discard, "", 0))
}
开发者ID:farcaller,项目名称:alertmanager,代码行数:27,代码来源:main.go
示例2: initMesh
func initMesh(addr, hwaddr, nickname, pw string) *mesh.Router {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
log.Fatalf("mesh address: %s: %v", addr, err)
}
port, err := strconv.Atoi(portStr)
if err != nil {
log.Fatalf("mesh address: %s: %v", addr, err)
}
name, err := mesh.PeerNameFromString(hwaddr)
if err != nil {
log.Fatalf("invalid hardware address %q: %v", hwaddr, err)
}
password := []byte(pw)
if len(password) == 0 {
// Emtpy password is used to disable secure communication. Using a nil
// password disables encryption in mesh.
password = nil
}
return mesh.NewRouter(mesh.Config{
Host: host,
Port: port,
ProtocolMinVersion: mesh.ProtocolMinVersion,
Password: password,
ConnLimit: 64,
PeerDiscovery: true,
TrustedSubnets: []*net.IPNet{},
}, name, nickname, mesh.NullOverlay{}, stdlog.New(ioutil.Discard, "", 0))
}
开发者ID:prometheus,项目名称:alertmanager,代码行数:34,代码来源:main.go
示例3: 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,
}
}
开发者ID:Jimdo,项目名称:statsd_exporter,代码行数:25,代码来源:main.go
示例4: 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))
}
开发者ID:janeczku,项目名称:powerdns_exporter,代码行数:35,代码来源:powerdns_exporter.go
示例5: 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)
}
}
开发者ID:wrouesnel,项目名称:node_exporter,代码行数:60,代码来源:node_exporter.go
示例6: scrape
func (e *Exporter) scrape() {
resp, err := e.client.Get(e.URL)
if err != nil {
e.up.Set(0)
log.Errorf("Can't scrape Spring Actuator: %v", err)
return
}
defer resp.Body.Close()
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) {
e.up.Set(0)
log.Errorf("Can't scrape Spring Actuator: StatusCode: %d", resp.StatusCode)
return
}
e.up.Set(1)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Errorf("Reading response body failed %v", err)
return
}
var metrics map[string]*json.RawMessage
if err := json.Unmarshal(body, &metrics); err != nil {
log.Fatalf("JSON unmarshaling failed: %s", err)
}
e.export(metrics)
}
开发者ID:yu74n,项目名称:spring_actuator_exporter,代码行数:27,代码来源:spring_actuator_exporter.go
示例7: main
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("blackbox_exporter"))
os.Exit(0)
}
log.Infoln("Starting blackbox_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
yamlFile, err := ioutil.ReadFile(*configFile)
if err != nil {
log.Fatalf("Error reading config file: %s", err)
}
config := Config{}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
log.Fatalf("Error parsing config file: %s", err)
}
http.Handle("/metrics", prometheus.Handler())
http.HandleFunc("/probe",
func(w http.ResponseWriter, r *http.Request) {
probeHandler(w, r, &config)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Blackbox Exporter</title></head>
<body>
<h1>Blackbox Exporter</h1>
<p><a href="/probe?target=prometheus.io&module=http_2xx">Probe prometheus.io for http_2xx</a></p>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
})
log.Infoln("Listening on", *listenAddress)
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
log.Fatalf("Error starting HTTP server: %s", err)
}
}
开发者ID:FauxFaux,项目名称:blackbox_exporter,代码行数:45,代码来源:main.go
示例8: 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)
}
}
开发者ID:trayio,项目名称:node_exporter,代码行数:53,代码来源:node_exporter.go
示例9: StartServer
// StartServer is a method which starts HTTP server
func StartServer(addr *string) {
http.Handle("/metrics", prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>LXC Exporter</title></head>
<body>
<h1>LXC Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>`))
})
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatalf("Error starting HTTP server: %s", err)
}
}
开发者ID:SebastianCzoch,项目名称:lxc-exporter,代码行数:17,代码来源:service.go
示例10: Get
func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels) prometheus.Gauge {
hash := hashNameAndLabels(metricName, labels)
gauge, ok := c.Elements[hash]
if !ok {
gauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: metricName,
Help: defaultHelp,
ConstLabels: labels,
})
c.Elements[hash] = gauge
if err := prometheus.Register(gauge); err != nil {
log.Fatalf(regErrF, metricName, err)
}
}
return gauge
}
开发者ID:Jimdo,项目名称:statsd_exporter,代码行数:16,代码来源:exporter.go
示例11: 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)
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)
}
}
开发者ID:ExpressenAB,项目名称:node_exporter,代码行数:47,代码来源:node_exporter.go
示例12: main
func main() {
flag.Parse()
log.Infoln("Starting snmp exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
// Bail early if the config is bad.
c, err := LoadFile(*configFile)
if err != nil {
log.Fatalf("Error parsing config file: %s", err)
}
// Initilise metrics.
for module, _ := range *c {
snmpDuration.WithLabelValues(module)
}
http.Handle("/metrics", promhttp.Handler()) // Normal metrics endpoint for SNMP exporter itself.
http.HandleFunc("/snmp", handler) // Endpoint to do SNMP scrapes.
log.Infof("Listening on %s", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
开发者ID:RichiH,项目名称:snmp_exporter,代码行数:21,代码来源:main.go
示例13: main
func main() {
flag.Parse()
exporter, err := NewPfExporter()
if err != nil {
log.Fatalf("Failed to create pf exporter: %v", err)
}
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>pf Exporter</title></head>
<body>
<h1>pf Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
开发者ID:mischief,项目名称:pf_exporter,代码行数:23,代码来源:main.go
示例14: startCollectdServer
func startCollectdServer(ctx context.Context, w api.Writer) {
if *collectdAddress == "" {
return
}
srv := network.Server{
Addr: *collectdAddress,
Writer: w,
}
if *collectdAuth != "" {
srv.PasswordLookup = network.NewAuthFile(*collectdAuth)
}
if *collectdTypesDB != "" {
file, err := os.Open(*collectdTypesDB)
if err != nil {
log.Fatalf("Can't open types.db file %s", *collectdTypesDB)
}
defer file.Close()
typesDB, err := api.NewTypesDB(file)
if err != nil {
log.Fatalf("Error in parsing types.db file %s", *collectdTypesDB)
}
srv.TypesDB = typesDB
}
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)
}
laddr, err := net.ResolveUDPAddr("udp", *collectdAddress)
if err != nil {
log.Fatalf("Failed to resolve binary protocol listening UDP address %q: %v", *collectdAddress, err)
}
if laddr.IP != nil && laddr.IP.IsMulticast() {
srv.Conn, err = net.ListenMulticastUDP("udp", nil, laddr)
} else {
srv.Conn, err = net.ListenUDP("udp", laddr)
}
if err != nil {
log.Fatalf("Failed to create a socket for a binary protocol server: %v", err)
}
if *collectdBuffer >= 0 {
if err = srv.Conn.SetReadBuffer(*collectdBuffer); err != nil {
log.Fatalf("Failed to adjust a read buffer of the socket: %v", err)
}
}
go func() {
log.Fatal(srv.ListenAndWrite(ctx))
}()
}
开发者ID:octo,项目名称:collectd_exporter,代码行数:62,代码来源:main.go
示例15: main
func main() {
flag.Parse()
http.Handle(*metricsPath, prometheus.Handler())
cfg, err := config.LoadFile(*configFile)
if err != nil {
log.Fatalln("Configuration file could not be read.", err)
}
c := newTailCollector(cfg)
prometheus.MustRegister(c)
// If args then start file/fifo collectors
if len(flag.Args()) > 0 {
for _, filename := range flag.Args() {
go func(filename string) {
var isPipe bool
st, err := os.Stat(filename)
if err == nil {
if st.Mode()&os.ModeNamedPipe == os.ModeNamedPipe {
isPipe = true
}
} else {
isPipe = false
}
t, err := tail.TailFile(filename, tail.Config{
Location: &tail.SeekInfo{0, os.SEEK_END},
ReOpen: true,
Follow: isPipe,
})
for line := range t.Lines {
c.IngestLine(line.Text)
}
}(filename)
}
}
// If collector address present, then start port collector.
if *collectorAddress != "" {
tcpSock, err := net.Listen("tcp", *collectorAddress)
if err != nil {
log.Fatalf("Error binding to TCP socket: %s", err)
}
go func() {
for {
conn, err := tcpSock.Accept()
if err != nil {
log.Errorf("Error accepting TCP connection: %s", err)
continue
}
go func() {
defer conn.Close()
c.processReader(conn)
}()
}
}()
udpAddress, err := net.ResolveUDPAddr("udp", *collectorAddress)
if err != nil {
log.Fatalf("Error resolving UDP address: %s", err)
}
udpSock, err := net.ListenUDP("udp", udpAddress)
if err != nil {
log.Fatalf("Error listening to UDP address: %s", err)
}
go func() {
defer udpSock.Close()
for {
buf := make([]byte, 65536)
chars, srcAddress, err := udpSock.ReadFromUDP(buf)
if err != nil {
log.Errorf("Error reading UDP packet from %s: %s", srcAddress, err)
continue
}
go c.processReader(bytes.NewReader(buf[0:chars]))
}
}()
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Tail Exporter</title></head>
<body>
<h1>TCP/UDP Tail Exporter</h1>
<p>Accepting raw lines over TCP and UDP on ` + *collectorAddress + `</p>
<p>Watching files for lines:` + strings.Join(flag.Args(), ", ") + `</p>
<p><a href="` + *metricsPath + `">Metrics</a></p>
<h1>Config</h1>
<pre>` +
cfg.Original +
`</pre>
</body>
</html>`))
})
log.Infof("Starting Server: %s", *listeningAddress)
http.ListenAndServe(*listeningAddress, nil)
//.........这里部分代码省略.........
开发者ID:wrouesnel,项目名称:tail_exporter,代码行数:101,代码来源:main.go
示例16: main
func main() {
var (
showVersion = flag.Bool("version", false, "Print version information.")
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 *showVersion {
fmt.Fprintln(os.Stdout, version.Print("node_exporter"))
os.Exit(0)
}
log.Infoln("Starting node_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
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)
}
prometheus.MustRegister(NodeCollector{collectors: collectors})
handler := promhttp.HandlerFor(prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorLog: log.NewErrorLogger()})
http.Handle(*metricsPath, prometheus.InstrumentHandler("prometheus", 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.Infoln("Listening on", *listenAddress)
err = http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}
开发者ID:prometheus,项目名称:node_exporter,代码行数:61,代码来源:node_exporter.go
示例17: main
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("graphite_exporter"))
os.Exit(0)
}
log.Infoln("Starting graphite_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
http.Handle(*metricsPath, prometheus.Handler())
c := newGraphiteCollector()
prometheus.MustRegister(c)
c.mapper = &metricMapper{}
if *mappingConfig != "" {
err := c.mapper.initFromFile(*mappingConfig)
if err != nil {
log.Fatalf("Error loading metric mapping config: %s", err)
}
}
tcpSock, err := net.Listen("tcp", *graphiteAddress)
if err != nil {
log.Fatalf("Error binding to TCP socket: %s", err)
}
go func() {
for {
conn, err := tcpSock.Accept()
if err != nil {
log.Errorf("Error accepting TCP connection: %s", err)
continue
}
go func() {
defer conn.Close()
c.processReader(conn)
}()
}
}()
udpAddress, err := net.ResolveUDPAddr("udp", *graphiteAddress)
if err != nil {
log.Fatalf("Error resolving UDP address: %s", err)
}
udpSock, err := net.ListenUDP("udp", udpAddress)
if err != nil {
log.Fatalf("Error listening to UDP address: %s", err)
}
go func() {
defer udpSock.Close()
for {
buf := make([]byte, 65536)
chars, srcAddress, err := udpSock.ReadFromUDP(buf)
if err != nil {
log.Errorf("Error reading UDP packet from %s: %s", srcAddress, err)
continue
}
go c.processReader(bytes.NewReader(buf[0:chars]))
}
}()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Graphite Exporter</title></head>
<body>
<h1>Graphite Exporter</h1>
<p>Accepting plaintext Graphite samples over TCP and UDP on ` + *graphiteAddress + `</p>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
log.Infoln("Listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
开发者ID:dylanmei,项目名称:graphite_exporter,代码行数:76,代码来源:main.go
注:本文中的github.com/prometheus/common/log.Fatalf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论