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

Feature : Add Prometheus metrics #3535

Closed
pichouk opened this issue Feb 6, 2021 · 23 comments
Closed

Feature : Add Prometheus metrics #3535

pichouk opened this issue Feb 6, 2021 · 23 comments

Comments

@pichouk
Copy link
Contributor

pichouk commented Feb 6, 2021

Hi,

I'm currently hosting a Wekan instance for several organisations, and I wonder if we can add a Prometheus endpoint to get some metrics from Wekan, for example :

  • number of users
  • number of connected users
  • number of boards (public or private)

Prometheus is really the leading monitoring solution, and a lot of online softwares have integrated Prometheus exporter (or plugins that does the job).
I guess it should not be too complicated as it consists of exposing a simple plain text file under /metrics, as described in Prometheus documentation. This page is generated regularly based on database query.

I'm not a Javascript developer (nor a developer actually), but I may try to implement an opt-in Prometheus exporter feature if it sounds interesting for other people. Or at least help to describe/design the feature.

@mfilser
Copy link
Contributor

mfilser commented Feb 6, 2021

I think the best to integrate third party apps is using the Wekan API.

@xet7
Copy link
Member

xet7 commented Feb 7, 2021

Yes. For those counts, you would add REST API code to wekan/models/*.js so that admin user (that has logged in to rest api and has valid bearer token) is aithorized to get that info. Then you would call that api in cron script that would write that textfile.

@xet7
Copy link
Member

xet7 commented Feb 7, 2021

@xet7
Copy link
Member

xet7 commented Feb 7, 2021

Related #1308

@pichouk
Copy link
Contributor Author

pichouk commented Feb 8, 2021

Yes, maybe I can directly use the API. But I would like some advices because it would be nice to have an API endpoint to get all private boards.

Right now, /api/boards return only public boards, and to get private boards I have to loop on /api/users/{user}/boards for each user (which is really inefficient for a large instance). IMHO it seems logical that /api/boards returns all boards, with an attribute that indicate if a board is private or not.
But it would be a breaking change, so I don't think it will be merged if I submit a PR. Should we had another endpoint ? /api/privateboard ? Or add a GET parameter to /api/boards to choose public or private boards ?

@xet7
Copy link
Member

xet7 commented Feb 8, 2021

@pichouk

You should add new API endpoint that does .count query/queries and returns number. Not loop through everything with cursor.

@pichouk
Copy link
Contributor Author

pichouk commented Feb 10, 2021

🤔 I'm not sure to understand. You mean I should create a /api/boards_count endpoint that return the number of public/private boards ?

@xet7
Copy link
Member

xet7 commented Feb 10, 2021

@pichouk

Yes. Somewhere here:
https://github.com/wekan/wekan/blob/master/models/boards.js#L1710

With this kind of MongoDB database counting query:

const privateBoardsCount = Boards.find({ 'permission': 'private' }).count()
const publicBoardsCount = Boards.find({ 'permission': 'public' }).count()

@pichouk
Copy link
Contributor Author

pichouk commented Feb 10, 2021

Ok I see, thanks I'll take a look and submit a PR !

@xet7
Copy link
Member

xet7 commented Feb 10, 2021

@pichouk

You can build Wekan, test code changes, and send pull request like similar like here:
https://github.com/wekan/wekan/wiki/Emoji#how-you-could-add-another-plugin

But with only your code changes, no need to add any plugin.

@xet7
Copy link
Member

xet7 commented Feb 11, 2021

Fixed at #3556

@xet7 xet7 closed this as completed Feb 11, 2021
@Emile840
Copy link
Contributor

Hi,

@pichouk, did you find a way to implement that prometheus exporter ?
@xet7, do you mind (or do you thing is a good idea) if i implement a new end point in WeKan "/metrics" that will be exposed without authentication and return severals metrics on promotheus text format ?

@xet7
Copy link
Member

xet7 commented Jan 27, 2022

@Emile840

Wow, without authentication? Those that mass scan Internet would get a lot of details. I prefer no.

@xet7
Copy link
Member

xet7 commented Jan 27, 2022

WeKan already has Matomo Web Analytics integration, is that not enough?
https://github.com/wekan/wekan-snap/wiki/Supported-settings-keys#matomo-web-analytics-integration

@Emile840
Copy link
Contributor

@xet7,
You're right about authentication issue.
unfortunately, Matomo web will not be enough, how about below solution for working around this authentication issue?

  • Adding a possibility for wekan admin user to set (in admin panel ) a list of ip adress that will be authorized when calling "/metrics" end point
  • When "/metrics" is called, before performing any action, check first if calling adress was been setted by wekan user

@xet7
Copy link
Member

xet7 commented Jan 27, 2022

@Emile840

Yes allowed IP address list for metrics is OK.

@pichouk
Copy link
Contributor Author

pichouk commented Jan 27, 2022

Just FYI I made a little python script to act as a Prometheus exporter, which use the Wekan API. it is hosted here but IIRC this is a private Gitlab instance. If you need it I may provide you a gist.

@xet7
Copy link
Member

xet7 commented Jan 27, 2022

@pichouk

Please provide gist. Thanks!

@pichouk
Copy link
Contributor Author

pichouk commented Jan 27, 2022

You can find a copy of the code here https://gist.github.com/pichouk/2040c30127bec7a561d31d646c4571a7

I'm not sure it will be very helpful because this is just a simple Python script running (in Docker) on the same server than the Wekan instance. This is not great software 😂
Also, please note that I'm not on the entity that run this script anymore, so I am not really able to debug it.

@xet7
Copy link
Member

xet7 commented Jan 27, 2022

@pichouk

It's very helpful. There are many Python scripts for WeKan already, this is great addition. Thanks!

@xet7 xet7 reopened this Jan 27, 2022
@xet7
Copy link
Member

xet7 commented Jan 27, 2022

@pichouk

I added wiki page about what Python code there is for WeKan:
https://github.com/wekan/wekan/wiki/Python

@Emile840
Copy link
Contributor

@xet7
regarding allowed IP address list for metrics, would you mind if a list of trusted ip adress is setted by using an environment variable instead of changing admin panel and corresponded back-end ?

@xet7
Copy link
Member

xet7 commented Jan 31, 2022

@Emile840

Environment variable usually is less code to add, it's OK.

@xet7 xet7 closed this as completed Nov 21, 2023
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

4 participants