Performance monitoring ideas?

Hey david! Welcome to the community !

I was going through the same problem a couple of weeks ago.
Apparently streamlit uses prometheus_client to export metrics at /metrics if you set --global.metrics=true with streamlit run like

streamlit run --global.metrics=true my_lit_app.py

you can create a init method for your prometheus metrics eg. Gauges, Summaries etc. and then use them across your application. Just make sure that you don’t create the metrics in the main file else you will keep getting Duplicate Timeseries errors. Then you can scrape the metrics using prometheus and store it in influx or the TSDB of your choice.

I visualize the metrics on grafana, you can use prometheus dashboard or something equivalent.

EDIT: Adding example,

# put this in a module like utils.py ?
class REGISTRY:
    inited = False
    @classmethod
    def get_metrics(cls):
        if cls.inited:
            return cls
        else:
            # Register your metrics here
            cls.REQUEST_TIME = Summary('some_summary', 'Time spent in processing request')
            cls.inited = True
# main script
from utils import REGISTRY

METRICS = REGISTRY.get_metrics()

@METRICS.REQUEST_TIME.time()
def i_sleep():
    sleep(1.0)

st.write("something")
i_sleep()

Load /metrics and look for some_summary_…

PS. managers love those graphs :smiley: Hope it helps ! :slight_smile:

2 Likes