Example #1
0
	"time"

	Mdb "github.com/open-falcon/common/db"
	cron "github.com/toolkits/cron"
	ntime "github.com/toolkits/time"

	"github.com/timercrack/task/proc"
)

const (
	indexDeleteCronSpec = "0 0 2 ? * 6" // 每周6晚上22:00执行一次
	deteleStepInSec     = 7 * 24 * 3600 // 索引的最大生存周期, sec
)

var (
	indexDeleteCron = cron.New()
)

// 启动 索引全量更新 定时任务
func StartIndexDeleteTask() {
	indexDeleteCron.AddFuncCC(indexDeleteCronSpec, func() { DeleteIndex() }, 1)
	indexDeleteCron.Start()
}

// 索引的全量更新
func DeleteIndex() {
	startTs := time.Now().Unix()
	deleteIndex()
	endTs := time.Now().Unix()
	log.Printf("deleteIndex, start %s, ts %ds", ntime.FormatTs(startTs), endTs-startTs)
Example #2
0
	"log"
	"time"

	cmodel "github.com/open-falcon/common/model"
	cutils "github.com/open-falcon/common/utils"
	tcron "github.com/toolkits/cron"
	ttime "github.com/toolkits/time"

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

var (
	judgeCron     = tcron.New()
	judgeCronSpec = "0 * * * * ?"
)

func StartJudgeCron() {
	judgeCron.AddFuncCC(judgeCronSpec, func() {
		start := time.Now().Unix()
		judge()
		end := time.Now().Unix()
		if g.Config().Debug {
			log.Printf("judge cron, time %ds, start %s\n", end-start, ttime.FormatTs(start))
		}

		// statistics
		g.JudgeCronCnt.Incr()
		g.JudgeLastTs.SetCnt(end - start)
Example #3
0
	"time"

	cron "github.com/toolkits/cron"
	nhttpclient "github.com/toolkits/http/httpclient"
	ntime "github.com/toolkits/time"

	"github.com/timercrack/task/g"
	"github.com/timercrack/task/proc"
)

const (
	destUrlFmt = "http://%s/index/updateAll"
)

var (
	indexUpdateAllCron = cron.New()
)

// 启动 索引全量更新 定时任务
func StartIndexUpdateAllTask() {
	for graphAddr, cronSpec := range g.Config().Index.Cluster {
		ga := graphAddr
		indexUpdateAllCron.AddFuncCC(cronSpec, func() { UpdateIndexOfOneGraph(ga, "cron") }, 1)
	}

	indexUpdateAllCron.Start()
}

// 手动触发全量更新
func UpdateAllIndex() {
	for graphAddr, _ := range g.Config().Index.Cluster {
Example #4
0
	"sync"
	"time"

	cmodel "github.com/open-falcon/common/model"
	tcron "github.com/toolkits/cron"
	thttpclient "github.com/toolkits/http/httpclient"
	ttime "github.com/toolkits/time"

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

var (
	lock              = sync.RWMutex{}
	avg       float64 = -100
	dev       float64 = 0
	gaussCron         = tcron.New()
)

func startGaussCron() {
	if !g.Config().Sender.Block.EnableGauss {
		log.Println("sender.StartGaussCron warning, not enabled")
		return
	}

	// start gauss cron
	gaussCron.AddFuncCC("40 */20 * * * ?", func() {
		start := time.Now().Unix()
		cnt := calcGaussOnce()
		end := time.Now().Unix()
		if g.Config().Debug {
			log.Printf("gause cron, cnt %d, time %ds, start %s\n", cnt, end-start, ttime.FormatTs(start))
Example #5
0
	"net/http"
	"os"
	"strings"
	"time"

	cmodel "github.com/open-falcon/common/model"
	cron "github.com/toolkits/cron"
	nhttpclient "github.com/toolkits/http/httpclient"
	ntime "github.com/toolkits/time"

	"github.com/open-falcon/task/g"
	"github.com/open-falcon/task/proc"
)

var (
	collectorCron = cron.New()
	srcUrlFmt     = "http://%s/statistics/all"
	destUrl       = "http://127.0.0.1:1988/v1/push"
)

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

	// init url
	if g.Config().Collector.DestUrl != "" {
		destUrl = g.Config().Collector.DestUrl
	}
	if g.Config().Collector.SrcUrlFmt != "" {
Example #6
0
	"github.com/open-falcon/task/proc"
	nsema "github.com/toolkits/concurrent/semaphore"
	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()
	})
Example #7
0
import (
	"log"
	"time"

	"github.com/toolkits/container/nmap"
	tcron "github.com/toolkits/cron"
	ttime "github.com/toolkits/time"

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

var (
	ndconfigCron     = tcron.New()
	ndconfigCronSpec = "50 */2 * * * ?"
)

func StartNdConfigCron() {
	ndconfigCron.AddFuncCC(ndconfigCronSpec, func() {
		start := time.Now().Unix()
		cnt, _ := syncNdConfig()
		end := time.Now().Unix()
		if g.Config().Debug {
			log.Printf("config cron, cnt %d, time %ds, start %s\n", cnt, end-start, ttime.FormatTs(start))
		}

		// statistics
		g.ConfigCronCnt.Incr()
		g.ConfigLastTs.SetCnt(end - start)
Example #8
0
	"net/http"
	"time"

	cmodel "github.com/open-falcon/common/model"
	cutils "github.com/open-falcon/common/utils"
	tsema "github.com/toolkits/concurrent/semaphore"
	tcron "github.com/toolkits/cron"
	thttpclient "github.com/toolkits/http/httpclient"
	ttime "github.com/toolkits/time"

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

var (
	collectorCron = tcron.New()
)

func StartCollectorCron() {
	collectorCron.AddFuncCC("*/20 * * * * ?", func() {
		start := time.Now().Unix()
		cnt := collectDataOnce()
		end := time.Now().Unix()
		if g.Config().Debug {
			log.Printf("collect cron, cnt %d, time %ds, start %s\n", cnt, end-start, ttime.FormatTs(start))
		}

		// statistics
		g.CollectorCronCnt.Incr()
		g.CollectorLastTs.SetCnt(end - start)
		g.CollectorLastCnt.SetCnt(int64(cnt))