Removed ps dependency from monitoring

This commit is contained in:
Derek Collison
2015-06-15 18:09:46 -07:00
parent 51f3ca8216
commit d932ac5652
2 changed files with 31 additions and 14 deletions

View File

@@ -1,14 +1,11 @@
// Copyright 2013-2014 Apcera Inc. All rights reserved.
// Copyright 2013-2015 Apcera Inc. All rights reserved.
package server
import (
"encoding/json"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"runtime"
"strconv"
"time"
@@ -16,6 +13,13 @@ import (
"github.com/apcera/gnatsd/sublist"
)
// Snapshot this
var numCores int
func init() {
numCores = runtime.NumCPU()
}
// Connz represents detail information on current connections.
type Connz struct {
NumConns int `json:"num_connections"`
@@ -166,15 +170,14 @@ func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request) {
w.Write(b)
}
// FIXME(dlc): This is a big hack, make real..
// Grab RSS and PCPU
func updateUsage(v *Varz) {
v.Cores = runtime.NumCPU()
pidStr := fmt.Sprintf("%d", os.Getpid())
out, err := exec.Command("ps", "o", "pcpu=,rss=", "-p", pidStr).Output()
if err != nil {
// FIXME(dlc): Log?
return
}
fmt.Sscanf(string(out), "%f %d", &v.CPU, &v.Mem)
v.Mem *= 1024 // 1k blocks, want bytes.
var rss, vss int64
var pcpu float64
procUsage(&pcpu, &rss, &vss)
v.Mem = rss
v.CPU = pcpu
v.Cores = numCores
}

14
server/pse_windows.go Normal file
View File

@@ -0,0 +1,14 @@
// Copyright 2015 Apcera Inc. All rights reserved.
package server
import ()
// This is a placeholder for now.
func procUsage(pcpu *float64, rss, vss *int64) error {
*pcpu = 0.0
*rss = 0
*vss = 0
return nil
}