Skip to content

Commit

Permalink
Running h3exporter as systemctl service
Browse files Browse the repository at this point in the history
  • Loading branch information
GilHoggarth committed Apr 8, 2023
1 parent 326d73e commit eedba07
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
31 changes: 6 additions & 25 deletions h3exporter/README
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
Python3 script to report WA hadoop3 key stats


CURRENTLY, BELOW systemctl SETUP NOT WORK - ISSUE WITH D-BUS AND monitor USER
To set up as a systemctl daemon, as the root user:
* Copy h3exporter service file to systemctl directory
* cp h3exporter.service /usr/lib/systemd/system/

To set up as a systemctl daemon:
* Ensure user systemd directory exists
* mkdir -p ~/.config/systemd/user

* Create service file as ~/.config/systemd/user/h3exporter.service, chmod 644

```
[Unit]
Description=h3exporter systemctl configuration
After=network.target

[Service]
Type=simple
ExecStart=/home/monitor/github/ukwa-monitor/h3exporter/run_h3exporter.sh
Restart=always
RestartSec=30

[Install]
WantedBy=default.target
```

* Reload user systemctl
* systemctl --user daemon-reload
* Reload systemctl
* systemctl daemon-reload

* Enable and start h3exporter service
* systemctl --user enable --now h3exporter
* systemctl enable --now h3exporter
10 changes: 5 additions & 5 deletions h3exporter/h3exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# globals
logger = logging.getLogger(__name__)
SCRIPTNAME = os.path.splitext(os.path.basename(__main__.__file__))[0]
CONFIG = 'config/settings'
CONFIG = '/home/monitor/github/ukwa-monitor/h3exporter/config/settings'


# script --------------------
Expand Down Expand Up @@ -44,10 +44,10 @@ def script():
or ( underReplicated != prevUnderReplicated):
h3stats.send_hadoop_stats(settings, usedPercent, deadNodes, underReplicated)

# update previous values
prevUsedPercent = usedPercent
prevDeadNodes = deadNodes
prevUnderReplicated = underReplicated
# update previous values
prevUsedPercent = usedPercent
prevDeadNodes = deadNodes
prevUnderReplicated = underReplicated

# sleep until next time to send hadoop3 stats
time.sleep(int(settings['sleep']))
Expand Down
14 changes: 14 additions & 0 deletions h3exporter/h3exporter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=h3exporter systemctl configuration
After=network.target

[Service]
Type=forking
User=monitor
Group=monitor
ExecStart=/home/monitor/github/ukwa-monitor/h3exporter/run_h3exporter.sh
Restart=always
RestartSec=30

[Install]
WantedBy=default.target

0 comments on commit eedba07

Please sign in to comment.