Ejemplo n.º 1
0
func InitMetaData() error {
	cfg.GetLogger().Info("Initializing meta data...")
	err := db.Update(func(tx *bolt.Tx) error {
		bucket, err := tx.CreateBucketIfNotExists([]byte(BUCKET_META))
		if err != nil {
			return err
		}

		var data []Meta
		jsonData := bucket.Get([]byte(META_DATA))
		if jsonData != nil {
			json.Unmarshal(jsonData, &data)
		}

		dbsMeta := make(map[string]string)
		for _, meta := range data {
			dbsMeta[meta.Title] = meta.Title
			if _, ok := cfg.GetConfig().GetDBByTitle(meta.Title); !ok {
				cfg.GetLogger().Info("DB not found in config, cleaning up", "title", meta.Title)
				// TODO: remove unused DB data
			}
		}

		for _, dbData := range cfg.GetConfig().Dbs {
			if _, ok := dbsMeta[dbData.Title]; !ok {
				cfg.GetLogger().Info("New DB to monitor", "title", dbData.Title)
			}
		}

		return nil
	})
	return err
}
Ejemplo n.º 2
0
func UpdateDB(title string) error {
	cfg.GetLogger().Info("Trying to update", "DB", title)

	var dbData cfg.DB
	var ok bool
	if dbData, ok = cfg.GetConfig().GetDBByTitle(title); !ok {
		return setDBStatusFailed(title, "Failed to get db data from config")
	}

	adapter, err := adapter.New(dbData)
	if err != nil {
		return err
	}
	tables, err := adapter.ListTables()
	if err != nil {
		return err
	}
	for _, table := range tables {
		table.State, err = adapter.GetState(table)
		if err != nil {
			return err
		}

		cfg.GetLogger().Debug("Got table status", "table", table, "filling", fmt.Sprintf("%.10f", table.State.Filling))
		if cfg.GetConfig().Debug {
			pp.Println(table)
		}
	}

	return err
}
Ejemplo n.º 3
0
func render(c *gin.Context, template string, ctx map[string]interface{}) {
	config := cfg.GetConfig()

	ctx["instance_id"] = cfg.InstanceId()
	ctx["url_path"] = c.Request.URL.Path
	ctx["date_format"] = config.Ui.DateFormat

	c.Set("template", fmt.Sprintf("%s/templates/%s/%s", cfg.RootDir(), config.Ui.Theme, template))
	c.Set("data", ctx)
	c.Writer.WriteHeader(http.StatusOK)
}