### Install jsonnet and jb Source: https://github.com/prometheus/node_exporter/blob/master/docs/node-mixin/README.md Install the necessary tools for using the Node Mixin. Ensure you have a working Go development environment. ```bash go install github.com/google/go-jsonnet/cmd/jsonnet@latest go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest ``` -------------------------------- ### Install Node Mixin Dependencies Source: https://github.com/prometheus/node_exporter/blob/master/docs/node-mixin/README.md Install the project's dependencies using jsonnet-bundler. Run this command in the root directory of the mixin. ```bash jb install ``` -------------------------------- ### Install node_exporter as LaunchDaemon Source: https://github.com/prometheus/node_exporter/blob/master/examples/launchctl/README.md Copy the node_exporter binary and its launchd plist file to the appropriate system directories. Bootstrap the service using launchctl to enable it to run automatically. ```bash sudo cp -n node_exporter /usr/local/bin/ sudo cp -n examples/launchctl/io.prometheus.node_exporter.plist /Library/LaunchDaemons/ sudo launchctl bootstrap system/ /Library/LaunchDaemons/io.prometheus.node_exporter.plist ``` -------------------------------- ### Run Node Exporter on Custom Address and Path Source: https://context7.com/prometheus/node_exporter/llms.txt Starts the Node Exporter listening on a custom port (9200) and exposing metrics at a custom path (/node-metrics). ```bash ./node_exporter --web.listen-address=":9200" --web.telemetry-path="/node-metrics" ``` -------------------------------- ### Start Node Exporter with TLS and Basic Auth Source: https://context7.com/prometheus/node_exporter/llms.txt Launch node_exporter using a web configuration file that specifies TLS certificates and user credentials for authentication. Scrape metrics using curl with appropriate authentication and TLS settings. ```bash # Start with TLS and basic auth ./node_exporter --web.config.file=web-config.yml # Scrape with credentials curl -u prometheus:prometheus_password \ --cacert node_exporter.crt \ https://localhost:9100/metrics | grep node_load ``` -------------------------------- ### Configure node_exporter Arguments Source: https://github.com/prometheus/node_exporter/blob/master/examples/launchctl/README.md Optionally, configure command-line arguments for node_exporter by creating an arguments file. This example sets the web listen address to port 9101. ```bash echo -- '--web.listen-address=:9101' | sudo tee /usr/local/etc/node_exporter.args ``` -------------------------------- ### Print node_exporter Process State Source: https://github.com/prometheus/node_exporter/blob/master/examples/launchctl/README.md Get detailed information about the node_exporter process state using the 'launchctl print' command. ```bash sudo launchctl print system/io.prometheus.node_exporter ``` -------------------------------- ### Start Node Exporter with Textfile Collector Source: https://context7.com/prometheus/node_exporter/llms.txt Configure node_exporter to read custom metrics from a specified directory. Ensure metrics files are written atomically to prevent partial reads. ```bash # Start node_exporter pointing at a textfile directory ./node_exporter --collector.textfile.directory=/var/lib/node_exporter/textfile_collector # Write a custom metric atomically (use temp file + rename to avoid partial reads) cat <<'EOF' > /tmp/custom_metrics.prom.tmp # HELP batch_job_last_success_timestamp_seconds Unix timestamp of last successful batch job run. # TYPE batch_job_last_success_timestamp_seconds gauge batch_job_last_success_timestamp_seconds{job="nightly_backup"} 1700000000 # HELP hardware_sensor_temperature_celsius Current hardware temperature in Celsius. # TYPE hardware_sensor_temperature_celsius gauge hardware_sensor_temperature_celsius{sensor="cpu_package"} 52.5 EOF mv /tmp/custom_metrics.prom.tmp /var/lib/node_exporter/textfile_collector/custom_metrics.prom # Verify the custom metrics appear curl -s http://localhost:9100/metrics | grep -E 'batch_job|hardware_sensor' # Expected output: # batch_job_last_success_timestamp_seconds{job="nightly_backup"} 1.7e+09 # hardware_sensor_temperature_celsius{sensor="cpu_package"} 52.5 # node_textfile_mtime_seconds{file="/var/lib/node_exporter/textfile_collector/custom_metrics.prom"} 1.7e+09 # node_textfile_scrape_error 0 ``` ```bash # Multiple directories and glob patterns are supported (repeatable flag) ./node_exporter \ --collector.textfile.directory=/var/lib/node_exporter \ --collector.textfile.directory=/opt/app/metrics ``` -------------------------------- ### Expose Single Numeric Sysctl Value Source: https://github.com/prometheus/node_exporter/blob/master/README.md Enable the sysctl collector and use --collector.sysctl.include to expose a single numeric sysctl value as a metric. For example, vm.user_reserve_kbytes. ```bash --collector.sysctl --collector.sysctl.include=vm.user_reserve_kbytes ``` -------------------------------- ### Build and Run Node Exporter with Defaults Source: https://context7.com/prometheus/node_exporter/llms.txt Builds the Node Exporter from source and runs it with default settings. Verifies that metrics are being served by fetching the first 30 lines of the /metrics endpoint. ```bash git clone https://github.com/prometheus/node_exporter.git cd node_exporter make build ./node_exporter # Verify metrics are being served curl -s http://localhost:9100/metrics | head -30 ``` -------------------------------- ### Build Node Exporter Source: https://github.com/prometheus/node_exporter/blob/master/README.md Clone the repository, navigate to the directory, and run 'make build' to compile the node_exporter. Use '' to pass any desired command-line arguments. ```bash git clone https://github.com/prometheus/node_exporter.git cd node_exporter make build ./node_exporter ``` -------------------------------- ### Enable Perf Tracepoint Collection Source: https://github.com/prometheus/node_exporter/blob/master/README.md Use the --collector.perf.tracepoint flag to enable the collection of tracepoint counts. Specify the tracepoint name, for example, 'sched:sched_process_exec'. ```bash --collector.perf.tracepoint="sched:sched_process_exec" ``` -------------------------------- ### Enable and Configure Sysctl Collector Source: https://context7.com/prometheus/node_exporter/llms.txt Activate the sysctl collector and specify which kernel parameters to expose as metrics. Numeric values become gauges, and string values become info metrics. ```bash # Enable sysctl collector with specific keys ./node_exporter \ --collector.sysctl \ --collector.sysctl.include=vm.user_reserve_kbytes \ --collector.sysctl.include="net.ipv4.tcp_rmem:min,default,max" \ --collector.sysctl.include-info=kernel.hostname # Expected output: # node_sysctl_vm_user_reserve_kbytes 131072 # node_sysctl_net_ipv4_tcp_rmem_min 4096 # node_sysctl_net_ipv4_tcp_rmem_default 131072 # node_sysctl_net_ipv4_tcp_rmem_max 6291456 # node_sysctl_info{index="0",key="kernel.hostname",value="myserver"} 1 ``` -------------------------------- ### Display Node Exporter Help Source: https://github.com/prometheus/node_exporter/blob/master/README.md Run the compiled node_exporter with the -h flag to view all available configuration flags and options. ```bash ./node_exporter -h ``` -------------------------------- ### Run Node Exporter Tests Source: https://github.com/prometheus/node_exporter/blob/master/README.md Execute the test suite for the node_exporter by running 'make test' in the project directory. ```bash make test ``` -------------------------------- ### Create and Register NodeCollector for Specific Metrics Source: https://context7.com/prometheus/node_exporter/llms.txt Demonstrates how to create a `NodeCollector` instance filtered to include only 'cpu' and 'meminfo' collectors. It then registers this collector with a Prometheus registry and gathers/prints the metrics. ```go // Usage: create a NodeCollector restricted to cpu and meminfo nc, err := collector.NewNodeCollector(logger, "cpu", "meminfo") if err != nil { log.Fatal(err) } reg := prometheus.NewRegistry() reg.MustRegister(nc) // Gather and print metrics mfs, _ := reg.Gather() for _, mf := range mfs { fmt.Println(mf.GetName(), "->", len(mf.GetMetric()), "series") } ``` -------------------------------- ### Enable TLS Endpoint Source: https://github.com/prometheus/node_exporter/blob/master/README.md Configure the node_exporter to use TLS by providing a web configuration file using the '--web.config.file' flag. Refer to the exporter-toolkit documentation for detailed configuration options. ```console ./node_exporter --web.config.file=web-config.yml ``` -------------------------------- ### Query CPU Metrics Source: https://context7.com/prometheus/node_exporter/llms.txt Queries the node_exporter for key CPU metrics. Ensure the CPU collector is enabled. ```bash # Query key CPU metrics curl -s http://localhost:9100/metrics | grep -E '^node_cpu' ``` -------------------------------- ### Enable Network Address Info and Detailed Metrics Source: https://context7.com/prometheus/node_exporter/llms.txt Enables the collection of network interface address information and detailed network metrics. This provides a more comprehensive view of network activity. ```bash # Enable address info collection and detailed metrics ./node_exporter \ --collector.netdev.address-info \ --collector.netdev.enable-detailed-metrics ``` -------------------------------- ### Generate TLS Certificate and Web Config Source: https://context7.com/prometheus/node_exporter/llms.txt Create a self-signed certificate for testing TLS encryption and define a web configuration file to enable TLS and basic authentication for node_exporter. ```bash # Generate a self-signed cert (for testing) openssl req -newkey rsa:2048 -nodes -keyout node_exporter.key \ -x509 -days 365 -out node_exporter.crt \ -subj "/CN=node_exporter" # web-config.yml cat <<'EOF' > web-config.yml tls_server_config: cert_file: node_exporter.crt key_file: node_exporter.key basic_auth_users: # Password is bcrypt hash of "prometheus_password" prometheus: $2y$10$OikMDE/c3fUW/JdIRFzDxuQE.yJAT4xkMd7VChEVbLH3l4MkjHY5u EOF ``` -------------------------------- ### Query Filesystem Metrics Source: https://context7.com/prometheus/node_exporter/llms.txt Queries the node_exporter for filesystem size metrics. This is useful for monitoring disk space utilization. ```bash # Query filesystem metrics curl -s http://localhost:9100/metrics | grep '^node_filesystem_size' ``` -------------------------------- ### Expose Multiple String Sysctl Values Source: https://github.com/prometheus/node_exporter/blob/master/README.md Use --collector.sysctl.include-info to expose multiple string values from a sysctl as individual info metrics, each with an 'index' label. ```bash --collector.sysctl --collector.sysctl.include-info=kernel.seccomp.actions_avail ``` -------------------------------- ### Enable Extended CPU Info Source: https://context7.com/prometheus/node_exporter/llms.txt Enables extended CPU information collection, including flag and bug filtering. Use this to fine-tune the CPU metrics gathered. ```bash # Enable extended CPU info with flag/bug filtering ./node_exporter \ --collector.cpu.info \ --collector.cpu.info.flags-include="avx|avx2|sse4_2" \ --collector.cpu.info.bugs-include="spectre_v1|meltdown" ```