Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/disk_avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows && !openbsd && !netbsd && !wasm
//go:build !windows && !openbsd && !netbsd && !wasm && !illumos && !solaris

package server

Expand Down
38 changes: 38 additions & 0 deletions server/disk_avail_solaris.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build illumos || solaris

package server

import (
"os"
"golang.org/x/sys/unix"
)

func diskAvailable(storeDir string) int64 {
var ba int64
if _, err := os.Stat(storeDir); os.IsNotExist(err) {
os.MkdirAll(storeDir, defaultDirPerms)
}
var fs unix.Statvfs_t
if err := unix.Statvfs(storeDir, &fs); err == nil {
// Estimate 75% of available storage.
ba = int64(uint64(fs.Frsize) * uint64(fs.Bavail) / 4 * 3)
} else {
// Used 1TB default as a guess if all else fails.
ba = JetStreamMaxStoreDefault
}
return ba
}

34 changes: 28 additions & 6 deletions server/pse/pse_solaris.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2018 The NATS Authors
// Copyright 2015-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand All @@ -10,14 +10,36 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copied from pse_openbsd.go

//go:build illumos || solaris

package pse

// This is a placeholder for now.
func ProcUsage(pcpu *float64, rss, vss *int64) error {
*pcpu = 0.0
*rss = 0
*vss = 0
import (
"fmt"
"os"
"os/exec"
"strings"
)

// 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)
}
lines := strings.Split(string(out), "\n")
if len(lines) < 2 {
*rss, *vss = -1, -1
return fmt.Errorf("no ps output")
}
output := lines[1]
fmt.Sscanf(output, "%f %d %d", pcpu, rss, vss)
*rss *= 1024 // 1k blocks, want bytes.
*vss *= 1024 // 1k blocks, want bytes.
return nil
}
37 changes: 37 additions & 0 deletions server/sysmem/mem_solaris.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2025 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build illumos || solaris

package sysmem

import (
"golang.org/x/sys/unix"
)

const (
_SC_PHYS_PAGES = 500
_SC_PAGESIZE = 11
)

func Memory() int64 {
pages, err := unix.Sysconf(_SC_PHYS_PAGES)
if err != nil {
return 0
}
pageSize, err := unix.Sysconf(_SC_PAGESIZE)
if err != nil {
return 0
}
return int64(pages) * int64(pageSize)
}