Exemple #1
0
func init() {
	Connectors["facette"] = func(name string, settings map[string]interface{}) (Connector, error) {
		var err error

		c := &FacetteConnector{name: name}

		if c.upstream, err = config.GetString(settings, "upstream", true); err != nil {
			return nil, err
		}

		if c.timeout, err = config.GetInt(settings, "timeout", false); err != nil {
			return nil, err
		}
		if c.timeout <= 0 {
			c.timeout = facetteDefaultTimeout
		}

		if c.insecureTLS, err = config.GetBool(settings, "allow_insecure_tls", false); err != nil {
			return nil, err
		}

		if c.serverID, err = config.GetString(settings, "_id", true); err != nil {
			return nil, err
		}

		return c, nil
	}
}
Exemple #2
0
func init() {
	Connectors["rrd"] = func(name string, settings map[string]interface{}) (Connector, error) {
		var (
			pattern string
			err     error
		)

		c := &RRDConnector{
			name:    name,
			metrics: make(map[string]map[string]*rrdMetric),
		}

		if c.path, err = config.GetString(settings, "path", true); err != nil {
			return nil, err
		}

		if c.daemon, err = config.GetString(settings, "daemon", false); err != nil {
			return nil, err
		}

		if pattern, err = config.GetString(settings, "pattern", true); err != nil {
			return nil, err
		}

		// Check and compile regexp pattern
		if c.re, err = compilePattern(pattern); err != nil {
			return nil, fmt.Errorf("unable to compile regexp pattern: %s", err)
		}

		return c, nil
	}
}
Exemple #3
0
func init() {
	Connectors["influxdb"] = func(name string, settings map[string]interface{}) (Connector, error) {
		var (
			pattern string
			err     error
		)

		connector := &InfluxDBConnector{
			name:     name,
			host:     "localhost:8086",
			username: "******",
			password: "******",
			series:   make(map[string]map[string][2]string),
		}

		if connector.host, err = config.GetString(settings, "host", false); err != nil {
			return nil, err
		}

		if connector.useTLS, err = config.GetBool(settings, "use_tls", false); err != nil {
			return nil, err
		}

		if connector.username, err = config.GetString(settings, "username", false); err != nil {
			return nil, err
		}

		if connector.password, err = config.GetString(settings, "password", false); err != nil {
			return nil, err
		}

		if connector.database, err = config.GetString(settings, "database", true); err != nil {
			return nil, err
		}

		if pattern, err = config.GetString(settings, "pattern", true); err != nil {
			return nil, err
		}

		// Check and compile regexp pattern
		if connector.re, err = compilePattern(pattern); err != nil {
			return nil, fmt.Errorf("unable to compile regexp pattern: %s", err)
		}

		connector.client, err = influxdb.NewClient(&influxdb.ClientConfig{
			Host:     connector.host,
			Username: connector.username,
			Password: connector.password,
			Database: connector.database,
			IsSecure: connector.useTLS,
		})

		if err != nil {
			return nil, fmt.Errorf("unable to create client: %s", err)
		}

		return connector, nil
	}
}
func (server *Server) startProviderWorkers() error {
	server.providerWorkers = worker.NewWorkerPool()

	logger.Log(logger.LevelDebug, "server", "declaring providers")

	for _, prov := range server.providers {
		connectorType, err := config.GetString(prov.Config.Connector, "type", true)
		if err != nil {
			return fmt.Errorf("provider `%s' connector: %s", prov.Name, err)
		} else if _, ok := connector.Connectors[connectorType]; !ok {
			return fmt.Errorf("provider `%s' uses unknown connector type `%s'", prov.Name, connectorType)
		}

		providerWorker := worker.NewWorker()
		providerWorker.RegisterEvent(eventInit, workerProviderInit)
		providerWorker.RegisterEvent(eventShutdown, workerProviderShutdown)
		providerWorker.RegisterEvent(eventRun, workerProviderRun)
		providerWorker.RegisterEvent(eventCatalogRefresh, workerProviderRefresh)

		if err := providerWorker.SendEvent(eventInit, false, prov, connectorType); err != nil {
			logger.Log(logger.LevelWarning, "server", "in provider `%s', %s", prov.Name, err)
			logger.Log(logger.LevelWarning, "server", "discarding provider `%s'", prov.Name)
			continue
		}

		// Add worker into pool if initialization went fine
		server.providerWorkers.Add(providerWorker)

		providerWorker.SendEvent(eventRun, true, nil)

		logger.Log(logger.LevelDebug, "server", "declared provider `%s'", prov.Name)
	}

	return nil
}
Exemple #5
0
func init() {
	Connectors["graphite"] = func(settings map[string]interface{}) (Connector, error) {
		var err error

		connector := &GraphiteConnector{
			insecureTLS: false,
		}

		if connector.URL, err = config.GetString(settings, "url", true); err != nil {
			return nil, err
		}

		if connector.insecureTLS, err = config.GetBool(settings, "allow_insecure_tls", false); err != nil {
			return nil, err
		}

		if connector.timeout, err = config.GetFloat(settings, "timeout", false); err != nil {
			return nil, err
		}

		if connector.timeout <= 0 {
			connector.timeout = graphiteDefaultTimeout
		}

		return connector, nil
	}
}
Exemple #6
0
// PrepareCollection applies options defaults and fallback values, then filters entries by graphs titles and state.
func (library *Library) PrepareCollection(collection *Collection, filter string) *Collection {
	collectionTemp := &Collection{}
	*collectionTemp = *collection
	collectionTemp.Entries = nil

	refreshInterval, _ := config.GetInt(collectionTemp.Options, "refresh_interval", false)

	for _, entry := range collection.Entries {
		item, err := library.GetItem(entry.ID, LibraryItemGraph)
		if err != nil {
			continue
		}

		graph := item.(*Graph)

		// Initialize options map if needed, then set defaults
		if entry.Options == nil {
			entry.Options = make(map[string]interface{})
			entry.Options["enabled"] = true
		}

		// Check for linked graph
		if graph.Link != "" {
			entry.Options["linked"] = true
		}

		// Retrieve missing title from graph if none provided
		if title, ok := entry.Options["title"]; !ok || title == nil {
			if graph.Title != "" {
				entry.Options["title"] = graph.Title
			} else {
				entry.Options["title"] = graph.Name
			}
		}

		// Get global refresh interval if none provided
		if refreshInterval > 0 {
			if _, err := config.GetInt(entry.Options, "refresh_interval", true); err != nil {
				entry.Options["refresh_interval"] = refreshInterval
			}
		}

		if enabled, err := config.GetBool(entry.Options, "enabled", false); err != nil || !enabled {
			continue
		} else if filter != "" {
			if title, err := config.GetString(entry.Options, "title", false); err != nil ||
				!strings.Contains(strings.ToLower(title), strings.ToLower(filter)) {
				continue
			}
		}

		collectionTemp.Entries = append(collectionTemp.Entries, entry)
	}

	return collectionTemp
}
Exemple #7
0
func init() {
	Connectors["rrd"] = func(settings map[string]interface{}) (Connector, error) {
		var err error

		connector := &RRDConnector{
			metrics: make(map[string]map[string]*rrdMetric),
		}

		if connector.path, err = config.GetString(settings, "path", true); err != nil {
			return nil, err
		}

		if connector.pattern, err = config.GetString(settings, "pattern", true); err != nil {
			return nil, err
		}

		if connector.daemon, err = config.GetString(settings, "daemon", false); err != nil {
			return nil, err
		}

		return connector, nil
	}
}
Exemple #8
0
func init() {
	Connectors["graphite"] = func(name string, settings map[string]interface{}) (Connector, error) {
		var (
			pattern string
			err     error
		)

		c := &GraphiteConnector{
			name:   name,
			series: make(map[string]map[string]string),
		}

		if c.url, err = config.GetString(settings, "url", true); err != nil {
			return nil, err
		}

		if c.timeout, err = config.GetInt(settings, "timeout", false); err != nil {
			return nil, err
		}
		if c.timeout <= 0 {
			c.timeout = graphiteDefaultTimeout
		}

		if c.insecureTLS, err = config.GetBool(settings, "allow_insecure_tls", false); err != nil {
			return nil, err
		}

		if pattern, err = config.GetString(settings, "pattern", true); err != nil {
			return nil, err
		}
		if c.re, err = compilePattern(pattern); err != nil {
			return nil, fmt.Errorf("unable to compile regexp pattern: %s", err)
		}

		return c, nil
	}
}
Exemple #9
0
// FilterCollection filters collection entries by graphs titles and enable state.
func (library *Library) FilterCollection(collection *Collection, filter string) *Collection {
	collectionTemp := &Collection{}
	*collectionTemp = *collection
	collectionTemp.Entries = nil

	for _, entry := range collection.Entries {
		if enabled, err := config.GetBool(entry.Options, "enabled", false); err != nil || !enabled {
			continue
		} else if filter != "" {
			if title, err := config.GetString(entry.Options, "title", false); err != nil ||
				!strings.Contains(strings.ToLower(title), strings.ToLower(filter)) {
				continue
			}
		}

		collectionTemp.Entries = append(collectionTemp.Entries, entry)
	}

	return collectionTemp
}
Exemple #10
0
func init() {
	Connectors["facette"] = func(settings map[string]interface{}) (Connector, error) {
		var err error

		connector := &FacetteConnector{}

		if connector.upstream, err = config.GetString(settings, "upstream", true); err != nil {
			return nil, err
		}

		if connector.timeout, err = config.GetFloat(settings, "timeout", false); err != nil {
			return nil, err
		}

		if connector.timeout <= 0 {
			connector.timeout = facetteDefaultTimeout
		}

		return connector, nil
	}
}
Exemple #11
0
func init() {
	Connectors["kairosdb"] = func(name string, settings map[string]interface{}) (Connector, error) {
		var (
			aggregators interface{}
			err         error
		)

		c := &KairosdbConnector{
			name:    name,
			timeout: kairosdbDefaultTimeout,
			series:  make(map[string]map[string]kairosdbSeriesEntry),
		}

		if c.url, err = config.GetString(settings, "url", true); err != nil {
			return nil, err
		}

		if c.timeout, err = config.GetInt(settings, "timeout", false); err != nil {
			return nil, err
		}
		if c.timeout <= 0 {
			c.timeout = kairosdbDefaultTimeout
		}

		if c.insecureTLS, err = config.GetBool(settings, "allow_insecure_tls", false); err != nil {
			return nil, err
		}

		if c.sourceTags, err = config.GetStringSlice(settings, "source_tags", false); err != nil {
			return nil, err
		}

		if c.startAbsolute, err = config.GetInt(settings, "start_absolute", false); err != nil {
			return nil, err
		}
		if c.endAbsolute, err = config.GetInt(settings, "end_absolute", false); err != nil {
			return nil, err
		}

		if c.startRelative, err = config.GetJsonObj(settings, "start_relative", false); err != nil {
			return nil, err
		}
		if c.endRelative, err = config.GetJsonObj(settings, "end_relative", false); err != nil {
			return nil, err
		}

		if c.defaultAggregator, err = config.GetJsonObj(settings, "default_aggregator", false); err != nil {
			return nil, err
		}

		if aggregators, err = config.GetJsonArray(settings, "aggregators", false); err != nil {
			return nil, err
		}

		c.aggregators = compileAggregatorPatterns(aggregators, c.name)

		if c.startAbsolute > 0 && c.startRelative != nil {
			return nil, fmt.Errorf("kairosdb[%s]: start_absolute/start_relative are mutually exclusive", c.name)
		}
		if c.endAbsolute > 0 && c.endRelative != nil {
			return nil, fmt.Errorf("kairosdb[%s]: end_absolute/end_relative are mutually exclusive", c.name)
		}

		// Enforce startRelative defaults
		if c.startAbsolute <= 0 && c.startRelative == nil {
			c.startRelative = map[string]interface{}{"value": 3, "unit": "months"}
		}

		// Enforce sourceTags defaults
		if c.sourceTags == nil {
			c.sourceTags = []string{"host", "server", "device"}
		}

		version, version_array, err := kairosdbGetVersion(c)
		if err != nil {
			return nil, fmt.Errorf("kairosdb[%s]: unable to get KairosDB version: %s", c.name, err)
		}

		if version_array[0] < 1 {
			if version_array[1] <= 9 {
				if version_array[1] < 9 || (version_array[1] == 9 && version_array[2] < 4) {
					return nil, fmt.Errorf(
						"kairosdb[%s]: only KairosDB version 0.9.4 and greater are supported (%s detected)",
						c.name,
						version,
					)
				}
			}
		}

		return c, nil
	}
}