Esempio n. 1
0
func (m *Metrics) Gauge(metric string, value int64) {
	if m.storeSnapshots {
		m.Lock()
		m.gauge[metric] = value
		m.Unlock()
	}

	/*
		    *if m.logger.ShouldLog(DEBUG) {
			*	m.logger.Debug("metrics", "gauge."+metric,
			*		LogFields{"value": strconv.FormatInt(value, 10),
			*			"type": "gauge"})
			*}
	*/
	if statsd := m.statsd; statsd != nil {
		if value >= 0 {
			statsd.Gauge(metric, value, 1.0)
			return
		}
		// Gauges cannot be set to negative values; sign prefixes indicate deltas.
		if err := statsd.Gauge(metric, 0, 1.0); err != nil {
			return
		}
		statsd.GaugeDelta(metric, value, 1.0)
	}
}
Esempio n. 2
0
func (m *Metrics) Gauge(metric string, value int64) {
	if m.storeSnapshots {
		m.Lock()
		m.gauge[metric] = value
		m.Unlock()
	}

	if statsd := m.statsd; statsd != nil {
		if value >= 0 {
			statsd.Gauge(m.formatGauge(metric), value, 1.0)
			return
		}
		// Gauges cannot be set to negative values; sign prefixes indicate deltas.
		if err := statsd.Gauge(m.formatGauge(metric), 0, 1.0); err != nil {
			return
		}
		statsd.GaugeDelta(m.formatGauge(metric), value, 1.0)
	}
}
Esempio n. 3
0
func main() {
	flag.Parse()

	// read our configuration
	config := ReadConfig(configPath)

	// connect to the database
	db := DBInit(config.PG.ConnectionString)
	defer db.con.Close()

	// connect to statsd
	statsd, err := statsd.New(config.ST.ConnectionString, config.ST.Prefix)
	// handle any errors
	if err != nil {
		log.Fatal(err)
	}
	// make sure to clean up
	defer statsd.Close()

	err = statsd.Gauge("biggest_relation_bytes", db.GetBiggestRelation(), 1.0)
	if err != nil {
		log.Printf("Error sending metric: %+v", err)
	}
	/*
		statementStats := db.GetStatementStats()
		for _, s := range statementStats {
			log.Printf("%#v", s)
		}

		sizeStats := db.GetSizeStats(50)
		for _, s := range sizeStats {
			log.Printf("%#v", s)
		}
	*/

}