示例#1
0
func GetEurekaClient() *EurekaClient {
	if eurekaClient != nil {
		return eurekaClient
	}
	var client *EurekaClient
	var err error
	conf := config.GetConfig()
	if conf.Eureka.Config.CertFile == "" || conf.Eureka.Config.KeyFile == "" {
		client = &EurekaClient{eureka.NewClient(conf.Eureka.Machines), conf.Instance.Name}
	} else {
		eurekaOriginalClient, err := eureka.NewTLSClient(
			conf.Eureka.Machines,
			conf.Eureka.Config.CertFile,
			conf.Eureka.Config.KeyFile,
			conf.Eureka.Config.CaCertFiles,
		)
		if err != nil {
			panic(err)
		}
		client = &EurekaClient{eurekaOriginalClient, conf.Instance.Name}
	}
	if err != nil {
		panic(err)
	}
	if conf.Eureka.Config.Consistency != "" {
		client.Config.Consistency = conf.Eureka.Config.Consistency
	}
	if conf.Eureka.Config.Timeout != 0 {
		client.Config.DialTimeout = time.Duration(conf.Eureka.Config.Timeout) * time.Second
	}
	eureka.SetLogger(logger.GetMinLog().GetLogger())
	return client
}
示例#2
0
func RunCachetMonitor() {
	componentId := 0
	strictTls := true
	cachet.LoadEmptyConfig()

	cachet.Config.APIUrl = "https://demo.cachethq.io/api"
	cachet.Config.APIToken = "9yMHsdioQosnyVK4iCVR"
	cachet.Config.InsecureAPI = false
	cachet.Config.Monitors = []*cachet.Monitor{
		&cachet.Monitor{
			Name:               "nodegear frontend",
			URL:                "https://nodegear.io/ping",
			MetricID:           0,
			Threshold:          float32(80),
			ComponentID:        &componentId,
			ExpectedStatusCode: 200,
			StrictTLS:          &strictTls,
		},
	}
	fmt.Println(cachet.Config.SystemName)
	cachet.Logger = logger.GetMinLog().GetLogger()
	log := logger.GetMinLog()

	log.Info("System: %s, API: %s\n", cachet.Config.SystemName, cachet.Config.APIUrl)
	log.Info("Starting %d monitors:\n", len(cachet.Config.Monitors))
	for _, mon := range cachet.Config.Monitors {
		log.Info(" %s: GET %s & Expect HTTP %d\n", mon.Name, mon.URL, mon.ExpectedStatusCode)
		if mon.MetricID > 0 {
			log.Info(" - Logs lag to metric id: %d\n", mon.MetricID)
		}
	}

	log.Info("\n")

	ticker := time.NewTicker(time.Minute)
	for range ticker.C {
		for _, mon := range cachet.Config.Monitors {
			go mon.Run()
		}
	}
}
示例#3
0
import (
	"github.com/ArthurHlt/gominlog"
	"github.com/ArthurHlt/microcos/config"
	"github.com/ArthurHlt/microcos/eureka_client"
	"github.com/ArthurHlt/microcos/logger"
	"github.com/ArthurHlt/microcos/server/eureka_request"
	"github.com/ArthurHlt/microcos/server/jobs_request"
	"github.com/go-martini/martini"
	"github.com/martini-contrib/auth"
	"github.com/martini-contrib/cors"
	"github.com/martini-contrib/render"
	"net"
)

var loggerServer *gominlog.MinLog = logger.GetMinLog()

type Server struct {
	Martini      *martini.ClassicMartini
	EurekaClient *eureka_client.EurekaClient
}

func NewServer() *Server {
	return &Server{
		Martini:      martini.Classic(),
		EurekaClient: eureka_client.GetEurekaClient(),
	}
}

func (this *Server) Run(withRandomPort ...bool) {
	this.Martini.Use(cors.Allow(&cors.Options{
示例#4
0
文件: db.go 项目: ArthurHlt/microcos
package db

import (
	"github.com/ArthurHlt/gominlog"
	"github.com/ArthurHlt/microcos/config"
	"github.com/ArthurHlt/microcos/db/model"
	"github.com/ArthurHlt/microcos/logger"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
	_ "github.com/mattn/go-sqlite3"
)

var dbInstance *gorm.DB

var loggerDb *gominlog.MinLog = logger.GetMinLog()

func GetDb() (*gorm.DB, error) {
	if dbInstance != nil {
		return dbInstance, nil
	}
	var db gorm.DB
	db, err := gorm.Open(config.GetConfig().Db.Driver, config.GetConfig().Db.DataSource)
	if err != nil {
		return nil, err
	}
	dbInstance = &db
	autoMigrate()
	return dbInstance, nil
}