Skip to content

Commit 0252795

Browse files
committed
Initial commit
1 parent 64a28b2 commit 0252795

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# machine-metrics
22
Script to install and run Prometheus Node Exporter (https://github.com/prometheus/node_exporter)
3+
4+
Usage:
5+
6+
```
7+
sudo -H ./install.sh
8+
```
9+
10+
You can then control the service as per a normal systemd service, i.e.
11+
12+
* `sudo systemctl [start|stop|enable|disable] machine-metrics.service`
13+
* `systemctl status machine-metrics.service`
14+
* `sudo journalctl --unit montagu-staging`

install.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
HERE=$(dirname $(realpath $0))
5+
TARGET=/etc/systemd/system/machine-metrics.service
6+
7+
if [[ "$HOME" != /root ]]; then
8+
echo "Run with sudo -H ./install.sh"
9+
exit 1;
10+
fi
11+
12+
set -x
13+
sudo snap install --classic go
14+
go get github.com/prometheus/node_exporter
15+
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/node_exporter
16+
make
17+
18+
cp $HERE/machine-metrics.service $TARGET
19+
sed -i "s:__PATH__:$HERE:g" $TARGET
20+
systemctl enable machine-metrics
21+
22+
set +x
23+
echo ""
24+
echo "Prometheus node exporter is installed at a service and is running at:"
25+
echo ""
26+
echo "http://localhost:9100/metrics"
27+
echo ""

machine-metrics.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Prometheus Node Metrics Exporter
3+
Wants=network-online.target
4+
After=network-online.target
5+
6+
[Install]
7+
WantedBy=multi-user.target
8+
9+
[Service]
10+
WorkingDirectory=__PATH__
11+
ExecStart=__PATH__/run.sh
12+
Type=simple

run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
/root/go/src/github.com/prometheus/node_exporter/node_exporter

0 commit comments

Comments
 (0)