mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 17:04:18 +02:00
add ilm forecast show
This commit is contained in:
@@ -84,6 +84,83 @@ types.Lifecycle{
|
||||
|
||||
hot for 7 days or 25Gig, then Rollover => warm 14 days => frozen 60 days => delete
|
||||
*/
|
||||
|
||||
func IlmForecastList(conf *cfg.Config) error {
|
||||
phaseData, err := getIlmPhaseData(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := printer.NewTable(conf, 8, 0)
|
||||
table.Addheaders("index", "current size", "current age", "virtual age", "min age", "min size", "current phase", "next phase")
|
||||
|
||||
for _, phase := range phaseData {
|
||||
virtualAge := virtualAge(&phase)
|
||||
|
||||
table.AddRow(
|
||||
phase.index,
|
||||
humanize.Bytes(uint64(phase.size)),
|
||||
fmt.Sprintf("%s", phase.age),
|
||||
|
||||
fmt.Sprintf("%s", virtualAge),
|
||||
|
||||
fmt.Sprintf("%s", phase.minage),
|
||||
humanize.Bytes(uint64(phase.minsize)),
|
||||
|
||||
phase.currentPhase,
|
||||
phase.nextPhase,
|
||||
)
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
return table.Print()
|
||||
}
|
||||
|
||||
// Loop over all current index phases of the current phase
|
||||
// (conf.Ilm.FromPhase). Calculate virtualAge if phase.minsize >0. If
|
||||
// the actual age is smaller than the virtual age, use this as a base,
|
||||
// otherwise use virtual age. Then look if the rollover would happen
|
||||
// within the phase.minage window (conf.Ilm.Within + current age) and
|
||||
// add the size.
|
||||
func IlmForecastShow(conf *cfg.Config) error {
|
||||
phaseData, err := getIlmPhaseData(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
within := parseDuration(conf.Ilm.Within)
|
||||
var toBeFreed int64 = 0
|
||||
|
||||
for _, phase := range phaseData {
|
||||
age := virtualAge(&phase)
|
||||
if age < phase.age {
|
||||
age = phase.age
|
||||
}
|
||||
|
||||
if age+within >= phase.minage {
|
||||
toBeFreed += phase.size
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%s bytes of data will be rolled within %s\n", humanize.Bytes(uint64(toBeFreed)), within)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func virtualAge(phase *PhaseData) time.Duration {
|
||||
if phase.minsize == 0 {
|
||||
return time.Duration(0)
|
||||
}
|
||||
|
||||
oneMinAge := phase.minage.Seconds() / 100
|
||||
oneMinSize := float64(phase.minsize) / 100
|
||||
|
||||
percentSize := float64(phase.size) / oneMinSize
|
||||
virtualAge := percentSize * oneMinAge
|
||||
|
||||
return time.Duration(virtualAge) * time.Second
|
||||
}
|
||||
|
||||
func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) {
|
||||
responses := make(chan apiResponse, 3)
|
||||
wg := &sync.WaitGroup{}
|
||||
@@ -177,33 +254,6 @@ func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func IlmForecastList(conf *cfg.Config) error {
|
||||
phaseData, err := getIlmPhaseData(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := printer.NewTable(conf, 7, 0)
|
||||
table.Addheaders("index", "current size", "current age", "min age", "min size", "current phase", "next phase")
|
||||
|
||||
for _, phase := range phaseData {
|
||||
table.AddRow(
|
||||
phase.index,
|
||||
humanize.Bytes(uint64(phase.size)),
|
||||
fmt.Sprintf("%s", phase.age),
|
||||
|
||||
fmt.Sprintf("%s", phase.minage),
|
||||
humanize.Bytes(uint64(phase.minsize)),
|
||||
|
||||
phase.currentPhase,
|
||||
phase.nextPhase,
|
||||
)
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
return table.Print()
|
||||
}
|
||||
|
||||
func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase {
|
||||
// phase list to determine which comes next
|
||||
order := []string{"hot", "warm", "cold", "frozen", "delete"}
|
||||
@@ -265,10 +315,7 @@ func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase {
|
||||
|
||||
if phase == "hot" {
|
||||
// if we're starting here, do not look for the next phase
|
||||
maxage, err := time.ParseDuration(phases[phase].Actions.Rollover.MaxAge.(string))
|
||||
if err != err {
|
||||
maxage = 0
|
||||
}
|
||||
maxage := parseDuration(phases[phase].Actions.Rollover.MaxAge.(string))
|
||||
|
||||
var maxsize int64 = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user