how to read the log file generated by alertmanager

86 views
Skip to first unread message

Adarsh Kumar Pandey

unread,
Apr 6, 2020, 2:50:16 AM4/6/20
to Prometheus Users
I saw that alertmanager generates a nflog file ..I was wondering how that works and can i get all the alerts fired from that log file?

Adarsh Kumar Pandey

unread,
Apr 6, 2020, 3:30:23 AM4/6/20
to Prometheus Users
Does prometheus (not the alertmanager log)stores the alerts generated somewhere and where to find it...?
Thanks for any suggestion and insights...I really appreciate the community efforts.

Adarsh Kumar Pandey

unread,
Apr 7, 2020, 11:57:13 AM4/7/20
to Prometheus Users
I can see that this is a issue that we all are facing.. I have developed a code that needs improvement to  write it to a database like postgresql.. right now it just takes the alerts and dumps the json in a file alerts.json
Feel free to get creative with the code and if you could solve this issue then you have just helped a lot of users and a ton of thanks to you for that !!!

On Monday, 6 April 2020 12:20:16 UTC+5:30, Adarsh Kumar Pandey wrote:

Adarsh Kumar Pandey

unread,
Apr 7, 2020, 11:59:10 AM4/7/20
to Prometheus Users
The code is a python flask app:
import json
from flask import request
from flask import Flask, redirect
app
=Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
   
if request.method == 'POST':
        data
=request.get_json()
       
print(data)
       
with open('yourpath/alerts.json','a') as f:
            json
.dump(data,f)
       
return redirect('/')
   
else:
       
return "nothing"
if __name__=='__main__':
    app
.run()




On Monday, 6 April 2020 12:20:16 UTC+5:30, Adarsh Kumar Pandey wrote:

Matthias Rampke

unread,
Apr 7, 2020, 12:02:20 PM4/7/20
to Adarsh Kumar Pandey, Prometheus Users
I don't think looking at alertmanager's internal storage is a good solution. The formats there may change at any time.

Instead, add a webhook receiver into your alert routing tree – if you add it at the beginning and with continue: true, you will get a copy of every notification as a webhook. Then you can do whatever you want with it, including putting it into your database.

/MR

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/3b6a09d1-cb4b-490a-a16a-65ed9207b18d%40googlegroups.com.

Adarsh Kumar Pandey

unread,
Apr 7, 2020, 12:59:40 PM4/7/20
to Prometheus Users
Yeah after this much only I was not able to implement the database saving function so I was wondering if someone has any codes or suggestions for that.

Alexander Golikov

unread,
Apr 9, 2020, 3:14:36 PM4/9/20
to Prometheus Users
Hello,
Prometheus stores all its alerts.
Query is ALERTS.
Or
count (ALERTS{alertstate="firing"}>0) by (intance, alername,severity)

Very nice view in Grafana Graph Visualisation.

Reply all
Reply to author
Forward
0 new messages