mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
Rename and move some things around
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nats-io/gnatsd/server/pse"
|
||||
)
|
||||
|
||||
// Snapshot this
|
||||
@@ -462,7 +464,7 @@ func updateUsage(v *Varz) {
|
||||
var rss, vss int64
|
||||
var pcpu float64
|
||||
|
||||
procUsage(&pcpu, &rss, &vss)
|
||||
pse.ProcUsage(&pcpu, &rss, &vss)
|
||||
|
||||
v.Mem = rss
|
||||
v.CPU = pcpu
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
package pse
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
pidStr := fmt.Sprintf("%d", os.Getpid())
|
||||
out, err := exec.Command("ps", "o", "pcpu=,rss=,vsz=", "-p", pidStr).Output()
|
||||
if err != nil {
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2015 Apcera Inc. All rights reserved.
|
||||
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
package pse
|
||||
|
||||
/*
|
||||
#include <sys/types.h>
|
||||
@@ -56,7 +56,7 @@ import (
|
||||
)
|
||||
|
||||
// This is a placeholder for now.
|
||||
func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
var r, v C.uint
|
||||
var c C.double
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2015 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
package pse
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -27,7 +27,7 @@ func init() {
|
||||
procStatFile = fmt.Sprintf("/proc/%d/stat", os.Getpid())
|
||||
}
|
||||
|
||||
func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
contents, err := ioutil.ReadFile(procStatFile)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,3 +56,24 @@ func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ascii numbers 0-9
|
||||
const (
|
||||
asciiZero = 48
|
||||
asciiNine = 57
|
||||
)
|
||||
|
||||
// parseInt64 expects decimal positive numbers. We
|
||||
// return -1 to signal error
|
||||
func parseInt64(d []byte) (n int64) {
|
||||
if len(d) == 0 {
|
||||
return -1
|
||||
}
|
||||
for _, dec := range d {
|
||||
if dec < asciiZero || dec > asciiNine {
|
||||
return -1
|
||||
}
|
||||
n = n*10 + (int64(dec) - asciiZero)
|
||||
}
|
||||
return n
|
||||
}
|
||||
12
server/pse/pse_solaris.go
Normal file
12
server/pse/pse_solaris.go
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
||||
|
||||
package pse
|
||||
|
||||
// This is a placeholder for now.
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
*pcpu = 0.0
|
||||
*rss = 0
|
||||
*vss = 0
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2015 Apcera Inc. All rights reserved.
|
||||
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
package pse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -29,7 +29,7 @@ func TestPSEmulation(t *testing.T) {
|
||||
psVss *= 1024 // 1k blocks, want bytes.
|
||||
|
||||
// Our internal version
|
||||
procUsage(&pcpu, &rss, &vss)
|
||||
ProcUsage(&pcpu, &rss, &vss)
|
||||
|
||||
if pcpu != psPcpu {
|
||||
delta := int64(pcpu - psPcpu)
|
||||
@@ -1,16 +1,16 @@
|
||||
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
package pse
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// cache the image name to optimize repeated calls
|
||||
@@ -112,7 +112,7 @@ func getProcessImageName() (name string) {
|
||||
// If there is more than one instance, "#<instancecount>" is appended to
|
||||
// the image name. Wildcard filters are supported, but result in a very
|
||||
// complex data set to parse.
|
||||
func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
func ProcUsage(pcpu *float64, rss, vss *int64) error {
|
||||
var ppid int = -1
|
||||
|
||||
imageLock.Lock()
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2016 Apcera Inc. All rights reserved.
|
||||
// +build win
|
||||
package server
|
||||
|
||||
package pse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright 2015 Apcera Inc. All rights reserved.
|
||||
|
||||
package server
|
||||
|
||||
// This is a placeholder for now.
|
||||
func procUsage(pcpu *float64, rss, vss *int64) error {
|
||||
*pcpu = 0.0
|
||||
*rss = 0
|
||||
*vss = 0
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func PrintAndDie(msg string) {
|
||||
|
||||
// PrintServerAndExit will print our version and exit.
|
||||
func PrintServerAndExit() {
|
||||
fmt.Printf("gnatsd version %s\n", VERSION)
|
||||
fmt.Printf("nats-server version %s\n", VERSION)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func (s *Server) logPid() {
|
||||
// Start up the server, this will block.
|
||||
// Start via a Go routine if needed.
|
||||
func (s *Server) Start() {
|
||||
Noticef("Starting gnatsd version %s", VERSION)
|
||||
Noticef("Starting nats-server version %s", VERSION)
|
||||
Debugf("Go build version %s", s.info.GoVersion)
|
||||
|
||||
s.running = true
|
||||
@@ -319,8 +319,8 @@ func (s *Server) AcceptLoop() {
|
||||
Noticef("TLS required for client connections")
|
||||
}
|
||||
|
||||
Debugf("server id is %s", s.info.ID)
|
||||
Noticef("server is ready")
|
||||
Debugf("Server id is %s", s.info.ID)
|
||||
Noticef("Server is ready")
|
||||
|
||||
// Setup state that can enable shutdown
|
||||
s.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user