Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gitlab-org/build/omnibus-mirror/node_exporter
1 result
Show changes
Commits on Source (14)
Showing
with 405 additions and 217 deletions
sudo: false
language: go
go:
- 1.8.x
- 1.9.x
- master
go_import_path: github.com/prometheus/node_exporter
script:
- make
Loading
Loading
@@ -27,6 +27,10 @@ DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
MACH ?= $(shell uname -m)
DOCKERFILE ?= Dockerfile
 
# TODO: Remove deprecated and problematic InstrumentHandlerFunc usage.
STATICCHECK_IGNORE = \
github.com/prometheus/node_exporter/node_exporter.go:SA1019
ifeq ($(GOHOSTARCH),amd64)
# Only supported on amd64
test-flags := -race
Loading
Loading
@@ -99,7 +103,7 @@ vet:
 
staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
@$(STATICCHECK) $(pkgs)
@$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
 
build: $(PROMU)
@echo ">> building binaries"
Loading
Loading
Loading
Loading
@@ -107,6 +107,39 @@ echo 'role{role="application_server"} 1' > /path/to/directory/role.prom.$$
mv /path/to/directory/role.prom.$$ /path/to/directory/role.prom
```
 
### Filtering enabled collectors
The node_exporter will expose all metrics from enabled collectors by default, but it can be passed an optional list of collectors to filter metrics. The `collect[]` parameter accepts values matching enabled collector names.
This can be useful for specifying different scrape intervals for different collectors in Prometheus:
```yaml
scrape_configs:
- job_name: 'node resources'
scrape_interval: 15s
static_configs:
- targets:
- '192.168.1.2:9100'
params:
collect[]:
- cpu
- meminfo
- diskstats
- netdev
- netstat
- job_name: 'node storage'
scrape_interval: 1m
static_configs:
- targets:
- '192.168.1.2:9100'
params:
collect[]:
- filefd
- filesystem
- xfs
```
## Building and running
 
Prerequisites:
Loading
Loading
@@ -133,40 +166,16 @@ To see all available configuration flags:
## Using Docker
The node\_exporter is designed to monitor the host system. It's not recommended
to deploy it as Docker container because it requires access to the host system.
If you need to run it on Docker, you can deploy this exporter using the
[node-exporter Docker
image](https://quay.io/repository/prometheus/node-exporter) with the following
options and bind-mounts:
Be aware that any non-root mount points you want to monitor will need bind-mounted
into the container.
 
for docker version >= 1.10
```bash
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro,rslave" \
docker run -d \
--net="host" \
quay.io/prometheus/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
--pid="host" \
quay.io/prometheus/node-exporter
```
 
for docker version < 1.10
```bash
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
quay.io/prometheus/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
```
Be aware though that the mountpoint label in various metrics will now have
`/rootfs` as prefix.
## Using a third-party repository for RHEL/CentOS/Fedora
 
There is a [community-supplied COPR repository](https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/). It closely follows upstream releases.
Loading
Loading
Loading
Loading
@@ -80,7 +80,18 @@ type nodeCollector struct {
}
 
// NewNodeCollector creates a new NodeCollector
func NewNodeCollector() (*nodeCollector, error) {
func NewNodeCollector(filters ...string) (*nodeCollector, error) {
f := make(map[string]bool)
for _, filter := range filters {
enabled, exist := collectorState[filter]
if !exist {
return nil, fmt.Errorf("missing collector: %s", filter)
}
if !*enabled {
return nil, fmt.Errorf("disabled collector: %s", filter)
}
f[filter] = true
}
collectors := make(map[string]Collector)
for key, enabled := range collectorState {
if *enabled {
Loading
Loading
@@ -88,7 +99,9 @@ func NewNodeCollector() (*nodeCollector, error) {
if err != nil {
return nil, err
}
collectors[key] = collector
if len(f) == 0 || f[key] {
collectors[key] = collector
}
}
}
return &nodeCollector{Collectors: collectors}, nil
Loading
Loading
Loading
Loading
@@ -861,6 +861,120 @@ node_infiniband_unicast_packets_received_total{device="mlx4_0",port="2"} 0
# TYPE node_infiniband_unicast_packets_transmitted_total counter
node_infiniband_unicast_packets_transmitted_total{device="mlx4_0",port="1"} 61239
node_infiniband_unicast_packets_transmitted_total{device="mlx4_0",port="2"} 0
# HELP node_interrupts Interrupt details.
# TYPE node_interrupts counter
node_interrupts{CPU="0",devices="",info="APIC ICR read retries",type="RTR"} 0
node_interrupts{CPU="0",devices="",info="Function call interrupts",type="CAL"} 148554
node_interrupts{CPU="0",devices="",info="IRQ work interrupts",type="IWI"} 1.509379e+06
node_interrupts{CPU="0",devices="",info="Local timer interrupts",type="LOC"} 1.74326351e+08
node_interrupts{CPU="0",devices="",info="Machine check exceptions",type="MCE"} 0
node_interrupts{CPU="0",devices="",info="Machine check polls",type="MCP"} 2406
node_interrupts{CPU="0",devices="",info="Non-maskable interrupts",type="NMI"} 47
node_interrupts{CPU="0",devices="",info="Performance monitoring interrupts",type="PMI"} 47
node_interrupts{CPU="0",devices="",info="Rescheduling interrupts",type="RES"} 1.0847134e+07
node_interrupts{CPU="0",devices="",info="Spurious interrupts",type="SPU"} 0
node_interrupts{CPU="0",devices="",info="TLB shootdowns",type="TLB"} 1.0460334e+07
node_interrupts{CPU="0",devices="",info="Thermal event interrupts",type="TRM"} 0
node_interrupts{CPU="0",devices="",info="Threshold APIC interrupts",type="THR"} 0
node_interrupts{CPU="0",devices="acpi",info="IR-IO-APIC-fasteoi",type="9"} 398553
node_interrupts{CPU="0",devices="ahci",info="IR-PCI-MSI-edge",type="43"} 7.434032e+06
node_interrupts{CPU="0",devices="dmar0",info="DMAR_MSI-edge",type="40"} 0
node_interrupts{CPU="0",devices="dmar1",info="DMAR_MSI-edge",type="41"} 0
node_interrupts{CPU="0",devices="ehci_hcd:usb1, mmc0",info="IR-IO-APIC-fasteoi",type="16"} 328511
node_interrupts{CPU="0",devices="ehci_hcd:usb2",info="IR-IO-APIC-fasteoi",type="23"} 1.451445e+06
node_interrupts{CPU="0",devices="i8042",info="IR-IO-APIC-edge",type="1"} 17960
node_interrupts{CPU="0",devices="i8042",info="IR-IO-APIC-edge",type="12"} 380847
node_interrupts{CPU="0",devices="i915",info="IR-PCI-MSI-edge",type="44"} 140636
node_interrupts{CPU="0",devices="iwlwifi",info="IR-PCI-MSI-edge",type="46"} 4.3078464e+07
node_interrupts{CPU="0",devices="mei_me",info="IR-PCI-MSI-edge",type="45"} 4
node_interrupts{CPU="0",devices="rtc0",info="IR-IO-APIC-edge",type="8"} 1
node_interrupts{CPU="0",devices="snd_hda_intel",info="IR-PCI-MSI-edge",type="47"} 350
node_interrupts{CPU="0",devices="timer",info="IR-IO-APIC-edge",type="0"} 18
node_interrupts{CPU="0",devices="xhci_hcd",info="IR-PCI-MSI-edge",type="42"} 378324
node_interrupts{CPU="1",devices="",info="APIC ICR read retries",type="RTR"} 0
node_interrupts{CPU="1",devices="",info="Function call interrupts",type="CAL"} 157441
node_interrupts{CPU="1",devices="",info="IRQ work interrupts",type="IWI"} 2.411776e+06
node_interrupts{CPU="1",devices="",info="Local timer interrupts",type="LOC"} 1.35776678e+08
node_interrupts{CPU="1",devices="",info="Machine check exceptions",type="MCE"} 0
node_interrupts{CPU="1",devices="",info="Machine check polls",type="MCP"} 2399
node_interrupts{CPU="1",devices="",info="Non-maskable interrupts",type="NMI"} 5031
node_interrupts{CPU="1",devices="",info="Performance monitoring interrupts",type="PMI"} 5031
node_interrupts{CPU="1",devices="",info="Rescheduling interrupts",type="RES"} 9.111507e+06
node_interrupts{CPU="1",devices="",info="Spurious interrupts",type="SPU"} 0
node_interrupts{CPU="1",devices="",info="TLB shootdowns",type="TLB"} 9.918429e+06
node_interrupts{CPU="1",devices="",info="Thermal event interrupts",type="TRM"} 0
node_interrupts{CPU="1",devices="",info="Threshold APIC interrupts",type="THR"} 0
node_interrupts{CPU="1",devices="acpi",info="IR-IO-APIC-fasteoi",type="9"} 2320
node_interrupts{CPU="1",devices="ahci",info="IR-PCI-MSI-edge",type="43"} 8.092205e+06
node_interrupts{CPU="1",devices="dmar0",info="DMAR_MSI-edge",type="40"} 0
node_interrupts{CPU="1",devices="dmar1",info="DMAR_MSI-edge",type="41"} 0
node_interrupts{CPU="1",devices="ehci_hcd:usb1, mmc0",info="IR-IO-APIC-fasteoi",type="16"} 322879
node_interrupts{CPU="1",devices="ehci_hcd:usb2",info="IR-IO-APIC-fasteoi",type="23"} 3.333499e+06
node_interrupts{CPU="1",devices="i8042",info="IR-IO-APIC-edge",type="1"} 105
node_interrupts{CPU="1",devices="i8042",info="IR-IO-APIC-edge",type="12"} 1021
node_interrupts{CPU="1",devices="i915",info="IR-PCI-MSI-edge",type="44"} 226313
node_interrupts{CPU="1",devices="iwlwifi",info="IR-PCI-MSI-edge",type="46"} 130
node_interrupts{CPU="1",devices="mei_me",info="IR-PCI-MSI-edge",type="45"} 22
node_interrupts{CPU="1",devices="rtc0",info="IR-IO-APIC-edge",type="8"} 0
node_interrupts{CPU="1",devices="snd_hda_intel",info="IR-PCI-MSI-edge",type="47"} 224
node_interrupts{CPU="1",devices="timer",info="IR-IO-APIC-edge",type="0"} 0
node_interrupts{CPU="1",devices="xhci_hcd",info="IR-PCI-MSI-edge",type="42"} 1.734637e+06
node_interrupts{CPU="2",devices="",info="APIC ICR read retries",type="RTR"} 0
node_interrupts{CPU="2",devices="",info="Function call interrupts",type="CAL"} 142912
node_interrupts{CPU="2",devices="",info="IRQ work interrupts",type="IWI"} 1.512975e+06
node_interrupts{CPU="2",devices="",info="Local timer interrupts",type="LOC"} 1.68393257e+08
node_interrupts{CPU="2",devices="",info="Machine check exceptions",type="MCE"} 0
node_interrupts{CPU="2",devices="",info="Machine check polls",type="MCP"} 2399
node_interrupts{CPU="2",devices="",info="Non-maskable interrupts",type="NMI"} 6211
node_interrupts{CPU="2",devices="",info="Performance monitoring interrupts",type="PMI"} 6211
node_interrupts{CPU="2",devices="",info="Rescheduling interrupts",type="RES"} 1.5999335e+07
node_interrupts{CPU="2",devices="",info="Spurious interrupts",type="SPU"} 0
node_interrupts{CPU="2",devices="",info="TLB shootdowns",type="TLB"} 1.0494258e+07
node_interrupts{CPU="2",devices="",info="Thermal event interrupts",type="TRM"} 0
node_interrupts{CPU="2",devices="",info="Threshold APIC interrupts",type="THR"} 0
node_interrupts{CPU="2",devices="acpi",info="IR-IO-APIC-fasteoi",type="9"} 824
node_interrupts{CPU="2",devices="ahci",info="IR-PCI-MSI-edge",type="43"} 6.478877e+06
node_interrupts{CPU="2",devices="dmar0",info="DMAR_MSI-edge",type="40"} 0
node_interrupts{CPU="2",devices="dmar1",info="DMAR_MSI-edge",type="41"} 0
node_interrupts{CPU="2",devices="ehci_hcd:usb1, mmc0",info="IR-IO-APIC-fasteoi",type="16"} 293782
node_interrupts{CPU="2",devices="ehci_hcd:usb2",info="IR-IO-APIC-fasteoi",type="23"} 1.092032e+06
node_interrupts{CPU="2",devices="i8042",info="IR-IO-APIC-edge",type="1"} 28
node_interrupts{CPU="2",devices="i8042",info="IR-IO-APIC-edge",type="12"} 240
node_interrupts{CPU="2",devices="i915",info="IR-PCI-MSI-edge",type="44"} 347
node_interrupts{CPU="2",devices="iwlwifi",info="IR-PCI-MSI-edge",type="46"} 460171
node_interrupts{CPU="2",devices="mei_me",info="IR-PCI-MSI-edge",type="45"} 0
node_interrupts{CPU="2",devices="rtc0",info="IR-IO-APIC-edge",type="8"} 0
node_interrupts{CPU="2",devices="snd_hda_intel",info="IR-PCI-MSI-edge",type="47"} 0
node_interrupts{CPU="2",devices="timer",info="IR-IO-APIC-edge",type="0"} 0
node_interrupts{CPU="2",devices="xhci_hcd",info="IR-PCI-MSI-edge",type="42"} 440240
node_interrupts{CPU="3",devices="",info="APIC ICR read retries",type="RTR"} 0
node_interrupts{CPU="3",devices="",info="Function call interrupts",type="CAL"} 155528
node_interrupts{CPU="3",devices="",info="IRQ work interrupts",type="IWI"} 2.428828e+06
node_interrupts{CPU="3",devices="",info="Local timer interrupts",type="LOC"} 1.30980079e+08
node_interrupts{CPU="3",devices="",info="Machine check exceptions",type="MCE"} 0
node_interrupts{CPU="3",devices="",info="Machine check polls",type="MCP"} 2399
node_interrupts{CPU="3",devices="",info="Non-maskable interrupts",type="NMI"} 4968
node_interrupts{CPU="3",devices="",info="Performance monitoring interrupts",type="PMI"} 4968
node_interrupts{CPU="3",devices="",info="Rescheduling interrupts",type="RES"} 7.45726e+06
node_interrupts{CPU="3",devices="",info="Spurious interrupts",type="SPU"} 0
node_interrupts{CPU="3",devices="",info="TLB shootdowns",type="TLB"} 1.0345022e+07
node_interrupts{CPU="3",devices="",info="Thermal event interrupts",type="TRM"} 0
node_interrupts{CPU="3",devices="",info="Threshold APIC interrupts",type="THR"} 0
node_interrupts{CPU="3",devices="acpi",info="IR-IO-APIC-fasteoi",type="9"} 863
node_interrupts{CPU="3",devices="ahci",info="IR-PCI-MSI-edge",type="43"} 7.492252e+06
node_interrupts{CPU="3",devices="dmar0",info="DMAR_MSI-edge",type="40"} 0
node_interrupts{CPU="3",devices="dmar1",info="DMAR_MSI-edge",type="41"} 0
node_interrupts{CPU="3",devices="ehci_hcd:usb1, mmc0",info="IR-IO-APIC-fasteoi",type="16"} 351412
node_interrupts{CPU="3",devices="ehci_hcd:usb2",info="IR-IO-APIC-fasteoi",type="23"} 2.644609e+06
node_interrupts{CPU="3",devices="i8042",info="IR-IO-APIC-edge",type="1"} 28
node_interrupts{CPU="3",devices="i8042",info="IR-IO-APIC-edge",type="12"} 198
node_interrupts{CPU="3",devices="i915",info="IR-PCI-MSI-edge",type="44"} 633
node_interrupts{CPU="3",devices="iwlwifi",info="IR-PCI-MSI-edge",type="46"} 290
node_interrupts{CPU="3",devices="mei_me",info="IR-PCI-MSI-edge",type="45"} 0
node_interrupts{CPU="3",devices="rtc0",info="IR-IO-APIC-edge",type="8"} 0
node_interrupts{CPU="3",devices="snd_hda_intel",info="IR-PCI-MSI-edge",type="47"} 0
node_interrupts{CPU="3",devices="timer",info="IR-IO-APIC-edge",type="0"} 0
node_interrupts{CPU="3",devices="xhci_hcd",info="IR-PCI-MSI-edge",type="42"} 2.434308e+06
# HELP node_intr Total number of interrupts serviced.
# TYPE node_intr counter
node_intr 8.885917e+06
Loading
Loading
@@ -2552,6 +2666,7 @@ node_scrape_collector_success{collector="entropy"} 1
node_scrape_collector_success{collector="filefd"} 1
node_scrape_collector_success{collector="hwmon"} 1
node_scrape_collector_success{collector="infiniband"} 1
node_scrape_collector_success{collector="interrupts"} 1
node_scrape_collector_success{collector="ipvs"} 1
node_scrape_collector_success{collector="ksmd"} 1
node_scrape_collector_success{collector="loadavg"} 1
Loading
Loading
@@ -2660,18 +2775,18 @@ node_xfs_allocation_btree_records_deleted_total{device="sda1"} 0
# HELP node_xfs_allocation_btree_records_inserted_total Number of allocation B-tree records inserted for a filesystem.
# TYPE node_xfs_allocation_btree_records_inserted_total counter
node_xfs_allocation_btree_records_inserted_total{device="sda1"} 0
# HELP node_xfs_block_mapping_btree_compares_total Number of block map B-tree compares for a filesystem.
# TYPE node_xfs_block_mapping_btree_compares_total counter
node_xfs_block_mapping_btree_compares_total{device="sda1"} 0
# HELP node_xfs_block_mapping_btree_lookups_total Number of block map B-tree lookups for a filesystem.
# TYPE node_xfs_block_mapping_btree_lookups_total counter
node_xfs_block_mapping_btree_lookups_total{device="sda1"} 0
# HELP node_xfs_block_mapping_btree_records_deleted_total Number of block map B-tree records deleted for a filesystem.
# TYPE node_xfs_block_mapping_btree_records_deleted_total counter
node_xfs_block_mapping_btree_records_deleted_total{device="sda1"} 0
# HELP node_xfs_block_mapping_btree_records_inserted_total Number of block map B-tree records inserted for a filesystem.
# TYPE node_xfs_block_mapping_btree_records_inserted_total counter
node_xfs_block_mapping_btree_records_inserted_total{device="sda1"} 0
# HELP node_xfs_block_map_btree_compares_total Number of block map B-tree compares for a filesystem.
# TYPE node_xfs_block_map_btree_compares_total counter
node_xfs_block_map_btree_compares_total{device="sda1"} 0
# HELP node_xfs_block_map_btree_lookups_total Number of block map B-tree lookups for a filesystem.
# TYPE node_xfs_block_map_btree_lookups_total counter
node_xfs_block_map_btree_lookups_total{device="sda1"} 0
# HELP node_xfs_block_map_btree_records_deleted_total Number of block map B-tree records deleted for a filesystem.
# TYPE node_xfs_block_map_btree_records_deleted_total counter
node_xfs_block_map_btree_records_deleted_total{device="sda1"} 0
# HELP node_xfs_block_map_btree_records_inserted_total Number of block map B-tree records inserted for a filesystem.
# TYPE node_xfs_block_map_btree_records_inserted_total counter
node_xfs_block_map_btree_records_inserted_total{device="sda1"} 0
# HELP node_xfs_block_mapping_extent_list_compares_total Number of extent list compares for a filesystem.
# TYPE node_xfs_block_mapping_extent_list_compares_total counter
node_xfs_block_mapping_extent_list_compares_total{device="sda1"} 0
Loading
Loading
Loading
Loading
@@ -82,7 +82,7 @@ func parseInterrupts(r io.Reader) (map[string]interrupt, error) {
}
intName := parts[0][:len(parts[0])-1] // remove trailing :
intr := interrupt{
values: parts[1:cpuNum],
values: parts[1 : cpuNum+1],
}
 
if _, err := strconv.Atoi(intName); err == nil { // numeral interrupt
Loading
Loading
Loading
Loading
@@ -33,4 +33,8 @@ func TestInterrupts(t *testing.T) {
if want, got := "5031", interrupts["NMI"].values[1]; want != got {
t.Errorf("want interrupts %s, got %s", want, got)
}
if want, got := "4968", interrupts["NMI"].values[3]; want != got {
t.Errorf("want interrupts %s, got %s", want, got)
}
}
Loading
Loading
@@ -39,7 +39,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
{name: "inactive_bytes", mib: "vm.stats.vm.v_inactive_count", conversion: fromPage},
{name: "wired_bytes", mib: "vm.stats.vm.v_wire_count", conversion: fromPage},
{name: "cache_bytes", mib: "vm.stats.vm.v_cache_count", conversion: fromPage},
{name: "buffer_bytes", mib: "vfs.bufspace"},
{name: "buffer_bytes", mib: "vfs.bufspace", dataType: bsdSysctlTypeCLong},
{name: "free_bytes", mib: "vm.stats.vm.v_free_count", conversion: fromPage},
{name: "size_bytes", mib: "vm.stats.vm.v_page_count", conversion: fromPage},
{name: "swap_in_bytes_total", mib: "vm.stats.vm.v_swappgsin", conversion: fromPage},
Loading
Loading
Loading
Loading
@@ -121,6 +121,12 @@ func parseNetStats(r io.Reader, fileName string) (map[string]map[string]string,
func getSNMP6Stats(fileName string) (map[string]map[string]string, error) {
file, err := os.Open(fileName)
if err != nil {
// On systems with IPv6 disabled, this file won't exist.
// Do nothing.
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
defer file.Close()
Loading
Loading
Loading
Loading
@@ -35,9 +35,11 @@ const (
bsdSysctlTypeUint32 bsdSysctlType = iota
bsdSysctlTypeUint64
bsdSysctlTypeStructTimeval
bsdSysctlTypeCLong
)
 
// Contains all the info needed to map a single bsd-sysctl to a prometheus value.
// Contains all the info needed to map a single bsd-sysctl to a prometheus
// value.
type bsdSysctl struct {
// Prometheus name
name string
Loading
Loading
@@ -72,42 +74,9 @@ func (b bsdSysctl) Value() (float64, error) {
tmp64, err = unix.SysctlUint64(b.mib)
tmpf64 = float64(tmp64)
case bsdSysctlTypeStructTimeval:
raw, err := unix.SysctlRaw(b.mib)
if err != nil {
return 0, err
}
/*
* From 10.3-RELEASE sources:
*
* /usr/include/sys/_timeval.h:47
* time_t tv_sec
* suseconds_t tv_usec
*
* /usr/include/sys/_types.h:60
* long __suseconds_t
*
* ... architecture dependent, via #ifdef:
* typedef __int64_t __time_t;
* typedef __int32_t __time_t;
*/
if len(raw) != (C.sizeof_time_t + C.sizeof_suseconds_t) {
// Shouldn't get here, unless the ABI changes...
return 0, fmt.Errorf(
"length of bytes received from sysctl (%d) does not match expected bytes (%d)",
len(raw),
C.sizeof_time_t+C.sizeof_suseconds_t,
)
}
secondsUp := unsafe.Pointer(&raw[0])
susecondsUp := uintptr(secondsUp) + C.sizeof_time_t
unix := float64(*(*C.time_t)(secondsUp))
usec := float64(*(*C.suseconds_t)(unsafe.Pointer(susecondsUp)))
// This conversion maintains the usec precision. Using
// the time package did not.
tmpf64 = unix + (usec / float64(1000*1000))
tmpf64, err = b.getStructTimeval()
case bsdSysctlTypeCLong:
tmpf64, err = b.getCLong()
}
 
if err != nil {
Loading
Loading
@@ -120,3 +89,69 @@ func (b bsdSysctl) Value() (float64, error) {
 
return tmpf64, nil
}
func (b bsdSysctl) getStructTimeval() (float64, error) {
raw, err := unix.SysctlRaw(b.mib)
if err != nil {
return 0, err
}
/*
* From 10.3-RELEASE sources:
*
* /usr/include/sys/_timeval.h:47
* time_t tv_sec
* suseconds_t tv_usec
*
* /usr/include/sys/_types.h:60
* long __suseconds_t
*
* ... architecture dependent, via #ifdef:
* typedef __int64_t __time_t;
* typedef __int32_t __time_t;
*/
if len(raw) != (C.sizeof_time_t + C.sizeof_suseconds_t) {
// Shouldn't get here, unless the ABI changes...
return 0, fmt.Errorf(
"length of bytes received from sysctl (%d) does not match expected bytes (%d)",
len(raw),
C.sizeof_time_t+C.sizeof_suseconds_t,
)
}
secondsUp := unsafe.Pointer(&raw[0])
susecondsUp := uintptr(secondsUp) + C.sizeof_time_t
unix := float64(*(*C.time_t)(secondsUp))
usec := float64(*(*C.suseconds_t)(unsafe.Pointer(susecondsUp)))
// This conversion maintains the usec precision. Using the time
// package did not.
return (unix + (usec / float64(1000*1000))), nil
}
func (b bsdSysctl) getCLong() (float64, error) {
raw, err := unix.SysctlRaw(b.mib)
if err != nil {
return 0, err
}
if len(raw) == C.sizeof_long {
return float64(*(*C.long)(unsafe.Pointer(&raw[0]))), nil
}
if len(raw) == C.sizeof_int {
// This is valid for at least vfs.bufspace, and the default
// long handler - which can clamp longs to 32-bits:
// https://github.com/freebsd/freebsd/blob/releng/10.3/sys/kern/vfs_bio.c#L338
// https://github.com/freebsd/freebsd/blob/releng/10.3/sys/kern/kern_sysctl.c#L1062
return float64(*(*C.int)(unsafe.Pointer(&raw[0]))), nil
}
return 0, fmt.Errorf(
"length of bytes received from sysctl (%d) does not match expected bytes (long: %d), (int: %d)",
len(raw),
C.sizeof_long,
C.sizeof_int,
)
}
Loading
Loading
@@ -16,9 +16,11 @@
package collector
 
import (
"syscall"
"bytes"
 
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
 
var unameDesc = prometheus.NewDesc(
Loading
Loading
@@ -47,18 +49,18 @@ func newUnameCollector() (Collector, error) {
}
 
func (c unameCollector) Update(ch chan<- prometheus.Metric) error {
var uname syscall.Utsname
if err := syscall.Uname(&uname); err != nil {
var uname unix.Utsname
if err := unix.Uname(&uname); err != nil {
return err
}
 
ch <- prometheus.MustNewConstMetric(unameDesc, prometheus.GaugeValue, 1,
unameToString(uname.Sysname),
unameToString(uname.Release),
unameToString(uname.Version),
unameToString(uname.Machine),
unameToString(uname.Nodename),
unameToString(uname.Domainname),
string(uname.Sysname[:bytes.IndexByte(uname.Sysname[:], 0)]),
string(uname.Release[:bytes.IndexByte(uname.Release[:], 0)]),
string(uname.Version[:bytes.IndexByte(uname.Version[:], 0)]),
string(uname.Machine[:bytes.IndexByte(uname.Machine[:], 0)]),
string(uname.Nodename[:bytes.IndexByte(uname.Nodename[:], 0)]),
string(uname.Domainname[:bytes.IndexByte(uname.Domainname[:], 0)]),
)
return nil
}
// Copyright 2015 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 386 amd64 arm64 mips64 mips64le mips mipsle
// +build linux
// +build !nouname
package collector
func unameToString(input [65]int8) string {
var str string
for _, a := range input {
if a == 0 {
break
}
str += string(a)
}
return str
}
// Copyright 2015 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 !nouname,linux,arm !nouname,linux,ppc64 !nouname,linux,ppc64le !nouname,linux,s390x
package collector
func unameToString(input [65]uint8) string {
var str string
for _, a := range input {
if a == 0 {
break
}
str += string(a)
}
return str
}
Loading
Loading
@@ -156,24 +156,24 @@ func (c *xfsCollector) updateXFSStats(ch chan<- prometheus.Metric, s *xfs.Stats)
value: float64(s.BlockMapping.ExtentListCompares),
},
{
name: "block_mapping_btree_lookups_total",
name: "block_map_btree_lookups_total",
desc: "Number of block map B-tree lookups for a filesystem.",
value: float64(s.AllocationBTree.Lookups),
value: float64(s.BlockMapBTree.Lookups),
},
{
name: "block_mapping_btree_compares_total",
name: "block_map_btree_compares_total",
desc: "Number of block map B-tree compares for a filesystem.",
value: float64(s.AllocationBTree.Compares),
value: float64(s.BlockMapBTree.Compares),
},
{
name: "block_mapping_btree_records_inserted_total",
name: "block_map_btree_records_inserted_total",
desc: "Number of block map B-tree records inserted for a filesystem.",
value: float64(s.AllocationBTree.RecordsInserted),
value: float64(s.BlockMapBTree.RecordsInserted),
},
{
name: "block_mapping_btree_records_deleted_total",
name: "block_map_btree_records_deleted_total",
desc: "Number of block map B-tree records deleted for a filesystem.",
value: float64(s.AllocationBTree.RecordsDeleted),
value: float64(s.BlockMapBTree.RecordsDeleted),
},
}
 
Loading
Loading
Loading
Loading
@@ -15,6 +15,7 @@ enabled_collectors=$(cat << COLLECTORS
filefd
hwmon
infiniband
interrupts
ipvs
ksmd
loadavg
Loading
Loading
Loading
Loading
@@ -14,6 +14,7 @@
package main
 
import (
"fmt"
"net/http"
_ "net/http/pprof"
 
Loading
Loading
@@ -29,6 +30,40 @@ func init() {
prometheus.MustRegister(version.NewCollector("node_exporter"))
}
 
func handler(w http.ResponseWriter, r *http.Request) {
filters := r.URL.Query()["collect[]"]
log.Debugln("collect query:", filters)
nc, err := collector.NewNodeCollector(filters...)
if err != nil {
log.Warnln("Couldn't create", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Couldn't create %s", err)))
return
}
registry := prometheus.NewRegistry()
err = registry.Register(nc)
if err != nil {
log.Errorln("Couldn't register collector:", err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Couldn't register collector: %s", err)))
return
}
gatherers := prometheus.Gatherers{
prometheus.DefaultGatherer,
registry,
}
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(gatherers,
promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
})
h.ServeHTTP(w, r)
}
func main() {
var (
listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9100").String()
Loading
Loading
@@ -43,6 +78,7 @@ func main() {
log.Infoln("Starting node_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
 
// This instance is only used to check collector creation and logging.
nc, err := collector.NewNodeCollector()
if err != nil {
log.Fatalf("Couldn't create collector: %s", err)
Loading
Loading
@@ -52,17 +88,8 @@ func main() {
log.Infof(" - %s", n)
}
 
if err := prometheus.Register(nc); err != nil {
log.Fatalf("Couldn't register collector: %s", err)
}
handler := promhttp.HandlerFor(prometheus.DefaultGatherer,
promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
})
// TODO(ts): Remove deprecated and problematic InstrumentHandler usage.
http.Handle(*metricsPath, prometheus.InstrumentHandler("prometheus", handler))
// TODO(ts): Remove deprecated and problematic InstrumentHandlerFunc usage.
http.HandleFunc(*metricsPath, prometheus.InstrumentHandlerFunc("prometheus", handler))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>
Loading
Loading
Loading
Loading
@@ -129,14 +129,9 @@ func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) e
errc <- fn(pid)
}(cmd.Process.Pid)
 
select {
case err := <-errc:
if cmd.Process != nil {
cmd.Process.Kill()
}
if err != nil {
return err
}
err := <-errc
if cmd.Process != nil {
cmd.Process.Kill()
}
return nil
return err
}
Loading
Loading
@@ -7,8 +7,6 @@
# data in them than you'd think.
# http://arstechnica.com/civis/viewtopic.php?p=22062211
 
disks="$(/usr/sbin/smartctl --scan | awk '{print $1 "|" $3}')"
parse_smartctl_attributes_awk="$(cat << 'SMARTCTLAWK'
$1 ~ /^[0-9]+$/ && $2 ~ /^[a-zA-Z0-9_-]+$/ {
gsub(/-/, "_");
Loading
Loading
@@ -34,6 +32,7 @@ host_writes_mib
host_writes_32mib
load_cycle_count
media_wearout_indicator
wear_leveling_count
nand_writes_1gib
offline_uncorrectable
power_cycle_count
Loading
Loading
@@ -136,7 +135,7 @@ if [[ "$(expr "${smartctl_version}" : '\([0-9]*\)\..*')" -lt 6 ]] ; then
exit
fi
 
device_list="$(/usr/sbin/smartctl --scan-open | awk '{print $1 "|" $3}')"
device_list="$(/usr/sbin/smartctl --scan-open | awk '/^\/dev/{print $1 "|" $3}')"
 
for device in ${device_list}; do
disk="$(echo ${device} | cut -f1 -d'|')"
Loading
Loading
Copyright 2015 Brett Vickers. All rights reserved.
Copyright 2015-2017 Brett Vickers. All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Loading
Loading
[![Build Status](https://travis-ci.org/beevik/ntp.svg?branch=master)](https://travis-ci.org/beevik/ntp)
[![GoDoc](https://godoc.org/github.com/beevik/ntp?status.svg)](https://godoc.org/github.com/beevik/ntp)
ntp
===
The ntp package is an implementation of a Simple NTP (SNTP) client based on
[RFC5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to
a remote NTP server and request the current time.
If all you care about is the current time according to a known remote NTP
server, simply use the `Time` function:
```go
time, err := ntp.Time("0.beevik-ntp.pool.ntp.org")
```
If you want the time as well as additional metadata about the time, use the
`Query` function instead:
```go
response, err := ntp.Query("0.beevik-ntp.pool.ntp.org")
```
To use the NTP pool in your application, please request your own
[vendor zone](http://www.pool.ntp.org/en/vendors.html). Avoid using
the `[number].pool.ntp.org` zone names in your applications.
[![Build Status](https://travis-ci.org/beevik/ntp.svg?branch=master)](https://travis-ci.org/beevik/ntp)
[![GoDoc](https://godoc.org/github.com/beevik/ntp?status.svg)](https://godoc.org/github.com/beevik/ntp)
ntp
===
The ntp package is an implementation of a Simple NTP (SNTP) client based on
[RFC5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to
a remote NTP server and request information about the current time.
## Querying the current time
If all you care about is the current time according to a remote NTP server,
simply use the `Time` function:
```go
time, err := ntp.Time("0.beevik-ntp.pool.ntp.org")
```
## Querying time metadata
To obtain the current time as well as some additional metadata about the time,
use the `Query` function:
```go
response, err := ntp.Query("0.beevik-ntp.pool.ntp.org")
time := time.Now().Add(response.ClockOffset)
```
Alternatively, use the `QueryWithOptions` function if you want to change the
default behavior used by the `Query` function:
```go
options := ntp.QueryOptions{ Timeout: 30*time.Second, TTL: 5 }
response, err := ntp.QueryWithOptions("0.beevik-ntp.pool.ntp.org", options)
time := time.Now().Add(response.ClockOffset)
```
The `Response` structure returned by `Query` includes the following
information:
* `Time`: The time the server transmitted its response, according to its own clock.
* `ClockOffset`: The estimated offset of the local system clock relative to the server's clock. For a more accurate time reading, you may add this offset to any subsequent system clock reading.
* `RTT`: An estimate of the round-trip-time delay between the client and the server.
* `Precision`: The precision of the server's clock reading.
* `Stratum`: The server's stratum, which indicates the number of hops from the server to the reference clock. A stratum 1 server is directly attached to the reference clock. If the stratum is zero, the server has responded with the "kiss of death".
* `ReferenceID`: A unique identifier for the consulted reference clock.
* `ReferenceTime`: The time at which the server last updated its local clock setting.
* `RootDelay`: The server's aggregate round-trip-time delay to the stratum 1 server.
* `RootDispersion`: The server's estimated maximum measurement error relative to the reference clock.
* `RootDistance`: An estimate of the root synchronization distance between the client and the stratum 1 server.
* `Leap`: The leap second indicator, indicating whether a second should be added to or removed from the current month's last minute.
* `MinError`: A lower bound on the clock error between the client and the server.
* `KissCode`: A 4-character string describing the reason for a "kiss of death" response (stratum=0).
* `Poll`: The maximum polling interval between successive messages to the server.
The `Response` structure's `Validate` method performs additional sanity checks
to determine whether the response is suitable for time synchronization
purposes.
```go
err := response.Validate()
if err == nil {
// response data is suitable for synchronization purposes
}
```
## Using the NTP pool
The NTP pool is a shared resource used by people all over the world.
To prevent it from becoming overloaded, please avoid querying the standard
`pool.ntp.org` zone names in your applications. Instead, consider requesting
your own [vendor zone](http://www.pool.ntp.org/en/vendors.html) or [joining
the pool](http://www.pool.ntp.org/join.html).