openwisp / openwisp-monitoring

Network monitoring system written in Python and Django, designed to be extensible, programmable, scalable and easy to use by end users: once the system is configured, monitoring checks, alerts and metric collection happens automatically.
https://openwisp.io/docs/dev/monitoring/
Other
163 stars 110 forks source link

Create a new chart for existing metric #573

Open mips171 opened 4 months ago

mips171 commented 4 months ago

I want to add a new chart of the number of neighbours for a device. Is the proper way to do that to simply add this to settings.py? Just asking because I'm unsure about the influxdb key and also I want to add it to the existing charts, not replace the defaults.

from openwisp_monitoring.monitoring.configuration import register_chart

neighbors_chart = {
'neighbors': {
        'type': 'line',
        'title': _('Neighbors count'),
        'description': _('Number of IP neighbors detected'),
        'unit': 'devices',
        'order': 900,
        'query': {
            'influxdb': (
                "SELECT COUNT(neighbors) FROM {key} WHERE time >= '{time}' AND "
                "content_type = '{content_type}' AND object_id = '{object_id}' "
                "GROUP BY time(1d)"
            ),
        },
    }
}
register_chart('neighbors_chart', neighbors_chart)
nemesifier commented 4 months ago

@mips171 register_chart is meant to be used when building custom django apps.

There's also a setting for adding new chart configurations: OPENWISP_MONITORING_CHARTS.

I don't remember we store neighbors in their own "table" (technically in influxdb that's called measurements), so I am not sure neighbors can be queried like that.