compilazione statica + Docker
This commit is contained in:
parent
85f88e40c7
commit
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 .
|
22
influxdb.go
22
influxdb.go
|
@ -55,13 +55,23 @@ func writeStats(mimp *MongoImp) {
|
||||||
"rate_smtp": mimp.Rate.Smtpp,
|
"rate_smtp": mimp.Rate.Smtpp,
|
||||||
"rate_total": mimp.Rate.Totalp,
|
"rate_total": mimp.Rate.Totalp,
|
||||||
}
|
}
|
||||||
pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date)
|
if opts.Out {
|
||||||
if err != nil {
|
pt, err := influxdb.NewPoint("cloudmark_out", tags, fields, mimp.Date)
|
||||||
fmt.Printf("Error: %+v\n", err)
|
if err != nil {
|
||||||
return
|
fmt.Printf("Error: %+v\n", err)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
bp.AddPoint(pt)
|
bp.AddPoint(pt)
|
||||||
|
} else {
|
||||||
|
pt, err := influxdb.NewPoint("cloudmark", tags, fields, mimp.Date)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error: %+v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bp.AddPoint(pt)
|
||||||
|
}
|
||||||
|
|
||||||
// Write the batch
|
// Write the batch
|
||||||
c.Write(bp)
|
c.Write(bp)
|
||||||
|
|
56
main.go
56
main.go
|
@ -24,6 +24,7 @@ type Options struct {
|
||||||
DateStart string
|
DateStart string
|
||||||
TimeStart time.Time
|
TimeStart time.Time
|
||||||
DateStop time.Duration
|
DateStop time.Duration
|
||||||
|
Out bool
|
||||||
Version bool
|
Version bool
|
||||||
Debug bool
|
Debug bool
|
||||||
}
|
}
|
||||||
|
@ -38,6 +39,7 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_imp = [...]string{"cmgw-1", "cmgw-2", "cmgw-3", "cmgw-4"}
|
_imp = [...]string{"cmgw-1", "cmgw-2", "cmgw-3", "cmgw-4"}
|
||||||
|
_out = [...]string{"michael", "santino"}
|
||||||
opts = Options{
|
opts = Options{
|
||||||
MongoUri: "mongodb://127.0.0.1:27018",
|
MongoUri: "mongodb://127.0.0.1:27018",
|
||||||
LogFile: "log/imp.log",
|
LogFile: "log/imp.log",
|
||||||
|
@ -54,7 +56,12 @@ func connectMongo() {
|
||||||
log.Println("Mongodb connect Error: ", err.Error())
|
log.Println("Mongodb connect Error: ", err.Error())
|
||||||
os.Exit(-3)
|
os.Exit(-3)
|
||||||
}
|
}
|
||||||
opts.ll = opts.mdb.DB("antispam").C("counters")
|
if opts.Out {
|
||||||
|
opts.ll = opts.mdb.DB("antispam").C("output")
|
||||||
|
} else {
|
||||||
|
opts.ll = opts.mdb.DB("antispam").C("counters")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
|
@ -75,6 +82,7 @@ func init() {
|
||||||
flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>")
|
flag.StringVar(&opts.DateStart, "d", opts.DateStart, "From Date <YYYY-MM-DD:HH>")
|
||||||
flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h")
|
flag.DurationVar(&opts.DateStop, "r", opts.DateStop, "Duration <HH>h")
|
||||||
flag.StringVar(&opts.Influxdb, "i", "", "Influxdb")
|
flag.StringVar(&opts.Influxdb, "i", "", "Influxdb")
|
||||||
|
flag.BoolVar(&opts.Out, "O", false, "Out")
|
||||||
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
||||||
flag.BoolVar(&opts.Version, "v", false, "Version")
|
flag.BoolVar(&opts.Version, "v", false, "Version")
|
||||||
}
|
}
|
||||||
|
@ -135,21 +143,41 @@ func main() {
|
||||||
for h := 0; h < int(opts.DateStop.Hours()); h++ {
|
for h := 0; h < int(opts.DateStop.Hours()); h++ {
|
||||||
stime := opts.TimeStart.Add(time.Hour * time.Duration(h))
|
stime := opts.TimeStart.Add(time.Hour * time.Duration(h))
|
||||||
// fmt.Println("Time: ", stime)
|
// fmt.Println("Time: ", stime)
|
||||||
for ind := range _imp {
|
|
||||||
uri := "http://" + _imp[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)
|
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)
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Stop: %v\n", time.Since(start))
|
fmt.Printf("Stop: %v\n", time.Since(start))
|
||||||
|
|
Loading…
Add table
Reference in a new issue