Skip to content

Commit

Permalink
add "--idle" argument
Browse files Browse the repository at this point in the history
add --idle argument, allows script to set env/hr price based on provider idle power consumption
  • Loading branch information
jedbrooke committed Mar 6, 2024
1 parent 931414c commit c22c9d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set this file to run as a cron job every hour (or as often as you see fit)
for a full list of options see `golem-price-update.py --help`

```
usage: golem-price-update.py [-h] [--currency CURRENCY] [--price_kwh PRICE_KWH] [-w WATTS] [-p PROFIT] [-t THREADS] [-u] [--dry_run]
usage: golem-price-update.py [-h] [--currency CURRENCY] [--price_kwh PRICE_KWH] [-w WATTS] [--idle IDLE] [-p PROFIT] [-t THREADS] [-u] [--dry_run]
automatically adjust golem provider prices. GLM Price provided by CoinGecko
Expand All @@ -33,6 +33,7 @@ optional arguments:
electricity price per kwH in your fiat currency, default: 0.1
-w WATTS, --watts WATTS
power usage of your provider in watts, default: 150
--idle IDLE power usage of your provider in watts at idle.used to calculate env/hr rate.If not provided, env/hr will be 0 and all earnings will be from cpu/hr
-p PROFIT, --profit PROFIT
desired additional profit beyond electricity costs, (1.0 is 100 percent), default: 0.1 (10 percent)
-t THREADS, --threads THREADS
Expand Down
42 changes: 26 additions & 16 deletions golem-price-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import os
import argparse
import subprocess
import sys
import time
import shlex
import random


Expand All @@ -19,6 +16,11 @@ def parse_args():
default=0.1)
parser.add_argument("-w", "--watts", type=int, help="power usage of your provider in watts, default: 150",
default=150)
parser.add_argument("--idle", type=int, help="power usage of your provider in watts at idle."
"used to calculate env/hr rate."
"If not provided, env/hr will be 0 and all earnings will be from cpu/hr",
default=0)

# TODO: add option to target earnings that could have been made by mining a coin/other workload
parser.add_argument("-p", "--profit", type=float,
help="desired additional profit beyond electricity costs, (1.0 is 100 percent), default: 0.1 (10 percent)",
Expand Down Expand Up @@ -72,12 +74,12 @@ def print_arg(k, v) -> str:
# TODO make this settable by an arg
job.minute.on(random.randint(0, 59))
job.hour.every(1)
if args.dry_run:
print("removing the following jobs from crontab")
print(*cron.find_comment(comment), sep="\n")
print("adding the following to cron tab:")
print(job)
else:

print("removing the following jobs from crontab")
print(*cron.find_comment(comment), sep="\n")
print("adding the following to cron tab:")
print(job)
if not args.dry_run:
# remove old job
cron.remove_all(comment=comment)
cron.append(job)
Expand All @@ -93,17 +95,25 @@ def print_arg(k, v) -> str:
if args.threads < 0:
num_threads = max(os.cpu_count() + args.threads, 1)

cost_per_hour = (args.watts * 0.001) * args.price_kwh
desired_income_per_hour = cost_per_hour * (1 + args.profit)
load_watts = args.watts - args.idle

cost_per_hour_load = (load_watts * 0.001) * args.price_kwh
desired_income_per_hour = cost_per_hour_load * (1 + args.profit)
price_per_thread_fiat = desired_income_per_hour / num_threads
price_per_thread_glm = price_per_thread_fiat * (1 / glm_price)
if args.dry_run:
print("CPU per hour:", price_per_thread_glm)
else:

cost_per_hour_idle = (args.idle * 0.001) * args.price_kwh
price_per_env_fiat = cost_per_hour_idle * (1 + args.profit)
price_per_env_glm = price_per_env_fiat * (1 / glm_price)

# print the price to show the user
print("CPU per hour:", price_per_thread_glm)
print("ENV per hour:", price_per_env_glm)

if not args.dry_run:
# set the price
golem_path = os.path.expanduser("~/.local/bin/golemsp")

# fixed in yagna 0.9.1
subprocess.call([golem_path, "settings", "set", "--cpu-per-hour", str(price_per_thread_glm)])
subprocess.call([golem_path, "settings", "set", "--env-per-hour", "0"])
subprocess.call([golem_path, "settings", "set", "--env-per-hour", str(price_per_env_glm)])
subprocess.call([golem_path, "settings", "set", "--starting-fee", "0"])

0 comments on commit c22c9d1

Please sign in to comment.