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

Add auto detection of miner model #67

Closed sergioclemente closed 6 years ago

sergioclemente commented 6 years ago

Title says all.

anselal commented 6 years ago

Hi,

looks a lot like my implementation. The main difference is that I added this piece of code together with an auto-discovery feature. I created a form that gives the user the opportunity to scan an IP range for miners and adds the found miners after a model autodetection

anselal commented 6 years ago

My code looks like this:

@app.route('/add', methods=['POST'])
def add_miner():
    miner_ip = request.form['ip']
    miner_model_id = request.form.get('model_id')
    miner_remarks = request.form['remarks']

    # exists = Miner.query.filter_by(ip="").first()
    # if exists:
    #    return "IP Address already added"

    add_miner(miner_ip, miner_model_id, miner_remarks)

    return redirect(url_for('miners'))

def add_miner(miner_ip, miner_model_id, miner_remarks):
    try:
        miner = Miner(ip=miner_ip, model_id=miner_model_id, remarks=miner_remarks)
        db.session.add(miner)
        db.session.commit()
        flash("Miner with IP Address {} added successfully".format(miner.ip), "success")
    except IntegrityError as e:
        db.session.rollback()
        flash("IP Address {} already added".format(miner_ip), "error")

@app.route('/batch/add/<string:subnet>/<int:start_ip>/<int:end_ip>')
def batch_add(subnet, start_ip, end_ip):
    #subnet = '192.168.1'
    #start_ip = 102
    #end_ip = 110

    miners = {}
    subnet = subnet + "."

    while start_ip <= end_ip:
        ip = subnet + str(start_ip)
        miner_stats = get_stats(ip)
        print("Quering IP %s" % ip)
        if miner_stats['STATUS'][0]['STATUS'] == 'error':
            print("Error adding IP %s" % ip)
            start_ip += 1
            continue
        miner_type = miner_stats['STATS'][0]['Type'].split(' ')[1]
        miners.update({ip: {"miner_type": miner_type}})
        print("Added IP %s, type %s" % (ip, miner_type))
        model = MinerModel.query.filter_by(model=miner_type).first()
        add_miner(ip, model.id, "")

        start_ip += 1

    return redirect(url_for('miners'))
sergioclemente commented 6 years ago

Can you call my code from your new code? It would make integration easier plus other folks can use as we don't know when you are going to submit this changes.

sergioclemente commented 6 years ago

PS. Integration would be easier because my code already supports avalon

anselal commented 6 years ago

Can you call my code from your new code? It would make integration easier plus other folks can use as we don't know when you are going to submit this changes.

Don't have quite the time to test it right now

shotaatosh commented 6 years ago

Auto detect would be great but I think choosing beforehand what miners must be added will be more useful, I mean if I have to add 40 D3s instead of auto detection it would be easier to just tick a 'D3' and start adding

anselal commented 6 years ago

@shotaatosh This is way more easier to implement

anselal commented 6 years ago

I see you added a CachedHttpRequest and a profits page. Nice work. How exactly does the CachedHttpRequest work and what does it cache ?

sergioclemente commented 6 years ago

Because I make some http requests to get BTC/LTC/etc price I cache them so that for many models the page loading time gets faster.

anselal commented 6 years ago

Oh man, a lot of merge conflicts . Anyways, this is what I got so far

anselal commented 6 years ago

I have inform you that I finished with refactoring the app into blueprints but i won't push the changes yet because i want to close some issues before the next release. Also I will have to update the README because I changed the way yo start the app. Basically instead of python manager.py runserver you start it with python manager.py run but this is only a development server. The best solution is to start the app with gunicorn. With gunicorn I updated the logging mechanism, now everything is logged using gunicorn but there are some tweaks I wanna do. I will try to document all the changes I made and want to do in an issue so we can discus them all and build a good structure.

sergioclemente commented 6 years ago

Sounds good thanks for the update. Looking forward for your changes.

Some notes:

I think I can close this based on your last comment.

anselal commented 6 years ago

I also opened two other issues #80 and #81 and locked them so only we two can write.