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

[question] Does this repo only support kubernetes metrics? #198

Closed
Jeffwan opened this issue Jun 30, 2024 · 3 comments
Closed

[question] Does this repo only support kubernetes metrics? #198

Jeffwan opened this issue Jun 30, 2024 · 3 comments

Comments

@Jeffwan
Copy link

Jeffwan commented Jun 30, 2024

I am curious whether this custom pod autoscaler framework support fetching metrics from pod directly instead of using kubernetes metrics?

@jthomperoo
Copy link
Owner

jthomperoo commented Jun 30, 2024

Hi @Jeffwan, yes Custom Pod Autoscalers can fetch metrics directly from pods, see this example to see how to do that:

https://github.com/jthomperoo/custom-pod-autoscaler/tree/5d39741bd6990c5268dc46dddcac2e7e8c0067ba/example/simple-pod-metrics-python

In the metric.py script it grabs the pod IP and uses that to send a request to an arbitrary /metrics endpoint exposed by the pod:

def metric(spec):
# Get Pod IP
status = spec["resource"]["status"]
ip = status["podIP"]
try:
# Make request to Pod metric endpoint
# (see ../flask-metrics/ folder for simple flask app exposing this endpoint)
response = requests.get(f"http://{ip}:5000/metric")
# Output whatever metrics are gathered to stdout
sys.stdout.write(response.text)
except HTTPError as http_err:
# If an error occurs, output error to stderr and exit with status 1
sys.stderr.write(f"HTTP error occurred: {http_err}")
exit(1)
except Exception as err:
# If an error occurs, output error to stderr and exit with status 1
sys.stderr.write(f"Other error occurred: {err}")
exit(1)

You can read more about the per-pod run mode which runs metric gathering per pod in the documentation here:
https://custom-pod-autoscaler.readthedocs.io/en/latest/user-guide/metric-gathering/#per-pod

@jthomperoo
Copy link
Owner

jthomperoo commented Jul 1, 2024

If my response above hasn't answered your question fully just re-open this issue with a comment explaining why.
Thanks!

@Jeffwan
Copy link
Author

Jeffwan commented Jul 1, 2024

@jthomperoo Thanks! I read the code and understand how it works now. kuberneresMetrics is actually additional metrics cpa can help feed into metric component, the primary focus could be per service or per pod metric scraping

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

No branches or pull requests

2 participants