Streamlit app view and statistics

Hey @shyamcody Welcome to the community !

Its not available out of the box but streamlit does use prometheus_client at /metrics endpoint to export some of the metrics. check this answer, Performance monitoring ideas?

You can utilize it using a little bit of code to count views by setting up a Counter collector for unique session_ids. I have added this functionality in my update to the state.py that I use for my streamlit apps.

Just copy the module from this gist, https://gist.github.com/ash2shukla/ff180d7fbe8ec3a0240f19f4452acde7

And import count_sessions and call the function at the top of your script, you will be able to see

TYPE session_count_total counter
session_count_total 5.0

at /metrics endpoint. If you want to add a dashboard then you can look into Grafana, prometheus combination of things.

This piece of code,

import streamlit as st
from state import count_sessions

count_sessions()

st.write("test")

Will give you this,

Hope it helps ! :slight_smile:

Beside this there’s already an issue opened,

PS. you can add anything you want to collectors then eg. times refreshed, function run summaries etc. :smiley:

6 Likes