Example #1
0
// Reusable function for pushing metrics to prometheus.  Handles initialization and so on.
func promPushRunningPending(running, pending int) error {
	if TestContext.PrometheusPushGateway == "" {
		return nil
	} else {
		// Register metrics if necessary
		if !prom_registered && TestContext.PrometheusPushGateway != "" {
			prometheus.Register(runningMetric)
			prometheus.Register(pendingMetric)
			prom_registered = true
		}
		// Update metric values
		runningMetric.Set(float64(running))
		pendingMetric.Set(float64(pending))

		// Push them to the push gateway.  This will be scraped by prometheus
		// provided you launch it with the pushgateway as an endpoint.
		if err := prometheus.Push(
			"e2e",
			"none",
			TestContext.PrometheusPushGateway, //i.e. "127.0.0.1:9091"
		); err != nil {
			fmt.Println("failed at pushing to pushgateway ", err)
			return err
		}
	}
	return nil
}
func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	flag.Parse()

	if !*runBackup && !*runSync {
		log.Fatal("Neither -backup nor -sync enabled, nothing to do.")
	}

	storageList := strings.Split(*storageHosts, ",")
	if len(storageList) > 2 {
		log.Fatal("More than 2 -storage_hosts are not supported. Please send a patch to fix.")
	}

	if *runBackup {
		backup(storageList)
	}

	if *runSync {
		sync(storageList)
	}

	lastSuccess := prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "last_success",
		Help: "Timestamp of the last success",
	})
	prometheus.MustRegister(lastSuccess)
	lastSuccess.Set(float64(time.Now().Unix()))

	if err := prometheus.Push("dornroeschen", "dornroeschen", *pushGateway); err != nil {
		log.Fatal(err)
	}
}
Example #3
0
// Push current metrics each minute
func processingLoop(sink *Sink) {
	c := time.Tick(sink.Config.Interval)
	for _ = range c {
		prometheus.Push(sink.Config.Job, sink.Config.Hostname, sink.Config.Endpoint)
		if sink.doneFlag {
			return
		}
	}
}
Example #4
0
// Push current metrics each minute
func processingLoop(sink *Sink) {
	c := time.Tick(sink.Config.Interval)

PROMETHEUS_PROCESSING_LOOP:
	for {
		select {
		case <-c:
			prometheus.Push(sink.Config.Job, sink.Config.Hostname, sink.Config.Endpoint)
		case <-sink.doneChan:
			sink.doneDoneChan <- true
			break PROMETHEUS_PROCESSING_LOOP
		}
	}
}
func main() {
	flag.Parse()

	for _, param := range strings.Split(*paramWhitelistStr, ",") {
		paramWhitelist[param] = true
		log.Printf("Whitelisted parameter: %q\n", param)
	}

	http.HandleFunc("/", handleRpc2)
	http.Handle("/metrics", prometheus.Handler())

	listener, err := net.Listen("tcp", *listenAddress)
	if err != nil {
		log.Fatal(err)
	}

	srv := http.Server{Addr: *listenAddress}
	go srv.Serve(tcpKeepAliveListener{listener.(*net.TCPListener)})

	externalURL := "http://" + *externalAddress
	log.Printf("Listening on %q, registering %q at the CCU2\n", listener.Addr(), externalURL)

	if err := hmInit("http://homematic-ccu2:9292/groups", externalURL, "zkjhmserver"); err != nil {
		log.Fatal(err)
	}

	if err := hmInit("http://homematic-ccu2:2001/", externalURL, "zkjrfd"); err != nil {
		log.Fatal(err)
	}

	for {
		time.Sleep(1 * time.Minute)
		if time.Since(lastEvent) > 5*time.Minute {
			log.Fatalf("Last event received at %v (%v ago)", lastEvent, time.Since(lastEvent))
		}
		if err := prometheus.Push("hm", "hm", *pushGateway); err != nil {
			log.Fatal(err)
		}
	}

}