func NewRethinkDBExporter(addr, auth, clusterName, namespace string) *Exporter {
	return &Exporter{
		addrs:       strings.Split(addr, ","),
		auth:        auth,
		clusterName: clusterName,
		namespace:   namespace,

		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_duration_seconds",
			Help:      "The last scrape duration.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_scrapes_total",
			Help:      "Current total rethinkdb scrapes.",
		}),
		scrapeError: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_error",
			Help:      "The last scrape error status.",
		}),
		metrics: map[string]*prometheus.GaugeVec{},
	}
}
// NewExporter returns a new PostgreSQL exporter for the provided DSN.
func NewExporter(dsn string, userQueriesPath string) *Exporter {
	return &Exporter{
		dsn:             dsn,
		userQueriesPath: userQueriesPath,
		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "last_scrape_duration_seconds",
			Help:      "Duration of the last scrape of metrics from PostgresSQL.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "scrapes_total",
			Help:      "Total number of times PostgresSQL was scraped for metrics.",
		}),
		error: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "last_scrape_error",
			Help:      "Whether the last scrape of metrics from PostgreSQL resulted in an error (1 for error, 0 for success).",
		}),
		variableMap:    nil,
		metricMap:      nil,
		queryOverrides: nil,
	}
}
Esempio n. 3
0
func registerProbes() {
	for _, probe := range config.Probes {
		probeURL, _ := url.Parse(probe)

		monitors := &probeMonitor{}
		monitors.Expires = prometheus.NewGauge(prometheus.GaugeOpts{
			Name: "certcheck_expires",
			Help: "Expiration date in unix timestamp (UTC)",
			ConstLabels: prometheus.Labels{
				"host": probeURL.Host,
			},
		})
		monitors.IsValid = prometheus.NewGauge(prometheus.GaugeOpts{
			Name: "certcheck_valid",
			Help: "Validity of the certificate (0/1)",
			ConstLabels: prometheus.Labels{
				"host": probeURL.Host,
			},
		})

		prometheus.MustRegister(monitors.Expires)
		prometheus.MustRegister(monitors.IsValid)

		probeMonitors[probeURL.Host] = monitors
	}
}
func NewRedisExporter(addrs []string, namespace string) *Exporter {
	e := Exporter{
		addrs:     addrs,
		namespace: namespace,

		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_duration_seconds",
			Help:      "The last scrape duration.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_scrapes_total",
			Help:      "Current total redis scrapes.",
		}),
		scrapeErrors: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_error",
			Help:      "The last scrape error status.",
		}),
	}

	e.initGauges()
	return &e
}
Esempio n. 5
0
// NewClusterUsageCollector creates and returns the reference to ClusterUsageCollector
// and internally defines each metric that display cluster stats.
func NewClusterUsageCollector(conn Conn) *ClusterUsageCollector {
	return &ClusterUsageCollector{
		conn: conn,

		GlobalCapacity: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: cephNamespace,
			Name:      "cluster_capacity_bytes",
			Help:      "Total capacity of the cluster",
		}),
		UsedCapacity: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: cephNamespace,
			Name:      "cluster_used_bytes",
			Help:      "Capacity of the cluster currently in use",
		}),
		AvailableCapacity: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: cephNamespace,
			Name:      "cluster_available_bytes",
			Help:      "Available space within the cluster",
		}),
		Objects: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: cephNamespace,
			Name:      "cluster_objects",
			Help:      "No. of rados objects within the cluster",
		}),
	}
}
Esempio n. 6
0
func startMonitoring(addr string) {

	var redisActiveConn = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "redis_active_conn",
		Help: "Number of active redis connections.",
	})
	prometheus.MustRegister(redisActiveConn)

	var redisMaxConn = prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "redis_max_conn",
		Help: "Maximum number of redis connections.",
	})
	prometheus.MustRegister(redisMaxConn)

	http.Handle("/metrics", prometheus.Handler())
	redisMaxConn.Set(float64(redisPool.MaxActive))
	go func() {
		tick := time.NewTicker(1 * time.Second)
		for range tick.C {
			if redisPool == nil {
				redisActiveConn.Set(0)
			} else {
				redisActiveConn.Set(float64(redisPool.ActiveCount()))
			}
		}
	}()
	err := http.ListenAndServe(addr, nil)
	if err != nil {
		lg.Fatal(err)
	}
}
// NewExporter returns a new MySQL exporter for the provided DSN.
func NewExporter(dsn string) *Exporter {
	return &Exporter{
		dsn: dsn,
		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "last_scrape_duration_seconds",
			Help:      "Duration of the last scrape of metrics from MySQL.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "scrapes_total",
			Help:      "Total number of times MySQL was scraped for metrics.",
		}),
		scrapeErrors: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "scrape_errors_total",
			Help:      "Total number of times an error occurred scraping a MySQL.",
		}, []string{"collector"}),
		error: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: exporter,
			Name:      "last_scrape_error",
			Help:      "Whether the last scrape of metrics from MySQL resulted in an error (1 for error, 0 for success).",
		}),
		mysqldUp: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "up",
			Help:      "Whether the MySQL server is up.",
		}),
	}
}
func NewPostgreSQLExporter(dsn string, cq []metrics.CustomQuery) *Exporter {
	e := &Exporter{
		dsn: dsn,
		metrics: []metrics.Collection{
			metrics.NewBufferMetrics(),
			metrics.NewDBMetrics(strings.Split(*databases, ",")),
			metrics.NewSlowQueryMetrics(*slow),
			metrics.NewCustomQueryMetrics(cq),
		},
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_scrapes_total",
			Help:      "Current total postgresql scrapes.",
		}),
		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_duration_seconds",
			Help:      "The last scrape duration.",
		}),
		errors: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_error",
			Help:      "The last scrape error status.",
		}),
	}

	if len(*tables) > 0 {
		e.metrics = append(e.metrics, metrics.NewTableMetrics(strings.Split(*tables, ",")))
	}

	return e
}
Esempio n. 9
0
func initPrometheusMetrics() {
	TotalClientCounter = stat.NewGauge(stat.GaugeOpts{
		Name: "total_clients",
		Help: "Total number of connected clients",
	})

	TotalNodes = stat.NewGauge(stat.GaugeOpts{
		Name: "meshnodes_total",
		Help: "Total number of Nodes",
	})

	TotalNodeTrafficRx = stat.NewCounter(stat.CounterOpts{
		Name: "total_traffic_rx",
		Help: "Total accumulated received traffic as reported by Nodes",
	})

	TotalNodeTrafficTx = stat.NewCounter(stat.CounterOpts{
		Name: "total_traffic_tx",
		Help: "Total accumulated transmitted traffic as reported by Nodes",
	})

	TotalNodeMgmtTrafficRx = stat.NewCounter(stat.CounterOpts{
		Name: "total_traffic_mgmt_rx",
		Help: "Total accumulated received management traffic as reported by Nodes",
	})

	TotalNodeMgmtTrafficTx = stat.NewCounter(stat.CounterOpts{
		Name: "total_traffic_mgmt_tx",
		Help: "Total accumulated transmitted management traffic as reported by Nodes",
	})

	OnlineNodes = stat.NewGauge(stat.GaugeOpts{
		Name: "meshnodes_online_total",
		Help: "All online nodes",
	})

	NodesTrafficRx = stat.NewCounterVec(stat.CounterOpts{
		Name: "meshnode_traffic_rx",
		Help: "Transmitted traffic from nodes",
	}, append(nodeLabels, "type"))

	NodesTrafficTx = stat.NewCounterVec(stat.CounterOpts{
		Name: "meshnode_traffic_tx",
		Help: "Received traffic on nodes",
	}, append(nodeLabels, "type"))

	NodesUptime = stat.NewCounterVec(stat.CounterOpts{
		Name: "meshnode_uptime",
		Help: "Uptime of meshnodes",
	}, nodeLabels)

	NodesClients = stat.NewGaugeVec(stat.GaugeOpts{
		Name: "meshnode_clients",
		Help: "Clients on single meshnodes",
	}, nodeLabels)
}
Esempio n. 10
0
// NewMgoStatsCollector creates a MgoStatsCollector for the given
// namespace (which may be empty).
func NewMgoStatsCollector(namespace string) *MgoStatsCollector {
	// Enable stats in the mgo driver.
	mgo.SetStats(true)
	return &MgoStatsCollector{
		clusters: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "clusters",
			Help:      "Number of alive clusters.",
		}),
		masterConns: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "master_connections",
			Help:      "Number of master connections.",
		}),
		slaveConns: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "slave_connections",
			Help:      "Number of slave connections.",
		}),
		sentOps: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "sent_operations",
			Help:      "Number of operations sent.",
		}),
		receivedOps: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "received_operations",
			Help:      "Number of operations received.",
		}),
		receivedDocs: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "received_documents",
			Help:      "Number of documents received.",
		}),
		socketsAlive: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "sockets_alive",
			Help:      "Number of alive sockets.",
		}),
		socketsInUse: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "sockets_in_use",
			Help:      "Number of in use sockets.",
		}),
		socketRefs: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: "mgo",
			Name:      "socket_references",
			Help:      "Number of references to sockets.",
		}),
	}
}
Esempio n. 11
0
func defineDnsmasqMetrics(options *Options) {
	const dnsmasqSubsystem = "dnsmasq"

	gauges[dnsmasq.CacheHits] = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "hits",
			Help:      "Number of DNS cache hits (from start of process)",
		})
	gauges[dnsmasq.CacheMisses] = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "misses",
			Help:      "Number of DNS cache misses (from start of process)",
		})
	gauges[dnsmasq.CacheEvictions] = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "evictions",
			Help:      "Counter of DNS cache evictions (from start of process)",
		})
	gauges[dnsmasq.CacheInsertions] = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "insertions",
			Help:      "Counter of DNS cache insertions (from start of process)",
		})
	gauges[dnsmasq.CacheSize] = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "max_size",
			Help:      "Maximum size of the DNS cache",
		})

	for i := range gauges {
		prometheus.MustRegister(gauges[i])
	}

	errorsCounter = prometheus.NewCounter(
		prometheus.CounterOpts{
			Namespace: options.PrometheusNamespace,
			Subsystem: dnsmasqSubsystem,
			Name:      "errors",
			Help:      "Number of errors that have occurred getting metrics",
		})
	prometheus.MustRegister(errorsCounter)
}
Esempio n. 12
0
func (n *Namespace) NewGauge(name, help string, unit Unit) Gauge {
	g := &gauge{
		pg: prometheus.NewGauge(n.newGaugeOpts(name, help, unit)),
	}
	n.addMetric(g)
	return g
}
Esempio n. 13
0
func metricsInit(servicename string) *syndicateMetrics {
	m := syndicateMetrics{}
	m.managedNodes = prometheus.NewGauge(prometheus.GaugeOpts{
		Name:        "ManagedNodes",
		Help:        "Current number of nodes managed.",
		ConstLabels: prometheus.Labels{"servicename": servicename},
	})
	m.subscriberNodes = prometheus.NewGauge(prometheus.GaugeOpts{
		Name:        "SubscriberNodes",
		Help:        "Current number of unmanaged nodes subscribed for ring changes.",
		ConstLabels: prometheus.Labels{"servicename": servicename},
	})
	prometheus.Register(m.managedNodes)
	prometheus.Register(m.subscriberNodes)
	return &m
}
Esempio n. 14
0
func (c *netStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
	netStats, err := getNetStats()
	if err != nil {
		return fmt.Errorf("couldn't get netstats: %s", err)
	}
	for protocol, protocolStats := range netStats {
		for name, value := range protocolStats {
			key := protocol + "_" + name
			if _, ok := c.metrics[key]; !ok {
				c.metrics[key] = prometheus.NewGauge(
					prometheus.GaugeOpts{
						Namespace: Namespace,
						Subsystem: netStatsSubsystem,
						Name:      key,
						Help:      fmt.Sprintf("%s %s from /proc/net/netstat.", protocol, name),
					},
				)
			}
			v, err := strconv.ParseFloat(value, 64)
			if err != nil {
				return fmt.Errorf("invalid value %s in netstats: %s", value, err)
			}
			c.metrics[key].Set(v)
		}
	}
	for _, m := range c.metrics {
		m.Collect(ch)
	}
	return err
}
Esempio n. 15
0
func TestSensorRecordGauge(t *testing.T) {
	testServer := httptest.NewServer(prometheus.UninstrumentedHandler())
	defer testServer.Close()

	sensor := &Sensor{
		Type: "gauge",
		collector: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: "telemetry",
			Subsystem: "sensors",
			Name:      "TestSensorRecordGauge",
			Help:      "help",
		})}

	prometheus.MustRegister(sensor.collector)
	sensor.record("1.2")
	resp := getFromTestServer(t, testServer)
	if strings.Count(resp, "telemetry_sensors_TestSensorRecordGauge 1.2") != 1 {
		t.Fatalf("Failed to get match for sensor in response: %s", resp)
	}
	sensor.record("2.3")
	resp = getFromTestServer(t, testServer)
	if strings.Count(resp, "telemetry_sensors_TestSensorRecordGauge 2.3") != 1 {
		t.Fatalf("Failed to get match for sensor in response: %s", resp)
	}
}
Esempio n. 16
0
func (c *fileFDStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
	fileFDStat, err := getFileFDStats(procFilePath("sys/fs/file-nr"))
	if err != nil {
		return fmt.Errorf("couldn't get file-nr: %s", err)
	}
	for name, value := range fileFDStat {
		if _, ok := c.metrics[name]; !ok {
			c.metrics[name] = prometheus.NewGauge(
				prometheus.GaugeOpts{
					Namespace: Namespace,
					Subsystem: fileFDStatSubsystem,
					Name:      name,
					Help:      fmt.Sprintf("File descriptor statistics: %s.", name),
				},
			)
		}
		v, err := strconv.ParseFloat(value, 64)
		if err != nil {
			return fmt.Errorf("invalid value %s in file-nr: %s", value, err)
		}
		c.metrics[name].Set(v)
	}
	for _, m := range c.metrics {
		m.Collect(ch)
	}
	return err
}
func New(configFile string) (e exporter, err error) {

	e = exporter{
		configFile: configFile,
		Metrics:    map[string]*prometheus.GaugeVec{},
		scrapeDuration: prometheus.NewSummaryVec(
			prometheus.SummaryOpts{
				Namespace: namespace,
				Name:      "scrape_duration_seconds",
				Help:      "gmond_exporter: Duration of a scrape job.",
			},
			[]string{"endpoint", "result"},
		),
		metricsUpdated: prometheus.NewGaugeVec(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Name:      "metrics_updated_count",
				Help:      "gmond_exporter: Number of metrics updated.",
			},
			[]string{"endpoint"},
		),
		metricsExported: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "metrics_exported_count",
			Help:      "gmond_exporter: Number of metrics exported.",
		}),
		configChan:            make(chan config),
		listeningAddress:      ":8080",
		gangliaScrapeInterval: 60 * time.Second,
	}

	conf, err := e.readConfig()
	if err != nil {
		return e, fmt.Errorf("Couldn't read config: %s", err)
	}
	e.conf = conf

	if conf.ListeningAddress != "" {
		e.listeningAddress = conf.ListeningAddress
	}
	if conf.GangliaScrapeInterval != 0 {
		e.gangliaScrapeInterval = time.Duration(conf.GangliaScrapeInterval) * time.Second
	}

	prometheus.MustRegister(e.scrapeDuration)
	prometheus.MustRegister(e.metricsUpdated)
	prometheus.MustRegister(e.metricsExported)
	debug("Registered internal metrics")

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGHUP)
	go func() {
		for _ = range sig {
			e.reloadConfig() // sends a new config to configChan
		}
	}()

	go e.serveStatus()
	return e, nil
}
Esempio n. 18
0
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)
	}
}
func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
	sockStats, err := getSockStats(procFilePath("net/sockstat"))
	if err != nil {
		return fmt.Errorf("couldn't get sockstats: %s", err)
	}
	for protocol, protocolStats := range sockStats {
		for name, value := range protocolStats {
			key := protocol + "_" + name
			if _, ok := c.metrics[key]; !ok {
				c.metrics[key] = prometheus.NewGauge(
					prometheus.GaugeOpts{
						Namespace: Namespace,
						Subsystem: sockStatSubsystem,
						Name:      key,
						Help:      fmt.Sprintf("Number of %s sockets in state %s.", protocol, name),
					},
				)
			}
			v, err := strconv.ParseFloat(value, 64)
			if err != nil {
				return fmt.Errorf("invalid value %s in sockstats: %s", value, err)
			}
			c.metrics[key].Set(v)
		}
	}
	for _, m := range c.metrics {
		m.Collect(ch)
	}
	return err
}
Esempio n. 20
0
func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
	prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "fake",
		Subsystem: "fake",
		Name:      "fake",
		Help:      "fake",
	}).Describe(ch)
}
Esempio n. 21
0
func newAuroraExporter(f finder) *exporter {
	return &exporter{
		f: f,
		errors: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Name:      "exporter_scrape_errors_total",
				Help:      "Total scrape errors",
			}),
		duration: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Namespace: namespace,
				Name:      "exporter_last_scrape_duration_seconds",
				Help:      "The last scrape duration",
			}),
	}
}
func exampleInit(c *cli.Context, reg *harness.MetricRegistry) (harness.Collector, error) {
	fooEnabled := c.Bool("flagfoo")
	if fooEnabled {
		fmt.Println("foo enabled")
	}

	reg.Register("example_metric_A", prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "example_metric_A",
		Help: "is example_metric_A",
	}))
	reg.Register("example_metric_B", prometheus.NewGauge(prometheus.GaugeOpts{
		Name: "example_metric_B",
		Help: "is example_metric_B",
	}))

	return &collector{}, nil
}
Esempio n. 23
0
func WritePrometheusMetrics(logger *log.Logger, PROM_GATEWAY string, HOST string, metrics []Metric) error {
	var err error
	logger.Printf("writing %d metrics\n", len(metrics))
	for i := 0; i < len(metrics); i++ {
		//metrics[i].Print()

		opts := prometheus.GaugeOpts{
			Name: PREFIX + metrics[i].MetricName,
			Help: "no help available",
		}

		labels := make(map[string]string)

		labels["DatabaseName"] = metrics[i].DatabaseName
		labels["Units"] = metrics[i].Units
		if metrics[i].TableName != "" {
			labels["TableName"] = metrics[i].TableName
		}

		if metrics[i].LockType != "" {
			labels["LockType"] = metrics[i].LockType
			labels["LockMode"] = metrics[i].LockMode
		}
		if metrics[i].LastVacuum != "" {
			labels["LastVacuum"] = metrics[i].LastVacuum
			labels["LastAnalyze"] = metrics[i].LastAnalyze
			labels["AvNeeded"] = metrics[i].AvNeeded
		}
		if metrics[i].Age != "" {
			labels["Age"] = metrics[i].Age
			labels["Kind"] = metrics[i].Kind
		}
		if metrics[i].MetricName == "wraparound" {
			labels["TableSz"] = strconv.FormatInt(metrics[i].TableSz, 10)
			labels["TotalSz"] = strconv.FormatInt(metrics[i].TotalSz, 10)
		}
		if metrics[i].MetricName == "pct_dead" {
			labels["DeadTup"] = strconv.FormatInt(metrics[i].DeadTup, 10)
			labels["RelTup"] = strconv.FormatInt(metrics[i].RelTup, 10)
			labels["TableSz"] = strconv.FormatInt(metrics[i].TableSz, 10)
			labels["TotalSz"] = strconv.FormatInt(metrics[i].TotalSz, 10)
		}

		opts.ConstLabels = labels

		newMetric := prometheus.NewGauge(opts)
		newMetric.Set(float64(metrics[i].Value))
		if err := prometheus.PushCollectors(
			metrics[i].MetricName, HOST,
			PROM_GATEWAY,
			newMetric,
		); err != nil {
			logger.Println("Could not push " + metrics[i].MetricName + "completion time to Pushgateway:" + err.Error())
			return err
		}
	}
	return err
}
Esempio n. 24
0
// return new empty exporter
func NewMySQLExporter(dsn string) *Exporter {
	return &Exporter{
		dsn: dsn,
		duration: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_duration_seconds",
			Help:      "The last scrape duration.",
		}),
		totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Name:      "exporter_scrapes_total",
			Help:      "Current total mysqld scrapes.",
		}),
		error: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      "exporter_last_scrape_error",
			Help:      "The last scrape error status.",
		}),
		metrics: map[string]prometheus.Gauge{},
		commands: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: globalStatus,
			Name:      "commands_total",
			Help:      "Number of executed mysql commands.",
		}, []string{"command"}),
		connectionErrors: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: globalStatus,
			Name:      "connection_errors_total",
			Help:      "Number of mysql connection errors.",
		}, []string{"error"}),
		innodbRows: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: globalStatus,
			Name:      "innodb_rows_total",
			Help:      "Mysql Innodb row operations.",
		}, []string{"operation"}),
		performanceSchema: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: globalStatus,
			Name:      "performance_schema_total",
			Help:      "Mysql instrumentations that could not be loaded or created due to memory constraints",
		}, []string{"instrumentation"}),
	}
}
Esempio n. 25
0
// Takes a prometheus registry and returns a new Collector exposing
// load1 stat.
func NewLoadavgCollector() (Collector, error) {
	return &loadavgCollector{
		metric: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: Namespace,
			Name:      "load1",
			Help:      "1m load average.",
		}),
	}, nil
}
Esempio n. 26
0
// New constructs a neww Notifier.
func New(o *Options) *Notifier {
	ctx, cancel := context.WithCancel(context.Background())

	return &Notifier{
		queue:  make(model.Alerts, 0, o.QueueCapacity),
		ctx:    ctx,
		cancel: cancel,
		more:   make(chan struct{}, 1),
		opts:   o,

		latency: prometheus.NewSummaryVec(prometheus.SummaryOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "latency_seconds",
			Help:      "Latency quantiles for sending alert notifications (not including dropped notifications).",
		},
			[]string{alertmanagerLabel},
		),
		errors: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "errors_total",
			Help:      "Total number of errors sending alert notifications.",
		},
			[]string{alertmanagerLabel},
		),
		sent: prometheus.NewCounterVec(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "sent_total",
			Help:      "Total number of alerts successfully sent.",
		},
			[]string{alertmanagerLabel},
		),
		dropped: prometheus.NewCounter(prometheus.CounterOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "dropped_total",
			Help:      "Total number of alerts dropped due to alert manager missing in configuration.",
		}),
		queueLength: prometheus.NewGauge(prometheus.GaugeOpts{
			Namespace: namespace,
			Subsystem: subsystem,
			Name:      "queue_length",
			Help:      "The number of alert notifications in the queue.",
		}),
		queueCapacity: prometheus.MustNewConstMetric(
			prometheus.NewDesc(
				prometheus.BuildFQName(namespace, subsystem, "queue_capacity"),
				"The capacity of the alert notifications queue.",
				nil, nil,
			),
			prometheus.GaugeValue,
			float64(o.QueueCapacity),
		),
	}
}
Esempio n. 27
0
func (_ prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
	depth := prometheus.NewGauge(prometheus.GaugeOpts{
		Subsystem: name,
		Name:      "depth",
		Help:      "Current depth of workqueue: " + name,
	})
	prometheus.Register(depth)
	return depth
}
Esempio n. 28
0
// NewSensors creates new sensors from a raw config
func NewSensors(raw []interface{}) ([]*Sensor, error) {
	var sensors []*Sensor
	if err := utils.DecodeRaw(raw, &sensors); err != nil {
		return nil, fmt.Errorf("Sensor configuration error: %v", err)
	}
	for _, s := range sensors {
		check, err := commands.NewCommand(s.CheckExec, s.Timeout)
		if err != nil {
			return nil, fmt.Errorf("could not parse check in sensor %s: %s", s.Name, err)
		}
		check.Name = fmt.Sprintf("%s.sensor", s.Name)
		s.checkCmd = check

		// the prometheus client lib's API here is baffling... they don't expose
		// an interface or embed their Opts type in each of the Opts "subtypes",
		// so we can't share the initialization.
		switch {
		case s.Type == "counter":
			s.collector = prometheus.NewCounter(prometheus.CounterOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "gauge":
			s.collector = prometheus.NewGauge(prometheus.GaugeOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "histogram":
			s.collector = prometheus.NewHistogram(prometheus.HistogramOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		case s.Type == "summary":
			s.collector = prometheus.NewSummary(prometheus.SummaryOpts{
				Namespace: s.Namespace,
				Subsystem: s.Subsystem,
				Name:      s.Name,
				Help:      s.Help,
			})
		default:
			return nil, fmt.Errorf("invalid sensor type: %s", s.Type)
		}
		// we're going to unregister before every attempt to register
		// so that we can reload config
		prometheus.Unregister(s.collector)
		if err := prometheus.Register(s.collector); err != nil {
			return nil, err
		}
	}
	return sensors, nil
}
Esempio n. 29
0
func newMetric(metricName string, docString string) prometheus.Gauge {
	return prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: namespace,
			Name:      metricName,
			Help:      docString,
		},
	)
}
Esempio n. 30
0
// NewExporter returns an initialized exporter
func NewExporter(server string) *Exporter {
	return &Exporter{
		mc: memcache.New(server),
		up: prometheus.NewGauge(
			prometheus.GaugeOpts{
				Name:        "up",
				Namespace:   namespace,
				Help:        "Are the servers up.",
				ConstLabels: prometheus.Labels{"server": server},
			},
		),
		uptime: prometheus.NewCounter(
			prometheus.CounterOpts{
				Name:        "uptime",
				Namespace:   namespace,
				Help:        "The uptime of the server.",
				ConstLabels: prometheus.Labels{"server": server},
			},
		),
		cache: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Name:        "cache",
				Namespace:   namespace,
				Help:        "The cache hits/misses broken down by command (get, set, etc.).",
				ConstLabels: prometheus.Labels{"server": server},
			},
			[]string{"command", "status"},
		),
		usage: prometheus.NewGaugeVec(
			prometheus.GaugeOpts{
				Name:        "usage",
				Namespace:   namespace,
				Help:        "Details the resource usage (items/connections) of the server, by time (current/total).",
				ConstLabels: prometheus.Labels{"server": server},
			},
			[]string{"time", "resource"},
		),
		bytes: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Name:        "bytes",
				Namespace:   namespace,
				Help:        "The bytes sent/received by the server.",
				ConstLabels: prometheus.Labels{"server": server},
			},
			[]string{"direction"},
		),
		removals: prometheus.NewCounterVec(
			prometheus.CounterOpts{
				Name:        "removal",
				Namespace:   namespace,
				Help:        "Number of items that have been evicted/expired (status), and if the were fetched ever or not.",
				ConstLabels: prometheus.Labels{"server": server},
			},
			[]string{"status", "fetched"},
		),
	}
}