In Graylog, if you want to find all possible pod hostnames (sources) for logs coming from a given Kubernetes namespace, but you don't know all the pod names upfront, you can do this efficiently by leveraging Graylog's field aggregation and search capabilities rather than scanning all messages manually.
Key points:
- You know the namespace (e.g.,
k8s_namespace or a similar field).
- The pod hostname is stored in the
source field.
- You want to find all distinct
source values for that namespace.
Step-by-step approach:
1. Filter by namespace
First, filter logs by the namespace field. For example, if your namespace field is called k8s_namespace:
k8s_namespace:your-namespace
This limits the search to logs from that namespace.
2. Use the "Field Values" or "Field Aggregation" feature
Graylog provides a way to see all distinct values of a field for the current search filter:
- After applying the namespace filter, go to the "Fields" sidebar on the search page.
- Find the
source field (or whatever field contains the pod hostname).
- Click on the field name or the small arrow next to it.
- Graylog will show you the top values for that field within the current search results, including counts.
This gives you a list of all pod hostnames (source values) that have logged messages in that namespace.
3. (Optional) Use a quick aggregation search
If you want a more programmatic or saved search approach:
- Use the Aggregation feature in Graylog (if available in your version).
- Create a new aggregation search:
- Filter:
k8s_namespace:your-namespace
- Group by:
source
- Metrics: count (to see how many messages per pod)
- Run the aggregation to get a list of all pod hostnames with message counts.
Summary
Query example:
k8s_namespace:your-namespace
Then check the top values of the source field in the search UI.
Additional tips
- If your logs have a different field for pod name (e.g.,
kubernetes.pod_name), you can do the same for that field.
- You can export the list of sources if needed.
- If you want to automate this, use the Graylog API to query distinct field values with a filter.
If you want, I can help you with exact API calls or UI navigation based on your Graylog version!