Skip to content

Commit 54e665a

Browse files
authored
Merge pull request #11 from galexrt/dev
Sync changes from fork jddggh and dev
2 parents 568684f + 94800fd commit 54e665a

21 files changed

+272
-74
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _testmain.go
2222
*.exe
2323
*.test
2424
*.prof
25-
25+
.idea/
2626
.build/
2727
.tarballs/
2828
.package/

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.1
1+
1.3.0

cmd/dellhw_exporter/dellhw_exporter.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,10 @@ import (
2222
)
2323

2424
const (
25-
defaultCollectors = "chassis,fans,memory,processors,ps,ps_amps_sysboard_pwr,storage_battery,storage_enclosure,storage_controller,storage_pdisk,storage_vdisk,system,temps,volts"
25+
defaultCollectors = "chassis,chassis_batteries,fans,memory,nics,processors,ps,ps_amps_sysboard_pwr,storage_battery,storage_controller,storage_enclosure,storage_pdisk,storage_vdisk,system,temps,volts"
2626
)
2727

2828
var (
29-
connectionDurationDesc = prometheus.NewDesc(
30-
prometheus.BuildFQName(collector.Namespace, "scrape", "connection_duration_seconds"),
31-
"srcds_exporter: Duration of the server connection.",
32-
[]string{"connection"},
33-
nil,
34-
)
35-
connectionSucessDesc = prometheus.NewDesc(
36-
prometheus.BuildFQName(collector.Namespace, "scrape", "connection_success"),
37-
"srcds_exporter: Whether the server connection succeeded.",
38-
[]string{"connection"},
39-
nil,
40-
)
4129
scrapeDurationDesc = prometheus.NewDesc(
4230
prometheus.BuildFQName(collector.Namespace, "scrape", "collector_duration_seconds"),
4331
"srcds_exporter: Duration of a collector scrape.",
@@ -91,7 +79,9 @@ func init() {
9179
// Define the usage function
9280
dellhwExporterFlags.Usage = usage
9381

94-
dellhwExporterFlags.Parse(os.Args[1:])
82+
if err := dellhwExporterFlags.Parse(os.Args[1:]); err != nil {
83+
log.Fatal(err)
84+
}
9585
}
9686

9787
// Describe implements the prometheus.Collector interface.
@@ -113,28 +103,17 @@ func (n DellHWCollector) Collect(ch chan<- prometheus.Metric) {
113103
wg.Wait()
114104
}
115105

116-
func filterAvailableCollectors(collectors string) string {
117-
var availableCollectors []string
118-
for _, c := range strings.Split(collectors, ",") {
119-
_, ok := collector.Factories[c]
120-
if ok {
121-
availableCollectors = append(availableCollectors, c)
122-
}
123-
}
124-
return strings.Join(availableCollectors, ",")
125-
}
126-
127106
func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
128107
begin := time.Now()
129108
err := c.Update(ch)
130109
duration := time.Since(begin)
131110
var success float64
132111

133112
if err != nil {
134-
log.Errorf("ERROR: %s collector failed after %fs: %s", name, duration.Seconds(), err)
113+
log.Errorf("%s collector failed after %fs: %s", name, duration.Seconds(), err)
135114
success = 0
136115
} else {
137-
log.Debugf("OK: %s collector succeeded after %fs.", name, duration.Seconds())
116+
log.Debugf("%s collector succeeded after %fs.", name, duration.Seconds())
138117
success = 1
139118
}
140119
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name)
@@ -164,7 +143,12 @@ func usage() {
164143
}
165144

166145
func main() {
167-
flagutil.SetFlagsFromEnv(dellhwExporterFlags, "DELLHW_EXPORTER")
146+
if err := flagutil.SetFlagsFromEnv(dellhwExporterFlags, "DELLHW_EXPORTER"); err != nil {
147+
log.Fatal(err)
148+
}
149+
if opts.help {
150+
usage()
151+
}
168152
if opts.version {
169153
fmt.Fprintln(os.Stdout, version.Print("srcds_exporter"))
170154
os.Exit(0)

collector/chassis.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type chassisCollector struct {
10-
current []*prometheus.Desc
10+
current *prometheus.Desc
1111
}
1212

1313
func init() {
@@ -28,12 +28,12 @@ func (c *chassisCollector) Update(ch chan<- prometheus.Metric) error {
2828
if err != nil {
2929
return err
3030
}
31-
current := prometheus.NewDesc(
31+
c.current = prometheus.NewDesc(
3232
prometheus.BuildFQName(Namespace, "", value.Name),
3333
"Overall status of chassis components.",
3434
nil, value.Labels)
3535
ch <- prometheus.MustNewConstMetric(
36-
current, prometheus.GaugeValue, float)
36+
c.current, prometheus.GaugeValue, float)
3737
}
3838

3939
return nil

collector/chassis_batteries.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package collector
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
8+
9+
type chassisBatteriesCollector struct {
10+
current *prometheus.Desc
11+
}
12+
13+
func init() {
14+
Factories["chassis_batteries"] = NewChassisBatteriesCollector
15+
}
16+
17+
func NewChassisBatteriesCollector() (Collector, error) {
18+
return &chassisBatteriesCollector{}, nil
19+
}
20+
21+
func (c *chassisBatteriesCollector) Update(ch chan<- prometheus.Metric) error {
22+
chassisBatteries, err := or.ChassisBatteries()
23+
if err != nil {
24+
return err
25+
}
26+
for _, value := range chassisBatteries {
27+
float, err := strconv.ParseFloat(value.Value, 64)
28+
if err != nil {
29+
return err
30+
}
31+
c.current = prometheus.NewDesc(
32+
prometheus.BuildFQName(Namespace, "", value.Name),
33+
"Overall status of chassis batteries",
34+
nil, value.Labels)
35+
ch <- prometheus.MustNewConstMetric(
36+
c.current, prometheus.GaugeValue, float)
37+
}
38+
39+
return nil
40+
}

collector/fans.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type fansCollector struct {
10-
current []*prometheus.Desc
10+
current *prometheus.Desc
1111
}
1212

1313
func init() {
@@ -28,12 +28,12 @@ func (c *fansCollector) Update(ch chan<- prometheus.Metric) error {
2828
if err != nil {
2929
return err
3030
}
31-
current := prometheus.NewDesc(
31+
c.current = prometheus.NewDesc(
3232
prometheus.BuildFQName(Namespace, "", value.Name),
3333
"Overall status of system fans.",
3434
nil, value.Labels)
3535
ch <- prometheus.MustNewConstMetric(
36-
current, prometheus.GaugeValue, float)
36+
c.current, prometheus.GaugeValue, float)
3737
}
3838

3939
return nil

collector/memory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type memoryCollector struct {
10-
current []*prometheus.Desc
10+
current *prometheus.Desc
1111
}
1212

1313
func init() {
@@ -28,12 +28,12 @@ func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error {
2828
if err != nil {
2929
return err
3030
}
31-
current := prometheus.NewDesc(
31+
c.current = prometheus.NewDesc(
3232
prometheus.BuildFQName(Namespace, "", value.Name),
3333
"System RAM DIMM status.",
3434
nil, value.Labels)
3535
ch <- prometheus.MustNewConstMetric(
36-
current, prometheus.GaugeValue, float)
36+
c.current, prometheus.GaugeValue, float)
3737
}
3838

3939
return nil

collector/nics.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package collector
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/prometheus/client_golang/prometheus"
7+
)
8+
9+
type nicsCollector struct {
10+
current *prometheus.Desc
11+
}
12+
13+
func init() {
14+
Factories["nics"] = NewNicsCollector
15+
}
16+
17+
func NewNicsCollector() (Collector, error) {
18+
return &nicsCollector{}, nil
19+
}
20+
21+
func (c *nicsCollector) Update(ch chan<- prometheus.Metric) error {
22+
nics, err := or.Nics()
23+
if err != nil {
24+
return err
25+
}
26+
for _, value := range nics {
27+
float, err := strconv.ParseFloat(value.Value, 64)
28+
if err != nil {
29+
return err
30+
}
31+
c.current = prometheus.NewDesc(
32+
prometheus.BuildFQName(Namespace, "", value.Name),
33+
"Connection status of network cards.",
34+
nil, value.Labels)
35+
ch <- prometheus.MustNewConstMetric(
36+
c.current, prometheus.GaugeValue, float)
37+
}
38+
39+
return nil
40+
}

collector/processors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type processorsCollector struct {
10-
current []*prometheus.Desc
10+
current *prometheus.Desc
1111
}
1212

1313
func init() {
@@ -28,12 +28,12 @@ func (c *processorsCollector) Update(ch chan<- prometheus.Metric) error {
2828
if err != nil {
2929
return err
3030
}
31-
current := prometheus.NewDesc(
31+
c.current = prometheus.NewDesc(
3232
prometheus.BuildFQName(Namespace, "", value.Name),
3333
"Overall status of CPUs.",
3434
nil, value.Labels)
3535
ch <- prometheus.MustNewConstMetric(
36-
current, prometheus.GaugeValue, float)
36+
c.current, prometheus.GaugeValue, float)
3737
}
3838

3939
return nil

collector/ps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
type psCollector struct {
10-
current []*prometheus.Desc
10+
current *prometheus.Desc
1111
}
1212

1313
func init() {
@@ -28,12 +28,12 @@ func (c *psCollector) Update(ch chan<- prometheus.Metric) error {
2828
if err != nil {
2929
return err
3030
}
31-
current := prometheus.NewDesc(
31+
c.current = prometheus.NewDesc(
3232
prometheus.BuildFQName(Namespace, "", value.Name),
3333
"Overall status of power supplies.",
3434
nil, value.Labels)
3535
ch <- prometheus.MustNewConstMetric(
36-
current, prometheus.GaugeValue, float)
36+
c.current, prometheus.GaugeValue, float)
3737
}
3838

3939
return nil

0 commit comments

Comments
 (0)