memorizza il totale dello storage su variabile locale

This commit is contained in:
Michele 2017-03-30 16:27:03 +02:00
parent e1b13718bf
commit 73cfd49a17
6 changed files with 62 additions and 15 deletions

View file

@ -2,6 +2,6 @@ FROM scratch
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
COPY quota_mongodb-v2.1.1 /bin/quota_mongodb
COPY quota_mongodb-v2.2.1 /bin/quota_mongodb
ENTRYPOINT [ "/bin/quota_mongodb" ]

View file

@ -1,3 +1,5 @@
#!/bin/bash
docker build -t mikif70/qmongo:2.1.1 .
VER=$1
docker build -t mikif70/qmongo:$VER .

View file

@ -31,6 +31,8 @@ func consumer() {
for {
lstart := time.Now()
prod := <-consume
status = _Consumer
@ -55,6 +57,16 @@ func consumer() {
bulk.Insert(mquota)
counter <- Counterchan{
tipo: "msg",
val: prod[p].messages,
}
counter <- Counterchan{
tipo: "storage",
val: prod[p].storage,
}
if opts.Test {
log.Printf("OK: %s\n", prod[p].user)
}
@ -71,7 +83,7 @@ func consumer() {
}
if opts.Debug {
fmt.Printf("CONS: users=%d in %v - active=%d\n", len(prod), time.Since(start), dbs.rdb.ActiveCount())
fmt.Printf("CONS: users=%d in %v - active=%d\n", len(prod), time.Since(lstart), dbs.rdb.ActiveCount())
}
wg.Done()

View file

@ -20,6 +20,8 @@ type Counter struct {
dup int
time time.Duration
wg int
msg int
storage int
}
// NewCounter iniitialized Counter structure
@ -53,11 +55,25 @@ func (c *Counter) Run() {
}
case "err":
c.addErr(tocount.val)
case "msg":
c.addMsg(tocount.val)
case "storage":
c.addStorage(tocount.val)
}
}
}
// AddStorage
func (c *Counter) addStorage(add int) {
c.storage += add
}
// AddMsg
func (c *Counter) addMsg(add int) {
c.msg += add
}
// AddUser increment number of users managed
func (c *Counter) addUser() {
c.user++
@ -88,6 +104,22 @@ func (c *Counter) delWG() {
c.wg--
}
// GetStorage
func (c *Counter) GetStorage() (ret int) {
c.mu.Lock()
defer c.mu.Unlock()
ret = c.storage
return
}
// GetMsg
func (c *Counter) GetMsg() (ret int) {
c.mu.Lock()
defer c.mu.Unlock()
ret = c.msg
return
}
// GetUser return total users
func (c *Counter) GetUser() (ret int) {
c.mu.Lock()

View file

@ -79,12 +79,13 @@ func writeStats() {
return
}
qtot := getStorage()
// qtot := getStorage()
tags := map[string]string{"server": infhost, "domain": "quota"}
fields := map[string]interface{}{
"user": count.GetUser(),
"storage": qtot,
"storage": count.GetStorage(),
"msg": count.GetMsg(),
"stop": count.GetTime(),
}
pt, err := influxdb.NewPoint("qmongo", tags, fields, start)

View file

@ -12,7 +12,7 @@ import (
)
const (
_Version = "v2.1.1"
_Version = "v2.2.1"
_Producer = 0
_Consumer = 1
)
@ -115,8 +115,8 @@ func main() {
count.SetTime(time.Since(start))
fmt.Printf("Stop %v - user: %d\n\r", count.GetTime(), count.GetUser())
log.Printf("Stop %v - user: %d\n\r", count.GetTime(), count.GetUser())
fmt.Printf("Stop %v - user: %d - Storage: %d\n\r", count.GetTime(), count.GetUser(), count.GetStorage())
log.Printf("Stop %v - user: %d - Storage: %d\n\r", count.GetTime(), count.GetUser(), count.GetStorage())
if opts.Influxdb != "" {
writeStats()