Code Monkey home page Code Monkey logo

flask-state's Introduction

Project Logo

Contributor Badge Gitter Badge NPM Badge License Badge Python Badge

Flask-State

English | 简体中文

Flask-State is a lightweight chart plugin for displaying machine state data in your web application.

  • Monitored Metric: CPU, memory, disk usage, disk IO, Network IO, LoadAVG and boot time.
  • Extensible: Offers rich customization options, including redis monitoring, user authentication, custom logging, i18n and etc.
  • Stable: Solves multiprocessing concurrency problems (if you use gunicorn) built on top of lightweight dependencies.

This project is in active development and thoroughly tested to ensure that Flask-State stays up-to-date with its project roadmap.

Screenshot

Documentation

Check out the live demo, or head over to the tutorial for more instructions.

Installation

Get this plugin from PyPI:

pip install Flask-State

Alternatively, install Flask-State via NPM or include this script tag to the head section of your HTML document:

<script src="https://cdn.jsdelivr.net/gh/yoobool/[email protected]/packages/umd/flask-state.min.js"></script>
<link href="https://cdn.jsdelivr.net/gh/yoobool/[email protected]/packages/flask-state.min.css" rel="stylesheet">
npm install flask-state --save

Usage

1. Bind Database Address

from flask_state import DEFAULT_BIND_SQLITE
app.config['SQLALCHEMY_BINDS'] = {DEFAULT_BIND_SQLITE: 'sqlite:///path'}

2. Configure Flask-State

import flask_state
flask_state.init_app(app)

3. Include Imports to Views

// requires echarts module
import 'echarts';
import 'flask-state/flask-state.min.css';
import {init} from 'flask-state';
// Create a DOM node with ID 'test'. After init() binds the node,
// click to open the listening window
init({dom:document.getElementById('test')});

Learn more about advanced configurations in the documentation.

Contributing

See the planning document for a roadmap and existing feature requests.

Flask-State follows the Contributor Covenant Code of Conduct.

Alternatives

Looking for something else? Try another monitor project:

Community Channel

We're on Gitter! Join the conversation for more questions and inquiries about this project.

License

Flask-State is available under the BSD-3-Clause License.

flask-state's People

Contributors

ccapton avatar cclauss avatar fesonx avatar greyli avatar harshcasper avatar hentai-chan avatar pindleskiny avatar wwgc avatar xiaoyuecai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-state's Issues

add network piece

Could you add a network piece. Like "netstat with set or select key word arguments. That tie back to process id too.

This would be helpful, when I'm troubleshooting process that tie back to sockets... And maybe resolve the IP to country of origin.

setup.py include some thing unnecessary

it's common acknowledge that package SHOULD NOT include dir like tests, examples etc.
You supposed to exclude this packages in setup.py.

like

# setup.py
from setuptools import setup, find_packages

about = {}
with open('flask_state/__about__.py') as f:
    exec(f.read(), about)
# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
setup(
    name=about['__title__'],
    version=about['__version__'],
    # Here
    packages=find_packages(exclude=("tests", "examples")),
    install_requires=[
        "Werkzeug>=0.15",
        "Jinja2>=2.10.1",
        "itsdangerous>=0.24",
        "click>=5.1",
        "Flask>=1.0",
        "SQLAlchemy>=1.2",
        "Flask-SQLAlchemy>=1.0"
    ]
)

Using custom exception with app error handler

Flask mentions Implementing API Exceptions in docs, which MAY be better than what we used in current project.

from flask import jsonify

class InvalidUsage(Exception):
    status_code = 400

    def __init__(self, message, status_code=None, payload=None):
        Exception.__init__(self)
        self.message = message
        if status_code is not None:
            self.status_code = status_code
        self.payload = payload

    def to_dict(self):
        rv = dict(self.payload or ())
        rv['message'] = self.message
        return rv

@app.errorhandler(InvalidUsage)
def handle_invalid_usage(error):
    response = jsonify(error.to_dict())
    response.status_code = error.status_code
    return response

@app.route('/foo')
def get_foo():
    """**Just raise and don't need more try-catch code!**"""
    raise InvalidUsage('This view is gone', status_code=410)

Network monitor on web dashboard

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Would be nice to have a network monitor in the dashboard. Something that depicted network information such as packets in/out, data received/sent, etc.

Describe alternatives you've considered
No alternative, but I think it would make a good addition to the dashboard.

Additional context
Might I recommend looking into the Scapy python library. It is a packet manipulation library that allows you to implement packet sniffers and network monitors.

Example needs a separate README

Currently, it is unclear how to use example/, because there's no information available.

Looks like it needs its own guide:

  • How to install all the required dependencies?
  • How to run the project?
  • What should you expect?
  • How to simulate the high-load so I can test that the metrics work?

Memory usage of the application or the code

Real time use of the memory in the code
e.g. if you import NumPy then what's the state of the memory. If you create a variable then how much did the memory increase.
Increase or change in memory usage as per every line that's present in the code would be really helpful for the programmers.

log.exception does not show the full stack trace of the problem

Describe the bug
When I use log.exception, the Flask-State does not log trace as expected.

It just show the error msg like use log.error

To Reproduce
Steps to reproduce the behavior:

  1. Run the examples/app.py without change the example Redis config
  2. Change the services/host_status in line 94 from log.warning(t) to log.exception(t)
  3. When trigger the record events, timeout error will be raised

Expected behavior
log.exception will print full stack trace of the error

Actual behavior
Simply log imeout connecting to server and with confuse code line like the following output:

FLASK_APP = examples/app.py
FLASK_ENV = development
FLASK_DEBUG = 1

flask-state/env/bin/python -m flask run
 * Serving Flask app "examples/app.py" (lazy loading)
 * Environment: development
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
2020-11-22 23:11:20,821 | INFO | manager:record_timer:83 - Acquired file lock successfully. process ID: 29123
 * Debugger is active!
 * Debugger PIN: 161-836-542
127.0.0.1 - - [22/Nov/2020 23:11:41] "GET / HTTP/1.1" 200 -
2020-11-22 23:12:01,012 | ERROR | __init__:exception:1413 - Timeout connecting to server
2020-11-22 23:12:01,025 | INFO | host_status:create_host_status:52 - Insert status

Additional context
Commit ID is 11c2ea4b29c40b3fa10cb85b38986eeca0b93ce3

Labels

I am suggesting you add labels to the X and Y axis, novices should be able to understand what the charts are measuring

Activation of DeepSource

Hi 👋

One of my Pull Requests around fixing Code Quality Issues with DeepSource was merged here: #33

I'd just like to inform you that the issues fixed here were detected by running DeepSource analysis on the repo. If you like, you can activate analysis for your repository to detect such code quality issues/bug risks on the fly for every change made. You can also use the Autofix feature to fix them with one click.

The .deepsource.toml file you merged will only take effect if you activate analysis for this repo.

Here's what you can do if you wish to activate DeepSource to continuously analyze your repository:

  • Sign up on DeepSource and activate analysis for this repository.
  • Create .deepsource.toml configuration which you can use to configure your analysis settings (My PR already added that, but feel free to edit it anytime).
  • Track/Check analysis here.

If you have any doubts or questions, you can check out the docs, or feel free to reach out :)

Consider GPU and maybe some analytics

GPU stats can be included too

Also temperature of CPU and other internal components and the relation between usage and temperature can be interesting stats to look at...

Besides, if you give interesting stats and analytics to your users and work on this area, it can be amazing and it brings a great advantage to your program. It may worth to inspect machine state monitor desktop programs to discover features that would match your project.

Prometheus metrics compatibility

This is more like a question, not actually a feature request.

For me right now it is unclear if I can use this project together with Prometheus stack.
It is the default solution right now for monitoring things.

Looks like it should be possible to use it instead of your own frontend to see the metrics.
Or are there any problems / unknowns?

Change disk usage plot to a pie chart or a disk chart.

Is your feature request related to a problem? Please describe.
Change disk usage plot to a pie chart or a disk chart.

Describe the solution you'd like
The disk usage plot can be changed to a pie chart which will have a better representation.

Support Japanese language

I am using this plugin, but it does not support Japanese. Can this feature be provided in the future?

Temperature, number of users etc as the features

I believe the temperature of the machine will be an interesting feature as the machines overheat when running deep learning models locally.
Boot time, number of threads can be an interesting addition as well.

Chart titles only display "Today" regardless of interval

Describe the bug
Regardless of what interval is set(1,3,7,30), the charts are always titled "Today" in the preview web app.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://flask-state.herokuapp.com/
  2. Click on preview
  3. Select [3, 7, or 30] days for your interval
  4. Notice that the charts still display Today

Expected behavior
I'm guessing this should be dynamic based on the intervals.

Screenshots
Screen Shot 2020-12-22 at 2 48 10 PM

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chome
  • Version: 1.0.5

Additional context
n/a

Typos found by codespell? recive ==> receive

% codespell --quiet-level=2

./packages/cjs/flask-state.js:578: recive ==> receive
./packages/umd/flask-state.js:582: recive ==> receive
./examples/static/initial.js:565: recive ==> receive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.