Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exporter): Add endpoint for RQ metrics #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tarunps
Copy link
Member

@tarunps tarunps commented Jan 3, 2025

Closes frappe/press#1283

  • Adds endpoint to fetch RQ metrics for all benches on server
  • Adds endpoint to fetch RQ metrics per bench
  • Exempts all benches endpoint from token validation
    • Will be proxying this through nginx metrics endpoints and that has it's own validation setup
    • Force redirect the agent endpoint to nginx one

TODO:
- Add to nginx.conf

		location /agent/benches/metrics {
			return 301 /metrics/rq;
		}
		location /metrics/rq {
			proxy_pass http://127.0.0.1:25052/benches/metrics;
		}

@tarunps tarunps force-pushed the feat/agent-rq-monitor branch 2 times, most recently from fde0a3a to e6c7c22 Compare January 3, 2025 08:05
@adityahase
Copy link
Member

adityahase commented Jan 3, 2025

Looks good. Needs a few changes.

The exemption you added will make /agent/benches/metrics publicly accessible without credentials. Add a forced redirect in NGINX config to /metrics/rq.

Add "rq" in https://github.com/frappe/press/blob/26205eb65e9fd32234114299f17809424e63bfbf/press/api/monitoring.py#L55 So Prometheus scrapes this endpoint.

@tarunps tarunps force-pushed the feat/agent-rq-monitor branch from e6c7c22 to a47c740 Compare January 3, 2025 13:05
def get_bench_metrics(bench):
from prometheus_client.exposition import generate_latest

return generate_latest(RQCollector(bench)) or "asa"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"asa" ???

@ankush
Copy link
Member

ankush commented Jan 6, 2025

Looking at diff I can't quite figure out how will this work with bench workers... is this only intended for Agent RQ workers?

def get_bench_metrics(bench):
from prometheus_client.exposition import generate_latest

return generate_latest(RQCollector(bench)) or "asa"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this stray. I don't know why I added it.


rq_jobs = GaugeMetricFamily("rq_jobs", "RQ jobs by state", labels=["bench", "queue", "status"])

workers = get_workers_stats(REDIS_PORT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this hardcoded port. You will have to expose redis_queue ports to 127.0.0.1

Ref:

agent/agent/bench.py

Lines 694 to 705 in 48f4dd3

ssh_port = self.bench_config.get("ssh_port", self.bench_config["web_port"] + 4000)
ssh_ip = self.bench_config.get("private_ip", "127.0.0.1")
bench_directory = "/home/frappe/frappe-bench"
mounts = self.prepare_mounts_on_host(bench_directory)
command = (
"docker run -d --init -u frappe "
f"--restart always --hostname {self.name} "
f"-p 127.0.0.1:{self.bench_config['web_port']}:8000 "
f"-p 127.0.0.1:{self.bench_config['socketio_port']}:9000 "
f"-p 127.0.0.1:{self.bench_config['codeserver_port']}:8088 "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup monitoring for Redis RQ
3 participants