implementata l'opzione DEBUG
forzata l'ora in UTC
This commit is contained in:
parent
cecc92066d
commit
4bf4821015
2 changed files with 15 additions and 9 deletions
11
main.go
11
main.go
|
@ -4,7 +4,6 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gopkg.in/mgo.v2"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -12,6 +11,8 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"gopkg.in/mgo.v2"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
|
@ -23,6 +24,7 @@ type Options struct {
|
|||
TimeStart time.Time
|
||||
DateStop time.Duration
|
||||
Version bool
|
||||
Debug bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -38,7 +40,7 @@ var (
|
|||
opts = Options{
|
||||
MongoUri: "mongodb://127.0.0.1:27018",
|
||||
LogFile: "log/imp.log",
|
||||
DateStart: time.Now().Add(-time.Hour).Format(_tformat),
|
||||
DateStart: time.Now().UTC().Add(-time.Hour).Format(_tformat),
|
||||
DateStop: time.Hour,
|
||||
}
|
||||
mimp = MongoImp{}
|
||||
|
@ -55,7 +57,7 @@ func connectMongo() {
|
|||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Println("Usage: imp_mongo -d <date (yyyy-mm-dd:hh)> -r <date range (HHh)> -m <mongodb uri> -l <logfile> -v\n")
|
||||
fmt.Println("Usage: imp_mongo -d <date (yyyy-mm-dd:hh)> -r <date range (HHh)> -m <mongodb uri> -l <logfile> -v -D\n")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
@ -71,6 +73,7 @@ func init() {
|
|||
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
|
||||
flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>")
|
||||
flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h")
|
||||
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
||||
flag.BoolVar(&opts.Version, "v", false, "Version")
|
||||
}
|
||||
|
||||
|
@ -141,8 +144,6 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
// fmt.Printf("%+v\n", mimp)
|
||||
|
||||
fmt.Printf("Stop: %v\n", time.Since(start))
|
||||
log.Printf("Stop: %v\n", time.Since(start))
|
||||
}
|
||||
|
|
11
parser.go
11
parser.go
|
@ -2,7 +2,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -113,9 +113,11 @@ func parse(body string, stime time.Time) {
|
|||
index.Date = stime
|
||||
} else if strings.HasPrefix(lines[ind], "counters") {
|
||||
k := strings.Split(lines[ind], ";")
|
||||
// fmt.Printf("%s = %s\n", k[0], k[1])
|
||||
key := strings.Split(k[0], "/")
|
||||
if opts.Debug {
|
||||
// fmt.Printf("%s = %s\n", k[0], k[1])
|
||||
// fmt.Printf("Keys: %s - %s - %s\n", key[0], key[1], key[2])
|
||||
}
|
||||
if key[0] == "counters" {
|
||||
switch key[1] {
|
||||
case "banner":
|
||||
|
@ -201,5 +203,8 @@ func parse(body string, stime time.Time) {
|
|||
if err != nil {
|
||||
log.Println("Insert Errro: ", err)
|
||||
}
|
||||
// fmt.Printf("%+v\n", info)
|
||||
|
||||
if opts.Debug {
|
||||
fmt.Printf("%+v\n", mimp)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue