node_exporter/collector/powersupplyclass.go
Sven Haardiek d089776e8b
Squashed commit of the following:
commit 5ef96388a978c54173e1b1ec8e7bcb41fc7d130d
Author: Sven Haardiek <sven@haardiek.de>
Date:   Wed Sep 18 20:45:23 2019 +0200

    block variables

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit c1177382e241994618a8ab7dd9842027d597b0df
Author: Sven Haardiek <sven@haardiek.de>
Date:   Wed Sep 18 20:38:33 2019 +0200

    Use SI Units

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 04e4f99c423872d3094f21f89a8235b233a01941
Merge: 5417c98 f3538e1
Author: Sven Haardiek <sven@haardiek.de>
Date:   Wed Sep 18 19:20:17 2019 +0200

    Merge branch 'master' into power_supply_class

commit 5417c9820a40b37b490caedeaa3526883380b9bf
Author: Sven Haardiek <sven@haardiek.de>
Date:   Wed Sep 4 23:02:39 2019 +0200

    Drop averages

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 1f1447dbe7bbdcdabebf4c968beb14c67d89dd9f
Author: Sven Haardiek <sven@haardiek.de>
Date:   Wed Sep 4 22:56:00 2019 +0200

    Update Copyright

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 9677425059a3bf61cd7498cf7b5f05d5af7a626b
Merge: 0b51589 d3478a2
Author: Sven Haardiek <sven@haardiek.de>
Date:   Mon Sep 2 22:02:53 2019 +0200

    Merge branch 'master' into power_supply_class

commit 0b51589f390cc1b33ea4728d85fca3a3b231cf3f
Author: PrometheusBot <prometheus-team@googlegroups.com>
Date:   Fri Aug 30 13:32:17 2019 +0200

    makefile: update Makefile.common with newer version (#1466)

    Signed-off-by: prombot <prometheus-team@googlegroups.com>

commit af2b9e849c7b69237b7fa0e9a289c929ec7173a0
Author: Boris Momčilović <boris.momcilovic@gmail.com>
Date:   Tue Aug 27 14:24:11 2019 +0200

    Ipvs firewall mark (#1455)

    * IPVS: include firewall mark label

    Signed-off-by: Boris Momčilović <boris@firstbeatmedia.com>

commit 773f99de7f699900a00b4d35340e356fe7098ee7
Author: Paul Gier <pgier@redhat.com>
Date:   Tue Aug 27 02:26:19 2019 -0500

    update procfs to v0.0.4 (#1457)

    Signed-off-by: Paul Gier <pgier@redhat.com>

commit 6f8a4f4348f62700cbf7eeb2657851237e13c35d
Author: beorn7 <beorn@grafana.com>
Date:   Tue Aug 20 18:49:12 2019 +0200

    Update legendLink

    This still had the 'k8s' in as it was copied and pasted from the
    kubernetes-mixin.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit d758cf394cfbed9e87e116a24d72050066cd039a
Author: beorn7 <beorn@grafana.com>
Date:   Wed Aug 14 22:24:24 2019 +0200

    Make the severity of "critical" alerts configurable

    This addresses the blissful scenario where single-node failures are
    unproblematic. No reason to wake somebody up if a node is about to
    screw itself up by filling the disk.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit 041b9e1e785f5f43bbef97c0c76d205181d08890
Author: beorn7 <beorn@grafana.com>
Date:   Thu Aug 15 16:43:57 2019 +0200

    Add line for number of cores to load graph

    Backported from the node dashboard in the kubernetes-mixin.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit 5552bb3a6b2be1e3dd1a93dbdb9650bd0363a922
Author: beorn7 <beorn@grafana.com>
Date:   Thu Aug 15 16:36:10 2019 +0200

    Fix title of CPU panel to usage

    We use the `mode="idle"` metric, but we are inverting it, so this is
    usage, and that's intended.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit db0571b402233323ed7e222e53f7ef7738520f49
Author: beorn7 <beorn@grafana.com>
Date:   Thu Aug 15 16:32:54 2019 +0200

    node-mixin: Improve disk usage panel

    - Use a stacked graph instead of a gauge as development over time is
      especially useful for disk space usage.

    - By only taking one metric per device into account, we avoid
      double-counting for devices that are mounted multiple times.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit 3822e096c5d27d06b9c9a68beff81ef23f12eb36
Author: Björn Rabenstein <beorn@grafana.com>
Date:   Thu Aug 15 00:40:51 2019 +0200

    node-mxin: Improve nodes dashboard (#1448)

    * node-mixin: Improve nodes dashboard

    - Use stacking where it makes sense.
    - Normalize idle CPU so that stacking is more meaningful.
    - Consistently fill where stacking is used but don't fill where not.
    - Fix y axis max value for Idle CPU panel.
    - Fix y axis min value for memory usage panel.
    - Use `$__interval` for range where applicable (and set min step
      to 1m).
    - Make the right Y axis for disk I/O actually work.

    This is just an incremental improvements. It doesn't touch the more
    involved TODOs.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit fbced86b9835e1b196c15ddcac01ba3cfcf369cc
Author: beorn7 <beorn@grafana.com>
Date:   Tue Aug 13 21:54:28 2019 +0200

    node-mixin: Fix various straight-forward issues in the USE dashboards

    - Normalize cluster memory utilisation.

    - Fix missing `1m` in memory saturation.

    - Have both disk-related row next to each other instead with the
      network row in between.

    - Correctly render transmit network traffic as negative, using
      `seriesOverrides` and `min: null` for the y-axis.

    - Make panel and row naming consistent.

    - Remove legend where it would just display a single entry with
      exactly the title of the panel.

    - Fix metric name in individual node CPU Saturation panel.

    - Break up disk space utilisation by device in the panel for an
      individual node.

    NB: All of that doesn't touch any more subtle issues captured in the
    various TODOs.

    Signed-off-by: beorn7 <beorn@grafana.com>

commit 5bdf0625023cf7d05e0f65c6b6a1303637772ca6
Author: Sandro Jäckel <sandro.jaeckel@gmail.com>
Date:   Wed Aug 7 09:19:20 2019 +0200

    Update rootfs syntax in Docker example (#1443)

    Signed-off-by: Sandro Jäckel <sandro.jaeckel@gmail.com>

commit b59f081d45a3ca65957900ec33772dca25a3066f
Author: Phil Frost <phil@postmates.com>
Date:   Tue Aug 6 13:08:06 2019 -0400

    Fix seconds reported by schedstat (#1426)

    Upstream bugfix: https://github.com/prometheus/procfs/pull/191

    Signed-off-by: Phil Frost <phil@postmates.com>

commit ac9a059ae81fa31f9963614483af3b5e3bfd672c
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sun Aug 4 20:15:36 2019 +0200

    Try to make it work for PowerPC

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit c81acf3b009e8538783489d1468f33faf65d8b01
Merge: c064116 75462bf
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sun Aug 4 20:14:16 2019 +0200

    Merge remote-tracking branch 'upstream/master' into power_supply_class

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit c0641162c3a432f29df30c8d0632a7756d7d2bff
Merge: 06f6e3e 0b710bb
Author: Sven Haardiek <sven@haardiek.de>
Date:   Fri Aug 2 18:30:28 2019 +0200

    Merge branch 'master' into power_supply_class

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 06f6e3e8b2a9b2e3f345b6d312a777731bb4b403
Author: Sven Haardiek <sven.haardiek@iotec-gmbh.de>
Date:   Fri Mar 22 15:36:03 2019 +0100

    Fix Pull Request comments

    * concise metric conditions
    * combine info about power supply to one metric

    Signed-off-by: Sven Haardiek <sven.haardiek@iotec-gmbh.de>

commit 785c3735c4626de56f8341f800ab7bb5e2594d08
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 18:47:52 2019 +0100

    Use sys.ttar instead of uploading the files

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit e07bff5d938457147b9009aef7d42d763018cd66
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 18:34:50 2019 +0100

    Add information about from /sys/class/power_supply

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 55b3e34840c9dfc6513ae8e69b6479d5842a3091
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 18:09:45 2019 +0100

    Use cyclecount instead of cycle_count since it is a gauge

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 602350b333cf9353d2cd0ffd40206c96ffe29941
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 18:09:25 2019 +0100

    other build options

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 5aa38f678451d5b63ffdc32336345a1ff6703725
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 18:08:56 2019 +0100

    Update fixtures

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit c6acc474a4224b8d9f7b178d0d2e02636d8629ea
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 17:20:30 2019 +0100

    Update command line parameter flag

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit f5a329e6ae5ed3b16aa866d67b944f1a73edfe42
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 17:20:06 2019 +0100

    Update procfs dependency

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 38d5fa5165643d6a44dc863b3a1696774259ac0d
Merge: 5a7ce69 28f3582
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Mar 9 16:28:29 2019 +0100

    Merge branch 'power_supply_class' of github.com:shaardie/node_exporter into power_supply_class

commit 5a7ce69505079c9c090e44448cfbd7ffb2b04df7
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Oct 20 18:55:49 2018 +0200

    Updated Metrics of Power Supply Class

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 690ab1b9c1f2e183b7088cf81c7f266d85ee6df6
Author: Sven Haardiek <sven@haardiek.de>
Date:   Fri Oct 19 20:03:42 2018 +0200

    Start work on Power Supply Collector

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 28f358222bbac4315fbf44d94da36d4b0ff2ed55
Author: Sven Haardiek <sven@haardiek.de>
Date:   Sat Oct 20 18:55:49 2018 +0200

    Updated Metrics of Power Supply Class

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

commit 751d99b818503e9a4430b10c39760f180349b294
Author: Sven Haardiek <sven@haardiek.de>
Date:   Fri Oct 19 20:03:42 2018 +0200

    Start work on Power Supply Collector

    Signed-off-by: Sven Haardiek <sven@haardiek.de>

Signed-off-by: Sven Haardiek <sven@haardiek.de>
2019-10-27 16:03:35 +01:00

195 lines
7 KiB
Go

// Copyright 2019 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 !nopowersupplyclass
// +build linux
package collector
import (
"fmt"
"regexp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
powerSupplyClassIgnoredPowerSupplies = kingpin.Flag("collector.powersupply.ignored-supplies", "Regexp of power supplies to ignore for powersupplyclass collector.").Default("^$").String()
)
type powerSupplyClassCollector struct {
subsystem string
ignoredPattern *regexp.Regexp
metricDescs map[string]*prometheus.Desc
}
func init() {
registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector)
}
func NewPowerSupplyClassCollector() (Collector, error) {
pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies)
return &powerSupplyClassCollector{
subsystem: "power_supply",
ignoredPattern: pattern,
metricDescs: map[string]*prometheus.Desc{},
}, nil
}
func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error {
powerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern)
if err != nil {
return fmt.Errorf("could not get power_supply class info: %s", err)
}
for _, powerSupply := range powerSupplyClass {
for name, value := range map[string]*int64{
"authentic": powerSupply.Authentic,
"calibrate": powerSupply.Calibrate,
"capacity": powerSupply.Capacity,
"capacity_alert_max": powerSupply.CapacityAlertMax,
"capacity_alert_min": powerSupply.CapacityAlertMin,
"cyclecount": powerSupply.CycleCount,
"online": powerSupply.Online,
"present": powerSupply.Present,
"time_to_empty_seconds": powerSupply.TimeToEmptyNow,
"time_to_full_seconds": powerSupply.TimeToFullNow,
} {
if value != nil {
pushPowerSupplyMetric(ch, c.subsystem, name, float64(*value), powerSupply.Name, prometheus.GaugeValue)
}
}
for name, value := range map[string]*int64{
"current_boot": powerSupply.CurrentBoot,
"current_max": powerSupply.CurrentMax,
"current_ampere": powerSupply.CurrentNow,
"energy_empty": powerSupply.EnergyEmpty,
"energy_empty_design": powerSupply.EnergyEmptyDesign,
"energy_full": powerSupply.EnergyFull,
"energy_full_design": powerSupply.EnergyFullDesign,
"energy_watthour": powerSupply.EnergyNow,
"voltage_boot": powerSupply.VoltageBoot,
"voltage_max": powerSupply.VoltageMax,
"voltage_max_design": powerSupply.VoltageMaxDesign,
"voltage_min": powerSupply.VoltageMin,
"voltage_min_design": powerSupply.VoltageMinDesign,
"voltage_volt": powerSupply.VoltageNow,
"voltage_ocv": powerSupply.VoltageOCV,
"charge_control_limit": powerSupply.ChargeControlLimit,
"charge_control_limit_max": powerSupply.ChargeControlLimitMax,
"charge_counter": powerSupply.ChargeCounter,
"charge_empty": powerSupply.ChargeEmpty,
"charge_empty_design": powerSupply.ChargeEmptyDesign,
"charge_full": powerSupply.ChargeFull,
"charge_full_design": powerSupply.ChargeFullDesign,
"charge_ampere": powerSupply.ChargeNow,
"charge_term_current": powerSupply.ChargeTermCurrent,
"constant_charge_current": powerSupply.ConstantChargeCurrent,
"constant_charge_current_max": powerSupply.ConstantChargeCurrentMax,
"constant_charge_voltage": powerSupply.ConstantChargeVoltage,
"constant_charge_voltage_max": powerSupply.ConstantChargeVoltageMax,
"precharge_current": powerSupply.PrechargeCurrent,
"input_current_limit": powerSupply.InputCurrentLimit,
"power_watt": powerSupply.PowerNow,
} {
if value != nil {
pushPowerSupplyMetric(ch, c.subsystem, name, float64(*value)/1e6, powerSupply.Name, prometheus.GaugeValue)
}
}
for name, value := range map[string]*int64{
"temp_celsius": powerSupply.Temp,
"temp_alert_max_celsius": powerSupply.TempAlertMax,
"temp_alert_min_celsius": powerSupply.TempAlertMin,
"temp_ambient_celsius": powerSupply.TempAmbient,
"temp_ambient_max_celsius": powerSupply.TempAmbientMax,
"temp_ambient_min_celsius": powerSupply.TempAmbientMin,
"temp_max_celsius": powerSupply.TempMax,
"temp_min_celsius": powerSupply.TempMin,
} {
if value != nil {
pushPowerSupplyMetric(ch, c.subsystem, name, float64(*value)/10.0, powerSupply.Name, prometheus.GaugeValue)
}
}
var (
keys []string
values []string
)
for name, value := range map[string]string{
"power_supply": powerSupply.Name,
"capacity_level": powerSupply.CapacityLevel,
"charge_type": powerSupply.ChargeType,
"health": powerSupply.Health,
"manufacturer": powerSupply.Manufacturer,
"model_name": powerSupply.ModelName,
"serial_number": powerSupply.SerialNumber,
"status": powerSupply.Status,
"technology": powerSupply.Technology,
"type": powerSupply.Type,
"usb_type": powerSupply.UsbType,
"scope": powerSupply.Scope,
} {
if value != "" {
keys = append(keys, name)
values = append(values, value)
}
}
fieldDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, c.subsystem, "info"),
"info of /sys/class/power_supply/<power_supply>.",
keys,
nil,
)
ch <- prometheus.MustNewConstMetric(fieldDesc, prometheus.GaugeValue, 1.0, values...)
}
return nil
}
func pushPowerSupplyMetric(ch chan<- prometheus.Metric, subsystem string, name string, value float64, powerSupplyName string, valueType prometheus.ValueType) {
fieldDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, name),
fmt.Sprintf("%s value of /sys/class/power_supply/<power_supply>.", name),
[]string{"power_supply"},
nil,
)
ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, value, powerSupplyName)
}
func getPowerSupplyClassInfo(ignore *regexp.Regexp) (sysfs.PowerSupplyClass, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, err
}
powerSupplyClass, err := fs.PowerSupplyClass()
if err != nil {
return powerSupplyClass, fmt.Errorf("error obtaining power_supply class info: %s", err)
}
for device := range powerSupplyClass {
if ignore.MatchString(device) {
delete(powerSupplyClass, device)
}
}
return powerSupplyClass, nil
}