-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1774 from ston1th/openbsd_amd64
remove openbsd amd64 cgo dependecies
- Loading branch information
Showing
19 changed files
with
659 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ crossbuild: | |
- linux/ppc64 | ||
- linux/ppc64le | ||
- linux/s390x | ||
- openbsd/amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2020 The Prometheus 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. | ||
|
||
// +build !noboottime | ||
|
||
package collector | ||
|
||
import ( | ||
"github.com/go-kit/kit/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"golang.org/x/sys/unix" | ||
"unsafe" | ||
) | ||
|
||
type bootTimeCollector struct { | ||
name, description string | ||
logger log.Logger | ||
} | ||
|
||
func init() { | ||
registerCollector("boottime", defaultEnabled, newBootTimeCollector) | ||
} | ||
|
||
// newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. | ||
func newBootTimeCollector(logger log.Logger) (Collector, error) { | ||
return &bootTimeCollector{ | ||
name: "boot_time_seconds", | ||
description: "Unix time of last boot, including microseconds.", | ||
logger: logger, | ||
}, nil | ||
} | ||
|
||
// Update pushes boot time onto ch | ||
func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error { | ||
raw, err := unix.SysctlRaw("kern.boottime") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tv := *(*unix.Timeval)(unsafe.Pointer(&raw[0])) | ||
v := (float64(tv.Sec) + (float64(tv.Usec) / float64(1000*1000))) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, "", c.name), | ||
c.description, | ||
nil, nil, | ||
), prometheus.GaugeValue, v) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2020 The Prometheus 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. | ||
|
||
// +build !nocpu | ||
|
||
package collector | ||
|
||
import ( | ||
"strconv" | ||
"unsafe" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
type clockinfo struct { | ||
hz int32 | ||
tick int32 | ||
tickadj int32 | ||
stathz int32 | ||
profhz int32 | ||
} | ||
|
||
const ( | ||
CP_USER = iota | ||
CP_NICE | ||
CP_SYS | ||
CP_SPIN | ||
CP_INTR | ||
CP_IDLE | ||
CPUSTATES | ||
) | ||
|
||
type cpuCollector struct { | ||
cpu typedDesc | ||
logger log.Logger | ||
} | ||
|
||
func init() { | ||
registerCollector("cpu", defaultEnabled, NewCPUCollector) | ||
} | ||
|
||
func NewCPUCollector(logger log.Logger) (Collector, error) { | ||
return &cpuCollector{ | ||
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, | ||
logger: logger, | ||
}, nil | ||
} | ||
|
||
func (c *cpuCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||
clockb, err := unix.SysctlRaw("kern.clockrate") | ||
if err != nil { | ||
return err | ||
} | ||
clock := *(*clockinfo)(unsafe.Pointer(&clockb[0])) | ||
hz := float64(clock.stathz) | ||
|
||
ncpus, err := unix.SysctlUint32("hw.ncpu") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var cpTime [][CPUSTATES]int64 | ||
for i := 0; i < int(ncpus); i++ { | ||
cpb, err := unix.SysctlRaw("kern.cp_time2", i) | ||
if err != nil && err != unix.ENODEV { | ||
return err | ||
} | ||
if err != unix.ENODEV { | ||
cpTime = append(cpTime, *(*[CPUSTATES]int64)(unsafe.Pointer(&cpb[0]))) | ||
} | ||
} | ||
|
||
for cpu, time := range cpTime { | ||
lcpu := strconv.Itoa(cpu) | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_USER])/hz, lcpu, "user") | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_NICE])/hz, lcpu, "nice") | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_SYS])/hz, lcpu, "system") | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_SPIN])/hz, lcpu, "spin") | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_INTR])/hz, lcpu, "interrupt") | ||
ch <- c.cpu.mustNewConstMetric(float64(time[CP_IDLE])/hz, lcpu, "idle") | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2020 The Prometheus 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. | ||
|
||
// +build !nodiskstats | ||
|
||
package collector | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
const ( | ||
DS_DISKNAMELEN = 16 | ||
) | ||
|
||
type DiskStats struct { | ||
Name [DS_DISKNAMELEN]int8 | ||
Busy int32 | ||
Rxfer uint64 | ||
Wxfer uint64 | ||
Seek uint64 | ||
Rbytes uint64 | ||
Wbytes uint64 | ||
Attachtime unix.Timeval | ||
Timestamp unix.Timeval | ||
Time unix.Timeval | ||
} | ||
|
||
type diskstatsCollector struct { | ||
rxfer typedDesc | ||
rbytes typedDesc | ||
wxfer typedDesc | ||
wbytes typedDesc | ||
time typedDesc | ||
logger log.Logger | ||
} | ||
|
||
func init() { | ||
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector) | ||
} | ||
|
||
// NewDiskstatsCollector returns a new Collector exposing disk device stats. | ||
func NewDiskstatsCollector(logger log.Logger) (Collector, error) { | ||
return &diskstatsCollector{ | ||
rxfer: typedDesc{readsCompletedDesc, prometheus.CounterValue}, | ||
rbytes: typedDesc{readBytesDesc, prometheus.CounterValue}, | ||
wxfer: typedDesc{writesCompletedDesc, prometheus.CounterValue}, | ||
wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue}, | ||
time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue}, | ||
logger: logger, | ||
}, nil | ||
} | ||
|
||
func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||
diskstatsb, err := unix.SysctlRaw("hw.diskstats") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ndisks := len(diskstatsb) / int(unsafe.Sizeof(DiskStats{})) | ||
diskstats := *(*[]DiskStats)(unsafe.Pointer(&diskstatsb)) | ||
|
||
for i := 0; i < ndisks; i++ { | ||
dn := *(*[DS_DISKNAMELEN]int8)(unsafe.Pointer(&diskstats[i].Name[0])) | ||
diskname := int8ToString(dn[:]) | ||
|
||
ch <- c.rxfer.mustNewConstMetric(float64(diskstats[i].Rxfer), diskname) | ||
ch <- c.rbytes.mustNewConstMetric(float64(diskstats[i].Rbytes), diskname) | ||
ch <- c.wxfer.mustNewConstMetric(float64(diskstats[i].Wxfer), diskname) | ||
ch <- c.wbytes.mustNewConstMetric(float64(diskstats[i].Wbytes), diskname) | ||
time := float64(diskstats[i].Time.Sec) + float64(diskstats[i].Time.Usec)/1000000 | ||
ch <- c.time.mustNewConstMetric(time, diskname) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2020 The Prometheus 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. | ||
|
||
// +build openbsd darwin,amd64 dragonfly | ||
// +build !nofilesystem | ||
|
||
package collector | ||
|
||
import ( | ||
"github.com/go-kit/kit/log/level" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
const ( | ||
defIgnoredMountPoints = "^/(dev)($|/)" | ||
defIgnoredFSTypes = "^devfs$" | ||
) | ||
|
||
// Expose filesystem fullness. | ||
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { | ||
var mnt []unix.Statfs_t | ||
size, err := unix.Getfsstat(mnt, unix.MNT_NOWAIT) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mnt = make([]unix.Statfs_t, size) | ||
_, err = unix.Getfsstat(mnt, unix.MNT_NOWAIT) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stats = []filesystemStats{} | ||
for _, v := range mnt { | ||
mountpoint := int8ToString(v.F_mntonname[:]) | ||
if c.ignoredMountPointsPattern.MatchString(mountpoint) { | ||
level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) | ||
continue | ||
} | ||
|
||
device := int8ToString(v.F_mntfromname[:]) | ||
fstype := int8ToString(v.F_fstypename[:]) | ||
if c.ignoredFSTypesPattern.MatchString(fstype) { | ||
level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) | ||
continue | ||
} | ||
|
||
var ro float64 | ||
if (v.F_flags & unix.MNT_RDONLY) != 0 { | ||
ro = 1 | ||
} | ||
|
||
stats = append(stats, filesystemStats{ | ||
labels: filesystemLabels{ | ||
device: device, | ||
mountPoint: mountpoint, | ||
fsType: fstype, | ||
}, | ||
size: float64(v.F_blocks) * float64(v.F_bsize), | ||
free: float64(v.F_bfree) * float64(v.F_bsize), | ||
avail: float64(v.F_bavail) * float64(v.F_bsize), | ||
files: float64(v.F_files), | ||
filesFree: float64(v.F_ffree), | ||
ro: ro, | ||
}) | ||
} | ||
return stats, nil | ||
} |
Oops, something went wrong.