2019-06-28 11:18:55 +00:00
|
|
|
package compression
|
|
|
|
|
|
|
|
import (
|
2020-01-19 12:30:47 +00:00
|
|
|
"github.com/volker-raschek/flucky/pkg/storage"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/storage/logfile"
|
2019-06-28 11:18:55 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
var (
|
2020-01-13 21:26:41 +00:00
|
|
|
round float64
|
2019-09-01 10:27:06 +00:00
|
|
|
)
|
2019-06-28 11:18:55 +00:00
|
|
|
|
2020-01-13 21:26:41 +00:00
|
|
|
// InitCmd initialize all compression subcommands
|
|
|
|
func InitCmd(cmd *cobra.Command) error {
|
2019-06-28 11:18:55 +00:00
|
|
|
|
2020-01-13 21:26:41 +00:00
|
|
|
compressionCmd := &cobra.Command{
|
|
|
|
Use: "compression",
|
|
|
|
Short: "Compress a logfile",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Example: "flucky compression /var/log/flucky/logfile.csv",
|
|
|
|
RunE: run,
|
|
|
|
}
|
2019-09-01 10:27:06 +00:00
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
compressionCmd.Flags().Float64Var(&round, "round", 0, "Round values. The value 0 deactivates the function")
|
2020-01-13 21:26:41 +00:00
|
|
|
cmd.AddCommand(compressionCmd)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(cmd *cobra.Command, args []string) error {
|
|
|
|
logfileInput := logfile.New(args[0])
|
|
|
|
measuredValues, err := logfileInput.Read()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if round != 0 {
|
|
|
|
storage.Round(measuredValues, round)
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Compression(measuredValues)
|
|
|
|
|
|
|
|
err = logfileInput.Write(measuredValues)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-28 11:18:55 +00:00
|
|
|
|
2020-01-13 21:26:41 +00:00
|
|
|
return nil
|
2019-06-28 11:18:55 +00:00
|
|
|
}
|