-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from backend-developers-ltd/proxy
Proxy
- Loading branch information
Showing
104 changed files
with
827 additions
and
2,475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ media/ | |
.terraform/ | ||
.nox/ | ||
__pycache__ | ||
./central-prometheus.yml | ||
./on-site-prometheus.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "prometheus"] | ||
path = prometheus | ||
url = git@github.com:prometheus/prometheus.git | ||
[submodule "protobuf"] | ||
path = protobuf | ||
url = https://github.com/gogo/protobuf.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Use Python base image from DockerHub | ||
FROM python:3.11 | ||
|
||
RUN pip install bittensor==8.2.0 | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y wget curl && \ | ||
wget https://github.com/prometheus/prometheus/releases/download/v2.55.0/prometheus-2.55.0.linux-amd64.tar.gz && \ | ||
tar xvzf prometheus-*.tar.gz && \ | ||
mkdir /etc/prometheus && \ | ||
mv prometheus-2.55.0.linux-amd64/prometheus /bin/ && \ | ||
mv prometheus-2.55.0.linux-amd64/promtool /bin/ && \ | ||
mv prometheus-2.55.0.linux-amd64/prometheus.yml /etc/prometheus/ && \ | ||
rm -rf prometheus-*.tar.gz prometheus-2.55.0.linux-amd64 && \ | ||
chown -R nobody:nogroup /etc/prometheus && \ | ||
chown -R nobody:nogroup /etc/prometheus | ||
|
||
RUN chown nobody: /etc/prometheus | ||
|
||
COPY read_wallet_and_substitute_config.py /app/ | ||
RUN chown -R nobody: /app/ | ||
|
||
COPY entrypoint.sh / | ||
RUN chown nobody: /entrypoint.sh | ||
|
||
RUN mkdir /nonexistent | ||
RUN chown nobody: /nonexistent | ||
|
||
RUN mkdir /wallets | ||
RUN chown nobody: /wallets | ||
|
||
#USER nobody | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Here lie the tools to build an image that runs prometheus but before starting reads the hotkey of a configured ( | ||
via env vars) bittensor wallet and allows for including that hotkey in prometheus' config. | ||
|
||
|
||
To run it, you need to provide a template of the prometheus config (only the hotkey part is meant to substituted when | ||
materializing this template), mount your wallet and specify it using env vars. for example: | ||
|
||
config: | ||
|
||
```yaml | ||
global: | ||
scrape_interval: 5s | ||
evaluation_interval: 5s | ||
|
||
scrape_configs: | ||
- job_name: "node" | ||
scrape_interval: 5s | ||
static_configs: | ||
- targets: ['host.docker.internal:9100'] | ||
labels: | ||
hotkey: '{hotkey}' # the 'template engine' in use is python's str.format() | ||
|
||
``` | ||
|
||
running: | ||
|
||
docker run \ | ||
-v config.yml:/etc/prometheus/prometheus.yml.template \ | ||
-v /home/user/.bittensor/wallets/:/wallets/ \ | ||
-e BITTENSOR_WALLET_NAME=validator \ | ||
-e BITTENSOR_WALLET_HOTKEY_NAME=default \ | ||
backenddevelopersltd/bittensor_prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
set -e | ||
python /app/read_wallet_and_substitute_config.py | ||
exec /bin/prometheus --config.file=/etc/prometheus/prometheus.yml "$@" |
34 changes: 34 additions & 0 deletions
34
app/bittensor_prometheus/read_wallet_and_substitute_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import pathlib | ||
|
||
import bittensor | ||
|
||
|
||
BITTENSOR_WALLET_NAME = os.environ.get("BITTENSOR_WALLET_NAME") | ||
BITTENSOR_WALLET_HOTKEY_NAME = os.environ.get("BITTENSOR_WALLET_HOTKEY_NAME") | ||
|
||
|
||
def get_wallet() -> bittensor.wallet: | ||
wallet = bittensor.wallet( | ||
name=BITTENSOR_WALLET_NAME, | ||
hotkey=BITTENSOR_WALLET_HOTKEY_NAME, | ||
path="/wallets", | ||
) | ||
wallet.hotkey_file.get_keypair() # this raises errors if the keys are inaccessible | ||
return wallet | ||
|
||
|
||
def read_and_substitute_config(hotkey: str): | ||
tmpl = pathlib.Path("/etc/prometheus/prometheus.yml.template").read_text() | ||
pathlib.Path("/etc/prometheus/prometheus.yml").write_text(tmpl.format(hotkey=hotkey)) | ||
|
||
|
||
def main(): | ||
if not BITTENSOR_WALLET_NAME or not BITTENSOR_WALLET_HOTKEY_NAME: | ||
raise RuntimeError("You must set BITTENSOR_WALLET_NAME and BITTENSOR_WALLET_HOTKEY_NAME env vars") | ||
wallet = get_wallet() | ||
read_and_substitute_config(wallet.hotkey.ss58_address) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.