2019-06-28 11:18:55 +00:00
|
|
|
package compression
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
"github.com/Masterminds/semver"
|
2019-10-11 10:36:00 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/storage"
|
2019-09-04 11:37:50 +00:00
|
|
|
"github.com/go-flucky/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 (
|
2019-10-11 10:36:00 +00:00
|
|
|
configFile *string
|
|
|
|
round float64
|
|
|
|
version *semver.Version
|
2019-09-01 10:27:06 +00:00
|
|
|
)
|
2019-06-28 11:18:55 +00:00
|
|
|
|
|
|
|
var compressionCmd = &cobra.Command{
|
|
|
|
Use: "compression",
|
|
|
|
Short: "Compress a logfile",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Example: "flucky compression /var/log/flucky/logfile.csv",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
logfileInput := logfile.New(args[0])
|
|
|
|
measuredValues, err := logfileInput.Read()
|
2019-06-28 11:18:55 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
if round != 0 {
|
|
|
|
storage.Round(measuredValues, round)
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Compression(measuredValues)
|
2019-06-28 11:18:55 +00:00
|
|
|
|
2019-10-11 10:36:00 +00:00
|
|
|
err = logfileInput.Write(measuredValues)
|
2019-06-28 11:18:55 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
func InitCmd(cmd *cobra.Command, cnfFile *string, sverion *semver.Version) {
|
2019-06-28 11:18:55 +00:00
|
|
|
configFile = cnfFile
|
2019-09-01 10:27:06 +00:00
|
|
|
version = sverion
|
|
|
|
|
2019-06-28 11:18:55 +00:00
|
|
|
cmd.AddCommand(compressionCmd)
|
2019-10-11 10:36:00 +00:00
|
|
|
compressionCmd.Flags().Float64Var(&round, "round", 0, "Round values. The value 0 deactivates the function")
|
2019-06-28 11:18:55 +00:00
|
|
|
|
|
|
|
}
|