How to get all IP addresses and their countries connecting to a live streamlit app on AWS-EC2

Please help to to get all IP addresses and their countries connecting to a live streamlit app on AWS-EC2

1 Like

Hi @Dr_Gulshan_Ahuja!

Streamlit doesn’t expose this ability out of the box, but you have a few options (none of which, unfortunately, are trivial):

  • Under the hood, Streamlit uses Tornado to handle all incoming web connections. You could modify the _BrowserWebSocketHandler.open() function, within Server.py, to log all incoming IP addresses. You may want to send them to a metrics provider like Mixpanel or Google Analytics.
    def open(self):
        # self.request.remote_ip contains the IP address of the user connecting
        # to the Streamlit app. You could send this to an analytics platform like MixPanel
        ip = self.request.remote_ip
        self._session = self._server._create_report_session(self)
  • EC2 may provide this logging for you already; it may be worth looking into what your options are there.

  • You could use a reverse proxy like nginx or Apache, and gather logs from there.

If you’re able to wait, the Plugins system being developed for Streamlit right now will enable you to more easily integrate third-party analytics into your Streamlit app.

3 Likes

I’d love the idea of plugins, I am sure in no time we will have plugins to easily just add a small Google analytics code to track visitors etc.

2 Likes