Example #1
0
func syncNdConfig() (cnt int, errt error) {
	// get configs
	configs := service.GetMockCfgFromDB()
	// restruct
	nm := nmap.NewSafeMap()
	for _, ndc := range configs {
		endpoint := ndc.Endpoint
		metric := ndc.Metric
		tags := ndc.Tags
		if endpoint == "" {
			log.Printf("bad config: %+v\n", ndc)
			continue
		}
		pk := cutils.PK(endpoint, metric, tags)
		nm.Put(pk, ndc)
	}

	// cache
	SetNdConfigMap(nm)

	return nm.Size(), nil
}
Example #2
0
	"log"
	"net/http"
	"time"

	cmodel "github.com/open-falcon/common/model"
	tsema "github.com/toolkits/concurrent/semaphore"
	"github.com/toolkits/container/nmap"
	thttpclient "github.com/toolkits/http/httpclient"
	ttime "github.com/toolkits/time"

	"github.com/open-falcon/nodata/config"
	"github.com/open-falcon/nodata/g"
)

var (
	MockMap = nmap.NewSafeMap()
	sema    = tsema.NewSemaphore(1)
)

func Start() {
	if !g.Config().Sender.Enabled {
		log.Println("sender.Start warning, not enabled")
		return
	}
	startGaussCron()
	log.Println("sender.Start ok")
}

func AddMock(key string, endpoint string, metric string, tags string, ts int64, dstype string, step int64, value interface{}) {
	item := &cmodel.JsonMetaData{metric, endpoint, ts, step, value, dstype, tags}
	MockMap.Put(key, item)
Example #3
0
func NewHttpClientPool() *HttpClientPool {
	return &HttpClientPool{httpClientMap: nmap.NewSafeMap()}
}
Example #4
0
import (
	"fmt"
	"log"

	tlist "github.com/toolkits/container/list"
	"github.com/toolkits/container/nmap"
	ttime "github.com/toolkits/time"

	"github.com/open-falcon/nodata/g"
)

// 主动收集到的监控数据 的缓存
var (
	// map - list
	ItemMap = nmap.NewSafeMap()
)

func Start() {
	if !g.Config().Collector.Enabled {
		log.Println("collector.Start warning, not enabled")
		return
	}

	StartCollectorCron()
	log.Println("collector.Start ok")
}

// Interfaces Of ItemMap
func GetFirstItem(key string) (*DataItem, bool) {
	listv, found := ItemMap.Get(key)
Example #5
0
package store

import (
	"github.com/open-falcon/common/model"
	tlist "github.com/toolkits/container/list"
	tmap "github.com/toolkits/container/nmap"
)

const (
	defaultHistorySize = 3
)

var (
	HistoryCache = tmap.NewSafeMap()
)

func GetLastItem(key string) *model.GraphItem {
	itemlist, found := HistoryCache.Get(key)
	if !found || itemlist == nil {
		return &model.GraphItem{}
	}

	first := itemlist.(*tlist.SafeListLimited).Front()
	if first == nil {
		return &model.GraphItem{}
	}

	return first.(*model.GraphItem)
}

func GetAllItems(key string) []*model.GraphItem {
Example #6
0
	nmap "github.com/toolkits/container/nmap"
	ncron "github.com/toolkits/cron"
	nhttpclient "github.com/toolkits/http/httpclient"
	ntime "github.com/toolkits/time"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
	"sync"
	"time"
)

var (
	monitorCron = ncron.New()
	sema        = nsema.NewSemaphore(1)
	statusCache = nmap.NewSafeMap()
	alarmCache  = nmap.NewSafeMap()
	cronSpec    = "30 * * * * ?"
)

func Start() {
	if !g.Config().Monitor.Enabled {
		log.Println("monitor.Start, not enable")
		return
	}
	//
	monitorCron.AddFunc(cronSpec, func() {
		monitor()
	})
	monitorCron.Start()
	go alarmJudge()
Example #7
0
import (
	"log"
	"sync"

	cmodel "github.com/open-falcon/common/model"
	"github.com/toolkits/container/nmap"

	"github.com/open-falcon/nodata/config/service"
	"github.com/open-falcon/nodata/g"
)

// nodata配置(mockcfg)的缓存, 这些数据来自配置中心
var (
	rwlock      = sync.RWMutex{}
	NdConfigMap = nmap.NewSafeMap()
)

func Start() {
	if !g.Config().Config.Enabled {
		log.Println("config.Start warning, not enabled")
		return
	}

	service.InitDB()
	StartNdConfigCron()
	log.Println("config.Start ok")
}

// Interfaces Of StrategyMap
func SetNdConfigMap(val *nmap.SafeMap) {
Example #8
0
package judge

import (
	"fmt"
	"sync"

	"github.com/toolkits/container/nmap"
	ttime "github.com/toolkits/time"
)

// Nodata Status Cache
var (
	statusLock = sync.RWMutex{}
	StatusMap  = nmap.NewSafeMap()
)

func LastTs(key string) int64 {
	statusLock.RLock()

	var ts int64 = 0
	v, found := StatusMap.Get(key)
	if !found {
		statusLock.RUnlock()
		return ts
	}

	ts = v.(*NodataStatus).Ts

	statusLock.RUnlock()
	return ts
}