Skip to content

Commit 9810c57

Browse files
committed
Merge pull request #128 from prometheus/ppc
Fix uname collector for ppc64 architectures
2 parents ee6b8e7 + 52f79e6 commit 9810c57

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

collector/uname_linux.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,19 @@ func newUnameCollector() (Collector, error) {
4646
return &unameCollector{}, nil
4747
}
4848

49-
func intArrayToString(array [65]int8) string {
50-
var str string
51-
for _, a := range array {
52-
if a == 0 {
53-
break
54-
}
55-
str += string(a)
56-
}
57-
return str
58-
}
59-
6049
func (c unameCollector) Update(ch chan<- prometheus.Metric) error {
6150
var uname syscall.Utsname
6251
if err := syscall.Uname(&uname); err != nil {
6352
return err
6453
}
6554

66-
labelValues := []string{
67-
intArrayToString(uname.Sysname),
68-
intArrayToString(uname.Release),
69-
intArrayToString(uname.Version),
70-
intArrayToString(uname.Machine),
71-
intArrayToString(uname.Nodename),
72-
intArrayToString(uname.Domainname),
73-
}
74-
ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1, labelValues...)
55+
ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1,
56+
unameToString(uname.Sysname),
57+
unameToString(uname.Release),
58+
unameToString(uname.Version),
59+
unameToString(uname.Machine),
60+
unameToString(uname.Nodename),
61+
unameToString(uname.Domainname),
62+
)
7563
return nil
7664
}

collector/uname_linux_int8.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// +build !nouname,linux,386 !nouname,linux,amd64
15+
16+
package collector
17+
18+
func unameToString(input [65]int8) string {
19+
var str string
20+
for _, a := range input {
21+
if a == 0 {
22+
break
23+
}
24+
str += string(a)
25+
}
26+
return str
27+
}

collector/uname_linux_uint8.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// +build !nouname,linux,arm !nouname,linux,ppc64 !nouname,linux,ppc64le
15+
16+
package collector
17+
18+
func unameToString(input [65]uint8) string {
19+
var str string
20+
for _, a := range input {
21+
if a == 0 {
22+
break
23+
}
24+
str += string(a)
25+
}
26+
return str
27+
}

0 commit comments

Comments
 (0)