Skip to content
Open
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
5 changes: 5 additions & 0 deletions collector/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ import (

var (
// The path of the proc filesystem.
etcPath = kingpin.Flag("path.etcfs", "etcfs mountpoint.").Default("/etc").String()
procPath = kingpin.Flag("path.procfs", "procfs mountpoint.").Default(procfs.DefaultMountPoint).String()
sysPath = kingpin.Flag("path.sysfs", "sysfs mountpoint.").Default("/sys").String()
rootfsPath = kingpin.Flag("path.rootfs", "rootfs mountpoint.").Default("/").String()
)

func etcFilePath(name string) string {
return filepath.Join(*etcPath, name)
}

func procFilePath(name string) string {
return filepath.Join(*procPath, name)
}
Expand Down
90 changes: 90 additions & 0 deletions collector/release_opensuse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2016 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 !novmstat

package collector

import (
"bufio"
// "fmt"
"os"
// "regexp"
// "strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
// "gopkg.in/alecthomas/kingpin.v2"
)

const (
releaseSubsystem = "release"
)

type releaseCollector struct{}
type release struct {
ID string
VersionID string
}

func init() {
registerCollector("release", defaultEnabled, newReleaseCollector)
}

func newReleaseCollector() (Collector, error) {
return &releaseCollector{}, nil
}

func (c *releaseCollector) Update(ch chan<- prometheus.Metric) error {
release, err := getRelease()
if err != nil {
return err
}

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, releaseSubsystem, "info"),
"/etc/os-release information",
[]string{"id", "versionid"}, nil),
prometheus.GaugeValue,
1,
release.ID,
release.VersionID,
)
return nil
}

func getRelease() (release, error) {
release := release{
ID: "",
VersionID: "",
}
file, err := os.Open(etcFilePath("os-release"))
if err != nil {
return release, err
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
parts := strings.Split(scanner.Text(), "=")
parts[1] = strings.Replace(parts[1], "\"", "", -1)
if "ID" == parts[0] {
release.ID = parts[1]
} else if "VERSION_ID" == parts[0] {
release.VersionID = parts[1]
}
}

return release, scanner.Err()
}
1 change: 1 addition & 0 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ disabled_collectors=$(cat << COLLECTORS
time
timex
uname
release
COLLECTORS
)
cd "$(dirname $0)"
Expand Down