Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion collector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ COPY ./collector/server.py /app

EXPOSE 5000

ENTRYPOINT [ "python", "server.py" ]
ENTRYPOINT [ "python", "server.py"]

CMD [ "--config-file-path", "/tmp/config.json"]
24 changes: 20 additions & 4 deletions collector/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from threading import Thread
import enum
import logging
import json

from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -115,7 +116,12 @@ async def metrics():

if __name__ == "__main__":
parser = argparse.ArgumentParser("snmp coolness")

parser.add_argument(
"--config-file-path",
required=True,
help="Path to config file that stores IPs",
)

parser.add_argument(
"--ips",
help="List of IP addresses of snmp agent (default: 192.168.69.208,192.168.69.149)",
Expand All @@ -140,10 +146,20 @@ async def metrics():
)

args = parser.parse_args()
ip_list = args.ips.split(',')
try:
with open(args.config_file_path, "r") as f:
config = json.load(f)
left_ip = config["PRINTING"]["LEFT"]["IP"]
right_ip = config["PRINTING"]["RIGHT"]["IP"]
ip_list=[left_ip, right_ip]

logging.info(f"connected to left printer ip: {left_ip}")
logging.info(f"connected to right printer ip: {right_ip}")
thread = Thread(target = scrape_snmp, args=(ip_list,), daemon=True)
thread.start()
except Exception as e:
logging.error(f"error opening config file: {e}")

thread = Thread(target = scrape_snmp, args=(ip_list,), daemon=True)
thread.start()
uvicorn.run(
app,
host=args.host,
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
build:
context: .
dockerfile: ./collector/Dockerfile

volumes:
- ./config/config.json:/tmp/config.json
# we attach the print container to an external docker
# network called "poweredge". we do this so a prometheus
# container can pull metrics from the server over HTTP
Expand Down