Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
7b67503f3a |
6 changed files with 82 additions and 20 deletions
7
Docker/Dockerfile
Normal file
7
Docker/Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
|||
FROM scratch
|
||||
|
||||
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
|
||||
|
||||
COPY imp_mongodb-v1.1.0 /bin/imp_mongodb
|
||||
|
||||
ENTRYPOINT [ "/bin/imp_mongodb" ]
|
BIN
Docker/imp_mongodb-v1.1.0
Executable file
BIN
Docker/imp_mongodb-v1.1.0
Executable file
Binary file not shown.
14
Docker/run.sh
Normal file
14
Docker/run.sh
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker run \
|
||||
--rm \
|
||||
-v /opt/impmongo/log:/data \
|
||||
--name impmongo \
|
||||
--log-opt max-size=2m \
|
||||
--log-opt max-file=5 \
|
||||
mikif70/impmongo:1.1.0 \
|
||||
-l /data/llmongo.log \
|
||||
-p /data/llmongo.pid \
|
||||
-m mongodb://10.39.80.189:27017 \
|
||||
-i http://10.39.109.107:8086 \
|
||||
$@
|
3
build.sh
Executable file
3
build.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo .
|
10
influxdb.go
10
influxdb.go
|
@ -55,6 +55,15 @@ func writeStats(mimp *MongoImp) {
|
|||
"rate_smtp": mimp.Rate.Smtpp,
|
||||
"rate_total": mimp.Rate.Totalp,
|
||||
}
|
||||
if opts.Out {
|
||||
pt, err := influxdb.NewPoint("cloudmark_out", tags, fields, mimp.Date)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %+v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
bp.AddPoint(pt)
|
||||
} else {
|
||||
pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %+v\n", err)
|
||||
|
@ -62,6 +71,7 @@ func writeStats(mimp *MongoImp) {
|
|||
}
|
||||
|
||||
bp.AddPoint(pt)
|
||||
}
|
||||
|
||||
// Write the batch
|
||||
c.Write(bp)
|
||||
|
|
28
main.go
28
main.go
|
@ -24,6 +24,7 @@ type Options struct {
|
|||
DateStart string
|
||||
TimeStart time.Time
|
||||
DateStop time.Duration
|
||||
Out bool
|
||||
Version bool
|
||||
Debug bool
|
||||
}
|
||||
|
@ -38,6 +39,7 @@ const (
|
|||
|
||||
var (
|
||||
_imp = [...]string{"cmgw-1", "cmgw-2", "cmgw-3", "cmgw-4"}
|
||||
_out = [...]string{"michael", "santino"}
|
||||
opts = Options{
|
||||
MongoUri: "mongodb://127.0.0.1:27018",
|
||||
LogFile: "log/imp.log",
|
||||
|
@ -54,7 +56,12 @@ func connectMongo() {
|
|||
log.Println("Mongodb connect Error: ", err.Error())
|
||||
os.Exit(-3)
|
||||
}
|
||||
if opts.Out {
|
||||
opts.ll = opts.mdb.DB("antispam").C("output")
|
||||
} else {
|
||||
opts.ll = opts.mdb.DB("antispam").C("counters")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func usage() {
|
||||
|
@ -75,6 +82,7 @@ func init() {
|
|||
flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>")
|
||||
flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h")
|
||||
flag.StringVar(&opts.Influxdb, "i", "", "Influxdb")
|
||||
flag.BoolVar(&opts.Out, "O", false, "Out")
|
||||
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
||||
flag.BoolVar(&opts.Version, "v", false, "Version")
|
||||
}
|
||||
|
@ -135,6 +143,24 @@ func main() {
|
|||
for h := 0; h < int(opts.DateStop.Hours()); h++ {
|
||||
stime := opts.TimeStart.Add(time.Hour * time.Duration(h))
|
||||
// fmt.Println("Time: ", stime)
|
||||
|
||||
if opts.Out {
|
||||
for ind := range _out {
|
||||
uri := "http://" + _out[ind] + _domain + ":" + _port + _dashboard + stime.Format("2006010215") + "00"
|
||||
// fmt.Println(uri)
|
||||
resp, err := http.Get(uri)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
parse(string(body), stime)
|
||||
}
|
||||
} else {
|
||||
for ind := range _imp {
|
||||
uri := "http://" + _imp[ind] + _domain + ":" + _port + _dashboard + stime.Format("2006010215") + "00"
|
||||
// fmt.Println(uri)
|
||||
|
@ -152,6 +178,8 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fmt.Printf("Stop: %v\n", time.Since(start))
|
||||
log.Printf("Stop: %v\n", time.Since(start))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue