mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 02:07:59 -07:00
This will allow applications (for instance NATS Streaming Server) to add new endpoints to the NATS http server. Resolves #480
24 lines
548 B
Go
24 lines
548 B
Go
// Copyright 2015-2016 Apcera Inc. All rights reserved.
|
|
|
|
package pse
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
)
|
|
|
|
// ProcUsage returns CPU usage
|
|
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 {
|
|
*rss, *vss = -1, -1
|
|
return fmt.Errorf("ps call failed:%v", err)
|
|
}
|
|
fmt.Sscanf(string(out), "%f %d %d", pcpu, rss, vss)
|
|
*rss *= 1024 // 1k blocks, want bytes.
|
|
*vss *= 1024 // 1k blocks, want bytes.
|
|
return nil
|
|
}
|