mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Removed ps dependency from monitoring
This commit is contained in:
@@ -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
14
server/pse_windows.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user