Example #1
0
func (o *FileOutput) openFile() (err error) {
	basePath := filepath.Dir(o.path)
	if err = os.MkdirAll(basePath, o.folderPerm); err != nil {
		return fmt.Errorf("Can't create the basepath for the FileOutput plugin: %s", err.Error())
	}
	if err = plugins.CheckWritePermission(basePath); err != nil {
		return
	}
	o.file, err = os.OpenFile(o.path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, o.perm)
	return
}
Example #2
0
func (o *WhisperOutput) Init(config interface{}) (err error) {
	conf := config.(*WhisperOutputConfig)
	globals := o.pConfig.Globals
	o.basePath = globals.PrependBaseDir(conf.BasePath)
	o.defaultAggMethod = conf.DefaultAggMethod

	var intPerm int64
	if intPerm, err = strconv.ParseInt(conf.FolderPerm, 8, 32); err != nil {
		err = fmt.Errorf("WhisperOutput '%s' can't parse `folder_perm`, ",
			"is it an octal integer string?", o.basePath)
		return
	}
	o.folderPerm = os.FileMode(intPerm)

	if err = os.MkdirAll(o.basePath, o.folderPerm); err != nil {
		return
	}

	if err = plugins.CheckWritePermission(o.basePath); err != nil {
		return
	}

	if conf.DefaultArchiveInfo == nil {
		// 60 seconds per datapoint, 1440 datapoints = 1 day of retention
		// 15 minutes per datapoint, 8 datapoints = 2 hours of retention
		// 1 hour per datapoint, 7 days of retention
		// 12 hours per datapoint, 2 years of retention
		conf.DefaultArchiveInfo = [][]uint32{
			{0, 60, 1440}, {0, 900, 8}, {0, 3600, 168}, {0, 43200, 1456},
		}
	}

	o.defaultArchiveInfo = make([]whisper.ArchiveInfo, len(conf.DefaultArchiveInfo))
	for i, aiSpec := range conf.DefaultArchiveInfo {
		if len(aiSpec) != 3 {
			err = fmt.Errorf("All default archive info settings must have 3 values.")
			return
		}
		o.defaultArchiveInfo[i] = whisper.ArchiveInfo{aiSpec[0], aiSpec[1], aiSpec[2]}
	}
	o.dbs = make(map[string]WhisperRunner)
	return
}