示例#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
}
示例#2
0
文件: sender.go 项目: ketqi/nodata
	"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)
示例#3
0
func NewHttpClientPool() *HttpClientPool {
	return &HttpClientPool{httpClientMap: nmap.NewSafeMap()}
}
示例#4
0
文件: collector.go 项目: ketqi/nodata
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)
示例#5
0
文件: history.go 项目: peteryj/graph
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 {
示例#6
0
文件: monitor.go 项目: peteryj/task
	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()
示例#7
0
文件: config.go 项目: ketqi/nodata
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) {
示例#8
0
文件: status.go 项目: ketqi/nodata
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
}