title: Set Up Prometheus Server without Kubernetes author: Ying Chen type: post date: 2020-04-01T00:00:00+00:00 url: /set-up-prometheus-server-without-kubernetes/ sf_thumbnail_type:
To taste Hue prometheus metrics, you may set up a Prometheus server to scrape the metrics endpoint /metrics on a Hue server (which may not need to run in docker or Kubernetes). Here is the set up example on Ubuntu 16.4.
Prerequisites: a Hue server running at localhost:8000.
Create a service user
$ sudo useradd --no-create-home --shell /bin/false prometheus
Create a directory in /etc for Prometheus’ configuration files and a directory in /var/lib for its data
$ sudo mkdir /etc/prometheus
$ sudo mkdir /var/lib/prometheus
Set the user and group ownership on the new directories to the prometheus user
$ sudo chown prometheus:prometheus /etc/prometheus
$ sudo chown prometheus:prometheus /var/lib/prometheus
Download Prometheus binary from https://prometheus.io/download/
$ cd ~/Downloads
$ curl -LO https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz
Validate checksum value with download
$ Sha256sum prometheus-2.16.0.linux-amd64.tar.gz
Unpack the downloaded archive
$ tar xvf prometheus-2.16.0.linux-amd64.tar.gz
Copy the two binaries to the /usr/local/bin directory
$ sudo cp prometheus-2.16.0.linux-amd64/prometheus /usr/local/bin/
$ sudo cp prometheus-2.16.0.linux-amd64/promtool /usr/local/bin/
Copy the consoles and console_libraries directories to /etc/prometheus.
$ sudo cp -r prometheus-2.16.0.linux-amd64/consoles /etc/prometheus
$ sudo cp -r prometheus-2.16.0.linux-amd64/console_libraries /etc/prometheus
Set the user and group ownership on the directories to the prometheus user. Using the -R flag will ensure that ownership is set on the files inside the directory as well.
$ sudo chown -R prometheus:prometheus /etc/prometheus/consoles
$ sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
Remove the leftover files from your downloads folder
$ rm -rf prometheus-2.16.0.linux-amd64.tar.gz prometheus-2.16.0.linux-amd64
Create a configuration file named prometheus.yml
$ vi /etc/prometheus/prometheus.yml
Content of prometheus.yml, port 8000 is your Hue server port, and change it if needed.
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'hue'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8000']
Set the user and group ownership on the configuration file to the prometheus user
$ sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
Create a new systemd service file.
$ vi /etc/systemd/system/prometheus.service
Content of service file
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
To use the newly created service, reload and start systemd.
$ sudo systemctl daemon-reload
$ sudo systemctl start prometheus
When you open the browser at localhost:9090, you will see the Prometheus server page like the screenshot below.
Any feedback or questions? Feel free to comment here or on the Forum or @gethue and quick start SQL querying!
Ying Chen from the Hue Team