memorizza il totale dello storage su variabile locale
This commit is contained in:
parent
e1b13718bf
commit
73cfd49a17
6 changed files with 62 additions and 15 deletions
|
@ -2,6 +2,6 @@ FROM scratch
|
||||||
|
|
||||||
MAINTAINER Michele Fadda "<mikif70@gmail.com>"
|
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" ]
|
ENTRYPOINT [ "/bin/quota_mongodb" ]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
docker build -t mikif70/qmongo:2.1.1 .
|
VER=$1
|
||||||
|
|
||||||
|
docker build -t mikif70/qmongo:$VER .
|
||||||
|
|
14
consumer.go
14
consumer.go
|
@ -31,6 +31,8 @@ func consumer() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
lstart := time.Now()
|
||||||
|
|
||||||
prod := <-consume
|
prod := <-consume
|
||||||
|
|
||||||
status = _Consumer
|
status = _Consumer
|
||||||
|
@ -55,6 +57,16 @@ func consumer() {
|
||||||
|
|
||||||
bulk.Insert(mquota)
|
bulk.Insert(mquota)
|
||||||
|
|
||||||
|
counter <- Counterchan{
|
||||||
|
tipo: "msg",
|
||||||
|
val: prod[p].messages,
|
||||||
|
}
|
||||||
|
|
||||||
|
counter <- Counterchan{
|
||||||
|
tipo: "storage",
|
||||||
|
val: prod[p].storage,
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Test {
|
if opts.Test {
|
||||||
log.Printf("OK: %s\n", prod[p].user)
|
log.Printf("OK: %s\n", prod[p].user)
|
||||||
}
|
}
|
||||||
|
@ -71,7 +83,7 @@ func consumer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Debug {
|
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()
|
wg.Done()
|
||||||
|
|
32
counter.go
32
counter.go
|
@ -20,6 +20,8 @@ type Counter struct {
|
||||||
dup int
|
dup int
|
||||||
time time.Duration
|
time time.Duration
|
||||||
wg int
|
wg int
|
||||||
|
msg int
|
||||||
|
storage int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCounter iniitialized Counter structure
|
// NewCounter iniitialized Counter structure
|
||||||
|
@ -53,11 +55,25 @@ func (c *Counter) Run() {
|
||||||
}
|
}
|
||||||
case "err":
|
case "err":
|
||||||
c.addErr(tocount.val)
|
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
|
// AddUser increment number of users managed
|
||||||
func (c *Counter) addUser() {
|
func (c *Counter) addUser() {
|
||||||
c.user++
|
c.user++
|
||||||
|
@ -88,6 +104,22 @@ func (c *Counter) delWG() {
|
||||||
c.wg--
|
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
|
// GetUser return total users
|
||||||
func (c *Counter) GetUser() (ret int) {
|
func (c *Counter) GetUser() (ret int) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
|
|
|
@ -79,12 +79,13 @@ func writeStats() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
qtot := getStorage()
|
// qtot := getStorage()
|
||||||
|
|
||||||
tags := map[string]string{"server": infhost, "domain": "quota"}
|
tags := map[string]string{"server": infhost, "domain": "quota"}
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"user": count.GetUser(),
|
"user": count.GetUser(),
|
||||||
"storage": qtot,
|
"storage": count.GetStorage(),
|
||||||
|
"msg": count.GetMsg(),
|
||||||
"stop": count.GetTime(),
|
"stop": count.GetTime(),
|
||||||
}
|
}
|
||||||
pt, err := influxdb.NewPoint("qmongo", tags, fields, start)
|
pt, err := influxdb.NewPoint("qmongo", tags, fields, start)
|
||||||
|
|
6
main.go
6
main.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_Version = "v2.1.1"
|
_Version = "v2.2.1"
|
||||||
_Producer = 0
|
_Producer = 0
|
||||||
_Consumer = 1
|
_Consumer = 1
|
||||||
)
|
)
|
||||||
|
@ -115,8 +115,8 @@ func main() {
|
||||||
|
|
||||||
count.SetTime(time.Since(start))
|
count.SetTime(time.Since(start))
|
||||||
|
|
||||||
fmt.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\n\r", count.GetTime(), count.GetUser())
|
log.Printf("Stop %v - user: %d - Storage: %d\n\r", count.GetTime(), count.GetUser(), count.GetStorage())
|
||||||
|
|
||||||
if opts.Influxdb != "" {
|
if opts.Influxdb != "" {
|
||||||
writeStats()
|
writeStats()
|
||||||
|
|
Loading…
Add table
Reference in a new issue