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

Use dashboard.out directly #15

Closed
BobLamarley opened this issue Jul 11, 2024 · 14 comments
Closed

Use dashboard.out directly #15

BobLamarley opened this issue Jul 11, 2024 · 14 comments

Comments

@BobLamarley
Copy link

BobLamarley commented Jul 11, 2024

Hello Adin,
I have a question, if i followed you're tutorial on you're website : https://hodovi.cc/blog/django-monitoring-with-prometheus-and-grafana/
I have'nt added ExportModelOperationsMixin on any of my django models,
And i already configured a datasources.yaml file, that is mounted inside the grafana:

apiVersion: 1

datasources:
  - name: Prometheus
    type: prometheus
    uid: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true
    jsonData:
      timeInterval: 5s

Am i supposed to/ Can i import the json files in dashboard_out/ directly into the grafana website ?
Since my datasource has an uid called prometheus, i've just replaced all the "uid": "$datasource" to "uid": "prometheus" but i think this isn't enough to make it work (I tried with this one: https://github.com/adinhodovic/django-mixin/blob/main/dashboards_out/django-overview.json ):
image

@adinhodovic
Copy link
Owner

adinhodovic commented Jul 11, 2024

Hey, are you running in a K8s environment?

The namespace varaible might be empty due to not running in a k8s env.

I see that migrations graph have metrics at one point.

@BobLamarley
Copy link
Author

BobLamarley commented Jul 11, 2024

Nope, i'm using docker
Yes you see that too, the migration metrics seems to be correctly working
And inside my prometheus there is all my metrics so they are here, but not correctly readed by the dashboard, i don't know where to look at :)
For example, i've also imported this dashboard (https://grafana.com/grafana/dashboards/17658-django/) just by changing the datasource uid to prometheus and it is working but it doesn't has any $namespace so maybe it is the point

@adinhodovic
Copy link
Owner

@adinhodovic
Copy link
Owner

It's this PR: #13.

@BobLamarley
Copy link
Author

No, i've created a new dashboard and imported the json but this is the same, only the migrations metrics is here

@adinhodovic
Copy link
Owner

I'm not sure, what's your scrape interval? Do you have metrics there?

do you see anything in prometheus for e.g django_http_responses_total_by_status_view_method_total?

@BobLamarley
Copy link
Author

My scrape interval is set to 15sec:
image
And no in metrics from prometheus i don't see anything related to views:
image
I've followed you're tutorial, i've added in my backend settings.py the two middleware PrometheusBeforeMiddleware and PrometheusAfterMiddleware, for my database changed the engine with the django_prometheus.db.backends.postgresql and updated urls.py, but i've not done any config for the views
I should add on my models somethings like that ? :
image

@adinhodovic
Copy link
Owner

adinhodovic commented Jul 11, 2024

Hmm, the /metrics should not have any metrics for django, those are prometheus runtime metrics. Can you open your prometheus UI and see if prometheus is scraping django and if there are view metrics related to for example: django_http_responses_total_by_status_view_method_total.

The model changes are not required.

@BobLamarley
Copy link
Author

In the prom UI, there is metrics for the view:
image
Here are all the method related to view that i have:
image

@adinhodovic
Copy link
Owner

Cool, so that works. Might just be insufficient amount of requests. If you increase the time range in grafana to lets say 7 days does anything show?

@BobLamarley
Copy link
Author

BobLamarley commented Jul 11, 2024

You was right, it was insufficient amount of data, everything works great, on production there will be a lot more of requests so more accurate, thanks a lot for the help :)
When i will need to monitor specific models, i will need to add a new panel, should i use your template with libsonnet to generate a new dashboard or can i add the panel inside grafana directly ?

@adinhodovic
Copy link
Owner

adinhodovic commented Jul 11, 2024

The dashboards don't support monitoring of specific models as of yet. There are no panels that cover that. I might add it soon! You can open a new issue for that or even a PR if you want. Ofcourse you can adjust the dashboards yourself on, but it's not provided out of the box yet. Open an Issue!

Happy to hear that it works. You can generate alerts or use preconfigured also: https://github.com/adinhodovic/django-mixin/blob/main/prometheus_alerts.yaml.

@BobLamarley
Copy link
Author

Thanks a lot, I will think about it when i will monitor my specific models, why not create a PR :)
For alerts, i see that there's a dashboard url pointing to https://grafana.com, since i'm using a self hosted grafana, i should change this ?
image
Also do you have an idea on how to pass the prometheus_alerts.yml file to prometheus in my docker compose, should i also use --config.file param for alerts config file ?
image

@adinhodovic
Copy link
Owner

adinhodovic commented Jul 12, 2024

The grafana URL for alerts is generated from config files here: https://github.com/adinhodovic/django-mixin/blob/remove-ns-dependency/config.libsonnet#L14. Everything is adjustable. However, the Grafana URL is only used for alerts and not necessary, here's a template for slack that uses the dashboard_url: https://hodovi.cc/blog/creating-awesome-alertmanager-templates-for-slack/.

Regarding prometheus, don't know of the top of my head, I use K8s/operators and that differs. I'll close this issue as it's unrelated.

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