aboutsummaryrefslogtreecommitdiff
path: root/go/util
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2014-03-25 13:46:59 -0700
committerChris Lu <chris.lu@gmail.com>2014-03-25 13:46:59 -0700
commit39b774a131ac3bc454a516f7b72dcefabc593103 (patch)
tree804763e28b55b1e30ebfefced71b552b8e3e34a1 /go/util
parent6e0601a73bf199e7d3ffd3cd2990223e959d3e24 (diff)
downloadseaweedfs-39b774a131ac3bc454a516f7b72dcefabc593103.tar.xz
seaweedfs-39b774a131ac3bc454a516f7b72dcefabc593103.zip
1. adding statistics reporting
2. refactor version to util package
Diffstat (limited to 'go/util')
-rw-r--r--go/util/constants.go7
-rw-r--r--go/util/net_timeout.go23
2 files changed, 26 insertions, 4 deletions
diff --git a/go/util/constants.go b/go/util/constants.go
new file mode 100644
index 000000000..f8f1ef5bd
--- /dev/null
+++ b/go/util/constants.go
@@ -0,0 +1,7 @@
+package util
+
+import ()
+
+const (
+ VERSION = "0.51"
+)
diff --git a/go/util/net_timeout.go b/go/util/net_timeout.go
index 410152a79..a6cc81c99 100644
--- a/go/util/net_timeout.go
+++ b/go/util/net_timeout.go
@@ -1,6 +1,7 @@
package util
import (
+ "code.google.com/p/weed-fs/go/stats"
"net"
"time"
)
@@ -18,6 +19,7 @@ func (l *Listener) Accept() (net.Conn, error) {
if err != nil {
return nil, err
}
+ stats.ConnectionOpen()
tc := &Conn{
Conn: c,
ReadTimeout: l.ReadTimeout,
@@ -34,20 +36,33 @@ type Conn struct {
WriteTimeout time.Duration
}
-func (c *Conn) Read(b []byte) (int, error) {
+func (c *Conn) Read(b []byte) (count int, e error) {
err := c.Conn.SetReadDeadline(time.Now().Add(c.ReadTimeout))
if err != nil {
return 0, err
}
- return c.Conn.Read(b)
+ count, e = c.Conn.Read(b)
+ if e == nil {
+ stats.BytesIn(int64(count))
+ }
+ return
}
-func (c *Conn) Write(b []byte) (int, error) {
+func (c *Conn) Write(b []byte) (count int, e error) {
err := c.Conn.SetWriteDeadline(time.Now().Add(c.WriteTimeout))
if err != nil {
return 0, err
}
- return c.Conn.Write(b)
+ count, e = c.Conn.Write(b)
+ if e == nil {
+ stats.BytesOut(int64(count))
+ }
+ return
+}
+
+func (c *Conn) Close() error {
+ stats.ConnectionClose()
+ return c.Conn.Close()
}
func NewListener(addr string, timeout time.Duration) (net.Listener, error) {