Skip to content

Grafana: track blacklisted domains count

fab edited this page Aug 29, 2023 · 1 revision

To track the total count of blacklisted entries across time using Grafana, you'll need to do the following:

  1. Make sure you have InfluxDB set up as a data source in Grafana.
  2. Modify the script to record counts rather than individual entries.
  3. Set up a Grafana dashboard to visualize the data.

1. Set up InfluxDB as a Data Source in Grafana:

  1. Open Grafana and go to the configuration (gear icon) on the left panel.
  2. Click on "Data Sources" and then "Add data source".
  3. Choose "InfluxDB" from the list.
  4. Fill in the details for your InfluxDB instance, including the URL, authentication token, and organization.
  5. Click "Save & Test".

2. Modify Script to Send Counts:

To record the number of blacklisted entries every hour, modify the send_to_influxdb function in the script:

def send_to_influxdb(domains_count):
    client = InfluxDBClient(url=INFLUXDB_URL, token=INFLUXDB_TOKEN, org=INFLUXDB_ORG)
    write_api = client.write_api(write_options=SYNCHRONOUS)

    point = Point("blacklist_stats").field("count", domains_count)
    write_api.write(INFLUXDB_BUCKET, INFLUXDB_ORG, point)

And update the if __name__ == '__main__': block:

if __name__ == '__main__':
    domains = fetch_blacklisted_domains()
    send_to_influxdb(len(domains))

3. Set Up Grafana Dashboard:

  1. In Grafana, click on the "+" icon on the left panel and choose "Dashboard".
  2. Click "Add New Panel".
  3. Choose the InfluxDB data source you added earlier.
  4. In the query editor:
    • From: "blacklist_stats".
    • Select: field(value) -> "count".
    • Click on "Apply".
  5. Under the "Visualization" tab, you can choose how you want to display the data. A graph or bar gauge would be appropriate for visualizing the count across time.
  6. You can also adjust the time range (for example, Last 7 days) and the refresh interval (every 1 hour) to fit your needs.
  7. Save the dashboard.

Now, every hour, as your script sends the count of blacklisted domains to InfluxDB, Grafana will visualize the changes, giving you an overview of how the blacklist count evolves over time.