func (e *Exporter) scrapeTimers(json *gabs.Container) {
	elements, _ := json.ChildrenMap()
	for key, element := range elements {
		new, err := e.scrapeTimer(key, element)
		if err != nil {
			log.Debug(err)
		} else if new {
			log.Infof("Added timer %q\n", key)
		}
	}
}
Beispiel #2
0
//ReturnBalances returns the available balances
func (poloniexClient *PoloniexClient) ReturnBalances() (balances *map[string]float64, err error) {
	log.Debug("ReturnBalances")

	commandParameters := make(map[string]string)
	poloniexBalances := make(map[string]string)

	err = poloniexClient.executeTradingAPICommand("returnBalances", commandParameters, poloniexBalances)
	if err != nil {
		return
	}

	return
}
Beispiel #3
0
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
	// Arcstats
	err = c.updateArcstats(ch)
	switch {
	case err == zfsNotAvailableError:
		log.Debug(err)
		return nil
	case err != nil:
		return err
	}

	// Pool stats
	return c.updatePoolStats(ch)
}
Beispiel #4
0
func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
	stat, err := newWifiStater(*collectorWifi)
	if err != nil {
		// Cannot access wifi metrics, report no error
		if os.IsNotExist(err) {
			log.Debug("wifi collector metrics are not available for this system")
			return nil
		}

		return fmt.Errorf("failed to access wifi data: %v", err)
	}
	defer stat.Close()

	ifis, err := stat.Interfaces()
	if err != nil {
		return fmt.Errorf("failed to retrieve wifi interfaces: %v", err)
	}

	for _, ifi := range ifis {
		// Only collect metrics on stations for now
		if ifi.Type != wifi.InterfaceTypeStation {
			continue
		}

		info, err := stat.StationInfo(ifi)
		if err != nil {
			return fmt.Errorf("failed to retrieve station info for device %s: %v",
				ifi.Name, err)
		}

		ch <- prometheus.MustNewConstMetric(
			c.InterfaceFrequencyHertz,
			prometheus.GaugeValue,
			mHzToHz(ifi.Frequency),
			ifi.Name,
		)

		c.updateStationStats(ch, ifi.Name, info)
	}

	return nil
}
Beispiel #5
0
func (b *Exporter) Listen(e <-chan Events) {
	for {
		events, ok := <-e
		if !ok {
			log.Debug("Channel is closed. Break out of Exporter.Listener.")
			return
		}
		for _, event := range events {
			metricName := ""
			prometheusLabels := event.Labels()

			labels, present := b.mapper.getMapping(event.MetricName())
			if present {
				metricName = labels["name"]
				for label, value := range labels {
					if label != "name" {
						prometheusLabels[label] = value
					}
				}
			} else {
				eventsUnmapped.Inc()
				metricName = escapeMetricName(event.MetricName())
			}

			switch event.(type) {
			case *CounterEvent:
				counter := b.Counters.Get(
					b.suffix(metricName, "counter"),
					prometheusLabels,
				)
				// We don't accept negative values for counters. Incrementing the counter with a negative number
				// will cause the exporter to panic. Instead we will warn and continue to the next event.
				if event.Value() < 0.0 {
					log.Errorf("Counter %q is: '%f' (counter must be non-negative value)", metricName, event.Value())
					continue
				}

				counter.Add(event.Value())

				eventStats.WithLabelValues("counter").Inc()

			case *GaugeEvent:
				gauge := b.Gauges.Get(
					b.suffix(metricName, "gauge"),
					prometheusLabels,
				)
				gauge.Set(event.Value())

				eventStats.WithLabelValues("gauge").Inc()

			case *TimerEvent:
				summary := b.Summaries.Get(
					b.suffix(metricName, "timer"),
					prometheusLabels,
				)
				summary.Observe(event.Value())

				eventStats.WithLabelValues("timer").Inc()

			default:
				log.Errorln("Unsupported event type")
				eventStats.WithLabelValues("illegal").Inc()
			}
		}
	}
}
Beispiel #6
0
func formatAsJSON(data interface{}) error {
	log.Debug("Formatting as json")
	return json.NewEncoder(os.Stdout).Encode(data)
}