Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Element to display host system resource utilization in python

Shulou Source: shulou.com Published: 2022-06-02 10:39:26 09月16日 Update

It is believed that many inexperienced people have no idea about how to use Element to display the utilization rate of host system resources in python. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. Front-end HTML and CSS select hosts: two。 Front-end JS new Vue ({el:'# app', data: {searchHost:'', HostData: []}, mounted () {/ / page load and get all templates this.init () }, methods: {init () {axios.get (site_url + "get_monitored_host/") .then (res = > {if (res.data.result) {this.HostData = res.data.data) } else {this.$message.error ('failed to acquire business');}}, 'json') }, changeHost () {axios.post (site_url + "get_host_load_data/", {"Competition": this.searchHost}) .then (res = > {if (res.data.result) {this.chartBar = echarts.init (document.getElementById ('load') This.chartBar.setOption ({title: {text: 'host MEM,DOSK,CPU utilization graph'} Tooltip: {trigger: 'axis'}, legend: {data:res.data.data.data1} Grid: {left:'3% floor, right:'4% floor, bottom:'3% floor, containLabel: true} Toolbox: {feature: {saveAsImage: {} XAxis: {type: 'category', boundaryGap: false, data: res.data.data.data2} YAxis: {type: 'value'}, series: res.data.data.data3})} else {this.$message.error (' update host MEM DOSK,CPU usage failed') }, 'json');}) 3.Django code

Urls.py file content

From django.conf.urls import patternsfrom home_application.host import views as host_viewurlpatterns = patterns ('home_application.views', (r' ^ status/$', host_view.status), (r'^ get _ monitored_host/$', host_view.get_monitored_host), (r'^ get _ host_load_data/$', host_view.get_host_load_data),...)

Contents of host\ views.py file

Import jsonimport randomfrom home_application.models import Host, LoadDatafrom home_application.utils.parse_time import get_range_date_listdef status (request): return render_mako_context (request, "/ home_application/status.html") def get_monitored_host (request): host_query = Host.objects.filter (is_monitored=True) res_data = [i.to_dict () for i in host_query] return JsonResponse ({"result": True "data": res_data}) def get_host_load_data (request): # data = json.loads (request.body) # Competition = data.get ("competition") # load_query = LoadData.objects.filter (host_id=pk). Order_by ("create_time") # res_data = [i.to_dict () for i in load_query] res_data = {"data1": ['cpu',' disk', 'mem'] "data2": get_range_date_list, "data3": [{"name": 'cpu', "type":' line', "stack": 'usage', "data": [random.randint (1,100) for i in range (100)]} {"name": 'disk', "type":' line', "stack": 'usage', "data": [random.randint (1,100) for i in range (100)]}, {"name": 'mem' "type": 'line', "stack":' usage', "data": [random.randint (1,100) for i in range (100)]} return JsonResponse ({"result": True, "data": res_data})

Models.py file content

From django.db import modelsfrom home_application.utils.parse_time import parse_datetime_to_timestrclass LoadData (models.Model): host_id = models.IntegerField (u "host ID", default=0) cpu = models.IntegerField (u "CPU usage", default=0) mem = models.IntegerField (u "memory usage", default=0) disk = models.IntegerField (u "hard disk utilization", default=0) create_time = models.DateTimeField (u "creation time" Auto_now_add=True) def to_dict (self): return {"host_id": self.host_id, "cpu": self.cpu, "mem": self.mem, "disk": self.disk, "create_time": parse_datetime_to_timestr (self.create_time)}

Realize the effect

After reading the above, have you mastered the method of how to use Element to display the host system resource utilization in python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Usage host content file system resource front end method more problem helpless to this end business code memory reason to this skill effect time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology macOS MariaDB Huawei