How to display the number of users visiting a Superset dashboard within a time interval on Prometheus?

1.6k views Asked by At

I want to monitor Superset dashboards and have planned to use my own custom Python exporter along with Prometheus. I am setting a gauge to value 1 every time a dashboard is logged to be visited by some user. My target plot is: y-axis as count of visits, x-axis as time and dashboard_id as the plot.

My Python exporter is as follows:

class DashboardMonitor:

    def __init__(self):
        self.dashboard_gaguge_map = defaultdict(Gauge)

    def create_dashboard_gauges(self, dashboards_list):
        for dashboard_id, dashboard_name in dashboards_list.items():
            gauge_name = 'dashboard_{}_gauge'.format(dashboard_id)
            gauge_description = dashboard_name
            dashboard_gauge = Gauge(gauge_name, gauge_description)
            self.dashboard_gaguge_map[dashboard_id] = dashboard_gauge

    def get_dashboard_gauge(self, dashboard_id):
        return self.dashboard_gaguge_map.get(dashboard_id, None)

    def set_dashboard_gauge(self, dashboard_id):
        dashboard_gauge = self.get_dashboard_gauge(dashboard_id)
        dashboard_gauge.set(1)

My current query on Prometheus is: sum(rate(dashboard_1_gauge[1m])) * 60 that plots the following: enter image description here

I am not confident whether the plot displays what I want it to be or whether the method of setting the gauge as 1 every time I encounter that dashboard in the logs is the optimal way to do this.

How do I do this?

1

There are 1 answers

6
sskrlj On BEST ANSWER

As stated in https://prometheus.io/docs/prometheus/latest/querying/functions/#rate, rate should only be used with counters, not gauges.

I'd change this metric into a counter and then use sum(rate(dashboard_1_counter[1m])) to chart the use rate in accesses per second or sum(increase(dashboard_1_counter[1m])) if you want to get a count of accesses in each time bucket, like 1m in this case.