From a8fa5e4534461d568c08261e0b7b9b32cc708f9d Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 8 Oct 2024 14:24:15 -0700 Subject: [PATCH] feat: update node-exporter example for smoother configuration --- node-exporter/.gitignore | 2 + node-exporter/README.md | 125 ++++-------------------------- node-exporter/docker-compose.yml | 25 +++--- node-exporter/greptime.env.sample | 7 ++ 4 files changed, 40 insertions(+), 119 deletions(-) create mode 100644 node-exporter/greptime.env.sample diff --git a/node-exporter/.gitignore b/node-exporter/.gitignore index 9cc11e3..2051fb3 100644 --- a/node-exporter/.gitignore +++ b/node-exporter/.gitignore @@ -1,2 +1,4 @@ /prometheus-data /prometheus.yml +greptime.env +greptime.env.bak diff --git a/node-exporter/README.md b/node-exporter/README.md index 5dd94a6..ef8fcef 100644 --- a/node-exporter/README.md +++ b/node-exporter/README.md @@ -14,114 +14,33 @@ First of all, let's get a free GreptimeDB service: 1. Obtain a free GreptimeDB service from [GreptimeCloud](https://console.greptime.cloud/). 2. Click the "Connection Information" button and find the connection string. -3. Export the necessary environment variables: +3. Create a `greptime.env` by copy the `greptime.env.sample` and fill with your + connection information. ```shell -export GREPTIME_HOST="" -``` - -```shell -export GREPTIME_DATABASE="" -``` - -```shell -export GREPTIME_USERNAME="" -``` - -```shell -export GREPTIME_PASSWORD="" +GREPTIME_SCHEME=https +GREPTIME_PORT=443 + +## Fill with your connection information +GREPTIME_HOST= +GREPTIME_DB= +GREPTIME_USERNAME= +GREPTIME_PASSWORD= ``` ![Connection](/media/conninfo.png) -## Step 2: Start the Node Exporter - -Node Exporter is a Prometheus exporter for hardware and OS metrics exposed by Linus or Darwin kernels. - -You can download and run the Node Exporter from its [release page](https://github.com/prometheus/node_exporter/releases). For example, run the following command if your system is `darwin-arm64`: +## Step 2: Start Node Exporter and Prometheus with Docker Compose -```bash -curl -fsSL -O https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.darwin-arm64.tar.gz -tar -xvzf node_exporter-1.8.2.darwin-arm64.tar.gz -cd node_exporter-1.8.2.darwin-arm64 -./node_exporter -``` - -The Node Exporter should print several INFO logs: +We build a docker-compose file to start Prometheus node exporter and Prometheus +with just one call. Make sure you have `docker` and `docker-compose` +installed. Run: ``` -... -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:111 level=info msg="Enabled collectors" -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=boottime -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=cpu -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=diskstats -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=filesystem -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=loadavg -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=meminfo -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=netdev -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=os -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=powersupplyclass -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=textfile -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=thermal -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=time -ts=2024-07-19T01:46:25.629Z caller=node_exporter.go:118 level=info collector=uname -ts=2024-07-19T01:46:25.629Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9100 -ts=2024-07-19T01:46:25.629Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9100 -... -``` - -Now, you can get the current hardware and OS metrics with: - -```bash -curl http://localhost:9100/metrics -``` - -## Step 3: Scrape Metrics and Push to GreptimeDB - -As shown above, the Node Exporter only exposes an endpoint that you can query the current metrics. To scrape these metrics and push them to the GreptimeDB service, you can either: - -1. Start up a Prometheus instance on localhost that's configured to scrape metrics from the running Node Exporter, and remotely write to the GreptimeDB service; or, -2. If the Node Exporter endpoint can be accessed from publish network, you can open the Web Dashboard of the GreptimeDB service, head to the Workbench tab (`https://.greptime.cloud/dashboard/workbench`), and modify the `prometheus.yml` file to add the config as described below. - -Since the Node Exporter started above is running on localhost, this demo chooses the first option. - -You can download and run a Prometheus instance from its [release page](https://github.com/prometheus/prometheus/releases). For example, run the following command if your system is `darwin-arm64`: - -```bash -curl -fsSL -O https://github.com/prometheus/prometheus/releases/download/v2.53.1/prometheus-2.53.1.darwin-arm64.tar.gz -tar -xvzf prometheus-2.53.1.darwin-arm64.tar.gz -cd prometheus-2.53.1.darwin-arm64 -``` - -Modify the `prometheus.yml` file with: - -> [!TIP] -> -> If you switch to a new session, you need to re-export the environment variables as in [Step 1](#step-1-set-up-greptimedb-service). - -```bash -cat < prometheus.yml -global: - scrape_interval: 15s -scrape_configs: - - job_name: "node" - static_configs: - - targets: ["localhost:9100"] -remote_write: - - url: "https://${GREPTIME_HOST}/v1/prometheus/write?db=${GREPTIME_DATABASE}" - basic_auth: - username: ${GREPTIME_USERNAME} - password: ${GREPTIME_PASSWORD} -END -``` - -Start the bridge instance with: - -```bash -./prometheus --config.file=./prometheus.yml +docker compose up ``` -## Step 4: Visualize on GreptimeDB Dashboard +## Step 3: Visualize on GreptimeCloud Dashboard You can visualize the node mertics from the Web Dashboard: @@ -166,15 +85,3 @@ Choose "Import a dashboard" and then load the Node Exporter Full public template Use the data source you just registered, and click "Import". You will be redirected to the final dashboard: ![Grafana Final Dashboard](media/grafana-final-dashboard.png) - -## Bonus: Bootstrap with a Docker Compose oneliner - -This demo also provides a [docker-compose.yml](docker-compose.yml) file so that you can set up the whole Node Exporter integration in one line: - -Create your own `prometheus.yml` from `prometheus.yml.tpl` by replacing -placeholders with your GreptimeDB connection information. Start Prometheus/Node -Exporter/Grafana with docker compose: - -```bash -docker compose up -``` diff --git a/node-exporter/docker-compose.yml b/node-exporter/docker-compose.yml index 40c162b..ca29d10 100644 --- a/node-exporter/docker-compose.yml +++ b/node-exporter/docker-compose.yml @@ -1,4 +1,15 @@ services: + envsubst: + image: docker.io/widerplan/envsubst + command: "-i /config_input/prometheus.yml.tpl -o /config_output/prometheus.yml" + volumes: + - ./prometheus.yml.tpl:/config_input/prometheus.yml.tpl + - config:/config_output + env_file: + - path: "greptime.env" + required: false + init: true + node_exporter: image: quay.io/prometheus/node-exporter:latest container_name: node_exporter @@ -15,23 +26,17 @@ services: networks: - demo-network volumes: - - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro + - config:/etc/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--web.enable-lifecycle' depends_on: - node_exporter + - envsubst ports: - 9090:9090 - grafana: - image: docker.io/grafana/grafana:11.1.0 - ports: - - 3000:3000 - networks: - - demo-network - restart: always - - networks: demo-network: +volumes: + config: diff --git a/node-exporter/greptime.env.sample b/node-exporter/greptime.env.sample new file mode 100644 index 0000000..8273323 --- /dev/null +++ b/node-exporter/greptime.env.sample @@ -0,0 +1,7 @@ +GREPTIME_SCHEME=https +GREPTIME_PORT=443 + +GREPTIME_HOST= +GREPTIME_DB= +GREPTIME_USERNAME= +GREPTIME_PASSWORD=