anselal / antminer-monitor

Cryptocurrency ASIC mining hardware monitor using a simple web interface
GNU General Public License v3.0
228 stars 145 forks source link

Email notifications #19

Open babycicak opened 7 years ago

babycicak commented 7 years ago

Maybe in future, can add in the Selected Error type and allow send notify via Email in set timer. Will be good, no need to login system to check everytime ;)

anselal commented 7 years ago

Nice idea @babycicak. We have to consider some things here. If you select to get email notifications lets say if a chip gets damaged in one of your miner, you will get this email forever until you replace the board. Replacing the board for only one chip is not very profitable because 1) you will lose money while mining with minus one board 2) you will have to pay for shipping costs back and forth. Do you agree ??? What kind of errors do you suggest to add in the email notification ?

nullwriter commented 7 years ago

@anselal what about temperature warning notification?

anselal commented 7 years ago

@nullwriter At which temperature should you get notified ? At the moment I display a warning when a miner reaches a temperature of 80 degrees. Do you think I shall increase this limit in the email notification ? The limit will be global for all miners or we can add a temperature limit per miner model.

nullwriter commented 7 years ago

If I'm not mistaken, I think all models (S7, S9, T9, L3+ and D3) have the same build (3 boards, same fan speeds, etc), so it must be reasonable to say they should all be on the same range of temperatures. So I see it as leaving the option to the user to set it. So I could set a global temperature limit of, say, 80 degrees. So if any of my miners reach this, I'd get a notification with the miners details (name etc) that it has reach/passed this temperature.

Theres of course the other way of setting a limit for each miner, but I think it wouldn't make much sense to have different temperature limits, as technically they are all in danger at the same level of degrees.

anselal commented 7 years ago

Not all miners have the same board numbers and same number of chips per board. The L3+ has 4 boards and all the other you mentioned (S7,S9,D3) have 3 boards. I am not sure about the T9 although I think it has 3 boards since it is a slower version of hte S9. The L3+ and S7 operate at almost the same temperature at about 55 degrees whereas the S9 operate at much higher temperatures at about 70 degrees. The overclocked D3s operate at about 80 but I've seen D3s reach up to 95-100 degrees. So I think it is safe to implement a per model limit.

nullwriter commented 7 years ago

@anselal Sweet, I didn't know about the L3+, but then as you say it should be per model then. Also, the T9 has a few chips less per board than the S9, but still has the same danger limit. Although, thanks to a better design in the board, it does operate cooler than an S9.

InTheta commented 6 years ago

s9 will run at 99 forever D3 85

These are my temperature alert temps.

(Polymer_City)

anselal commented 6 years ago

It doesn't mean they should run at those temps. Maybe the user should set the allowed temp for ecery miner.

InTheta commented 6 years ago

I'm just saying those are my upper limit temps. Once they get to that temp they start to down clock themselves to get a better temp. My S9 runs super hot, so it always runs at 97, even when it gets down locked to 300 @ 6.6 ths

gnanet commented 6 years ago

I also support the idea to allow the user to set the temperature notification level for every miner, with defaulting to a per-model limit, which is maybe already defined in the spec-sheet of the manufacturer (at least i hope, bitmain is defining one in their specifications)

I operated at least 2 server-rooms, and had access to high-profile co-location sites (for example Dataplex, and T-Systems in Hungary), and i can tell you, that the devices "alert limit" is no ways the desired operation temperature, and down-clocking a miner is only a small prevention against total hardware failure, but reduces the effectivity for finding valuable hashes.

If you are working with more miners, proper cooling is a must, where you also have to consider the air-flow, to ensure only cool air is entering the miner and the heated air that leaves the miner does not recirculate into other miners.

Also i am currently working on a high density site, slowly leaving the 2digit amount of miners, and air-conditioning (including humidity control, and air-filtering) was a key part of the server-rooms design.

A good reading is already published in 2005 about Recommended Data Center Temperature & Humidity

anselal commented 6 years ago

@ColossusFX what do you mean by "they start to down clock themselves to get a better temp". Are the antminers down-clocking them-self to prevent hight temperatures ? I hear this for the first time.

@gnanet Bitmain has indeed a specification sheet in which they mention, per model, the highest temperature the miner can operate but those limits are very high and I am not risking apply those temps for the notification system.

You can check the specification for some models at https://support.bitmain.com/hc/article_attachments/115003500154/TIM__20171019172342.png

anselal commented 6 years ago

About the specifications, I had a long conversation via email with a user who claimed that the "Stop Working Temp" applies to the board temp and not the chip temp. He also claimed that he tested his theory and that the D3 continued to operate after the chip temperature reached ~90 degrees.

The temp of the board is always higher than the chip temp. That means that if the board temp reaches 85 degrees the chip temp will be about 100 ??? That is a very high limit I guess.

gnanet commented 6 years ago

I agree that their stop-working temp shall be not the default notification limit.

but maybe a 20-30 percent lower value ?

InTheta commented 6 years ago

@anselal

I spoke to you on BTC forum. I’m just giving you some ideas as I have already built what you are doing.

pedrosimao commented 6 years ago

@ColossusFX are you willing to share your code? I could contribute to it.

anselal commented 6 years ago

@pedrosimao he was not willing to share his code, although he copied my opensource code. This is against the Open Source License.

InTheta commented 6 years ago

@anselal - I did not copy your open source code, I used the following which is available on other sites.. .Replace("}{", "},{");

I cannot share code presently as its only a beta version, and I need to re-write the whole thing in MVVM. Also I have a major issue with async SSH command, its taking too long to write config files.

I will upload a compiled version soon though.

anselal commented 6 years ago

@ColossusFX Point me to a site where you saw this piece of code. If I remember correctly you asked me about this line of code on bitcointalk. I myself didn't found it anywhere and had to come up with the solution. The only error this line solves is if you call cgminer's stats property.

Anyways..

InTheta commented 6 years ago

@anselal I cannot give away 4 months of work at the moment for a project which is only being used by myself.. I did say I would help with yours... I don't want to get in a petty argument.. I was only here to help with yours and give some ideas. My project is HUGE, and its no way near finished, its just working for what I need right now. I am still happy to help / give input to your project.

anselal commented 6 years ago

@ColossusFX I don't wanna argue either. Your help is welcome.

pedrosimao commented 6 years ago

Anyway, a simple alert by e-mail when miner becomes inactive would be fine. This should be quite easy to implement.

pedrosimao commented 6 years ago

Ok, I have done it myself. Now I have SMS (via Tropo API) and Email Alerts (via Gmail SMTP). Here is what I did:

1 - Created a file called "alerts.py" inside "views" folder

import smtplib
import requests

####
# Set Personal Details
####
TROPO_TOKEN = 'tropTokenHere'
MOBILE_PHONE = '+11111122233' 
MAIL_LOGIN = "originMail@gmail.com"
MAIL_PASS = "smtpPasswordHere"
MAIL_DESTIN = "destinationMail@gmail.com"

####
# Alert for Antminer Events
####
def sendAlert(myMessage):
    sms_url = 'https://api.tropo.com/1.0/sessions?action=create&token=' + TROPO_TOKEN + '&cNumber=' + MOBILE_PHONE + '&cAnswer=' + myMessage
    r = requests.get(sms_url)
    print("SMS Alert sent!" )
    #Send the mail
    server = smtplib.SMTP('smtp.gmail.com',587)
    server.starttls()
    server.login(MAIL_LOGIN, MAIL_PASS)
    SUBJECT = "ANTMINER MONITOR ALERT!"
    TEXT = myMessage
    msg = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT) # The /n separates the message from the headers
    server.sendmail(MAIL_LOGIN, MAIL_DESTIN, msg)
    server.quit()
    print("E-mail Alert sent!" )
    return True

Then on "antminer.py" import this "from . import alerts". Than add alerts.sendAlert(error_message) in lines 102, 113 and 120. I can also share my Tropo Api Script with you if you want to use SMS.

Should I commit those changes to the project?

gnanet commented 6 years ago

I have tried the latest release, but as i understand the functionality, the checks are only carried out if the web-page is open in some browser window. This way if you are simply running the app, but do not have a computer running with a browser open 24x7, you have still no email alerts.

The desired alerting solution would require you to develop a background process that regularly wakes up to carry out the checks, and then would trigger an alert if the conditions are met.

Edit: i have tried the latest release, and i am sure the checks are only running on a browser call, and need the website to be open to run on a regular basis

pedrosimao commented 6 years ago

If you don't want to let your browser open, and want to leave something running on the background you could simply run this command: watch -n 30 wget --spider 0.0.0.0:5000

This will check your Flask page every 30 seconds. Don't forget to install watch and wget. That's the easiest way. I could also change the Python code to check every X seconds for alerts.

gnanet commented 6 years ago

I am by far not a python expert / programmer, so i dont know if it is difficult to write the

Python code to check every X seconds

But i think that solution would keep antminer-monitor still mostly platform independent (i think it can run currently on windows, mac, linux, if the required python and the libs are installed)

but your simple solution was so simple i wonder why i did not think on it ;)

anselal commented 6 years ago

@gnanet You are right, at the moment all the checks are performed on every page refresh. My software isn't build on top of some API yet. The email notification system should run on it's own thread and check for instabilities, independent of the refresh rate of the app. The keyword here is service.

@pedrosimao As I want to keep the app platform independent I am looking for native python solutions and not some command line commands. Thanks though for pointing us in a direction. I have the code for the email service already written but I want to do some checks before I release it.

mikespax commented 6 years ago

@pedrosimao Could you add a bit more detail to those last few lines on your email notifications instructions? I'm not a code guy and I'm having trouble understanding exactly what was meant by:

Then on "antminer.py" import this "from . import alerts".

pedrosimao commented 6 years ago

@mikespax just add this line to the top of antminer.py file: from . import alerts

mikespax commented 6 years ago

ah yes, I tried that firstly. what would I do about this? @pedrosimao

ImportError: No module named requests

mikespax commented 6 years ago

May have answered my own question, will try in a second.

https://stackoverflow.com/questions/17309288/importerror-no-module-named-requests

mikespax commented 6 years ago

IT WORKS! WOOHOO. @pedrosimao

mikespax commented 6 years ago

I also added an email alert for a miner going offline.

if miner_stats['STATUS'][0]['STATUS'] == 'error': errors = True error_message = "[WARNING] Miner is offline '{}'.".format(miner.ip) inactive_miners.append(miner) alerts.sendAlert(error_message)

mikespax commented 6 years ago

@pedrosimao do you have a recommendation for a throwaway email account provider to use for this sending out the emails? I have a not so important secondary gmail account I've decided to use, but would prefer to created a dedicated not very important email to use for this purpose and this purpose only.

pedrosimao commented 6 years ago

I am glad it worked. Coding is fun, right? Maybe you should learn more. I just use a gmail account. I don't see a good reason to use a dedicated email account. I unhappily don't know much about e-mail providers. What I could help you with, is creating a script on Tropo, that will send out SMS alerts using the same code I shared.

mikespax commented 6 years ago

Yeah! It wasn't that bad at all. I was just worried about leaving my password plaintext on a machine. Don't need SMS alerts really with email being possible (and free!).

On Mon, Dec 18, 2017 at 8:36 AM, Pedro Simão notifications@github.com wrote:

I am glad it worked. Coding is fun, right? Maybe you should learn more. I just use a gmail account. I don't see a good reason to use a dedicated email account. I unhappily don't know much about e-mail providers. What I could help you with, is creating a script on Tropo, that will send out SMS alerts using the same code I shared.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/anselal/antminer-monitor/issues/19#issuecomment-352347306, or mute the thread https://github.com/notifications/unsubscribe-auth/AOTNFl41ST94GWtZ7rCN9mxmSPWaGNyrks5tBhXngaJpZM4QMcPb .

-- Michael Sparks (US) +1.850.396.2648 (HU) +36.30.350.1362

pedrosimao commented 6 years ago

Well... SMS on Tropo is free for developers. And I understand your security concern. Creating another Gmail account is the easy way to go.

anselal commented 6 years ago

What is a good time interval for the email notification service ? Do you think it should check on every page refresh or shall it run on its own thread, that means independently on the page refresh ?

pedrosimao commented 6 years ago

We could actually have a separate setting only for that. Each different user would prefer a certain time interval...

mikespax commented 6 years ago

I for one would like to know immediately if my house is on fire. I see no reason to go longer than the current refresh interval for emails.

If the issue is about sending too many emails within a short period of time, create a check that ensures not to repeat the same alert within a 4?(user configurable?) hour period. Probably one email is enough.

On Mon, Dec 18, 2017 at 10:21 AM, Pedro Simão notifications@github.com wrote:

We could actually have a separate setting only for that. Each different user would prefer a certain time interval...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/anselal/antminer-monitor/issues/19#issuecomment-352369757, or mute the thread https://github.com/notifications/unsubscribe-auth/AOTNFrgGmG7sUEDoSs4ltPAVwJyApUzVks5tBi6zgaJpZM4QMcPb .

-- Michael Sparks (US) +1.850.396.2648 (HU) +36.30.350.1362

pedrosimao commented 6 years ago

Or just create an "alertState" boolean variable. If Antminers have a problem, we set the variable alertState to True, in that case we wouldn't send alert again till alertState is set to False. Which means, one of the conditions of sending alerts would be having alertState==False This would avoid repetitive e-mail for the same alert...

anselal commented 6 years ago

@pedrosimao This is not a good idea at all. What if you turn notifications off and something happens... you won't be informed

anselal commented 6 years ago

@pedrosimao Your code looks a lot like mine, I use smtplib too, but I have structured it a bit different. Good job by the way.

@mikespax Just create a dedicated gmail account for monitoring your miners, so you don't worry about your password. This is what I have done.

Another idea. I can create a gmail account and hardcore it to the app. All users can receive notifications from this email address. They only would have to provide the recipient email address.

ThinkCode commented 6 years ago

I want to know the temperatures every 3 hours or so when I am away till I am comfortable with the error alerts when ever they happen with a bool flag as suggested.

I will add the email code and deploy it on a Raspberry PI. SMS alerts only for set thresholds.

Thanks @anselal and @pedrosimao, you guys saved me an entire weekend! Donations once I mint some bitcoin, just started!

3ricj commented 6 years ago

A general comment on monitoring -- it would be lovely if this could operate like a pluggin to nagios or some other monitoring system.

anselal commented 6 years ago

@3ricj what do you mean exactly ?

Demitrius commented 6 years ago

Guys, does Error via Email feature works from the box? Have you plans to release this?

anselal commented 6 years ago

@Demitrius Thank you for using AntminerMonitor. We are doing our best to implement all the requested features. We plan to release this feature in the near future.

shotaatosh commented 6 years ago

before error via email function will be implemented imo it is more important to choose what errors to get

Demitrius commented 6 years ago

Agree. It must have configurable thresholds.

alaaelmahdy commented 6 years ago

Thank you @pedrosimao for the solution, did you find out how to send only one mail ,i actually tried the Boolean attribute with a big failure.