forked from rouben/zfswatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osutil_solaris.go
91 lines (83 loc) · 2.28 KB
/
osutil_solaris.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// osutil_solaris.go
//
// Copyright © 2012-2013 Damicon Kraa Oy
//
// This file is part of zfswatcher.
//
// Zfswatcher is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Zfswatcher is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with zfswatcher. If not, see <http://www.gnu.org/licenses/>.
//
// +build solaris
package main
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
)
// Returns system uptime as time.Duration.
func getSystemUptime() (uptime time.Duration, err error) {
var (
i int
out string
)
cmd := "kstat -p unix:0:system_misc:snaptime"
if out, err = getCommandOutput(cmd); err != nil {
return 0, errors.New("Failed to run 'kstat'")
}
parts := strings.Split(out, "\t")
if len(parts) < 2 {
return 0, errors.New("Invalid output from 'kstat'")
}
_p1 := parts[1]
_s := strings.Split(_p1, ".")[0]
//fmt.Printf("Before the dot -> %s\n", _s)
if i, err = strconv.Atoi(_s); err != nil {
return 0, errors.New("Uptime was not an integer")
}
uptime = time.Duration(i) * time.Second
return uptime, nil
}
// Returns system load averages.
func getSystemLoadaverage() ([3]float32, error) {
var (
out string
err error
ret [3]float32
val float64
)
cmd := "uptime"
if out, err = getCommandOutput(cmd); err != nil {
return ret, errors.New("failed to run 'uptime'")
}
parts := strings.Split(out, " ")
load := parts[len(parts)-3:]
//fmt.Printf("load parts -> %s\n", load)
for i, e := range load {
e = strings.Replace(e, ",", "", 1)
e = strings.Join(strings.Fields(e), "")
if val, err = strconv.ParseFloat(e, 32); err != nil {
return ret, errors.New(fmt.Sprintf("failed to convert load value '%s'", e))
}
ret[i] = float32(val)
}
return ret, nil
//return [3]float32{0, 0, 0}, nil
}
// Device lookup paths. (This list comes from lib/libzfs/libzfs_import.c)
var deviceLookupPaths = [...]string{
"/dev/dsk",
}
// eof