我将设备监视脚本作为应该永远运行的后台进程运行。但是,该过程在24小时后因错误而被终止。
XIO: fatal IO error 25 (Inappropriate ioctl for device) on X server "localhost:10.0"^M
257706 after 507 requests (507 known processed) with 5 events remaining.^M
257707 0.4.38,23): recv 'x01159454 r28
我正在使用matplotlib绘制图形,这是我第一次使用此lib。
由于错误表示X服务器问题,因此我认为它与matplot lib有关,因为它是纯telnet脚本,因此脚本中任何地方都没有X服务器的作用
即使使用matplot lib,我的目标也是将图形另存为png图像。
以下是我的matplot lib代码,请查看是否有明显错误。
15 plt.ioff()
16
17 def plot_cpu_utilization_graphs(df):
18 plt.clf()
19 column_name = 'CPU'
20 #df = df[[column_name, 'timestamp', 'ip']]
21 max_value = df[column_name].max()
22 if max_value < 100:
23 max_value = 100
24 min_value = df[column_name].min()
25 if min_value > 0:
26 min_value = 0
27 start_idx = df['timestamp'].iloc[0]
28 end_idx = df['timestamp'].iloc[-1]
29 time_series = pandas.DatetimeIndex(freq='20T', start=start_idx, end=end_idx)
30 y_axes_series = range(int(min_value), int(max_value), 10)
31 #ax = df.groupby('ip').plot(x='timestamp', y='CPU')
32 fig, ax = plt.subplots()
33 labels = []
34 for key, grp in df.groupby(['ip']):
35 ax = grp.plot(x='timestamp', y='CPU', ax=ax )
36 labels.append(key)
37 lines, _ = ax.get_legend_handles_labels()
38 lgd = ax.legend(lines, labels, loc='upper center', bbox_to_anchor=(-.25, 1))
39 ax.set_ylabel("CPU")
40 ax.set_xlabel("Time")
41 ax.set_ylim(min_value, max_value)
42 #ax.set_xlim(time_series[0], time_series[-1])
43 plt.title("CPU STATS")
44 fig.savefig('CPUStats', bbox_extra_artists=(lgd,), bbox_inches='tight')
74 def reboot_count(df):
75 plt.clf()
76 plt.cla()
77 sf = df[df.Rebooted][['ip', 'Rebooted']].groupby(['ip', 'Rebooted']).agg(len)
78 if not sf.empty:
79 new_df = pandas.DataFrame({"ip":sf.index.levels[0], "Reboot Count":sf.values})
80 p = new_df.plot(kind='bar', x='ip', y='Reboot Count', color='grey')
81
82 ax = p.axes
83 for tick in ax.get_xticklabels():
84 tick.set_rotation(15)
85 ax.set_ylabel("Reboot Count")
86 ax.set_xlabel("IP")
87 #ax.legend().remove()
88 plt.title(" REBOOT COUNTS")
89 plt.savefig('Reboot Counts')
90 else:
91 print "No Data Present for Graphs"
参考方案
我有同样的错误。该错误是由于matplotlib
正在使用的后端引起的(您正在以非交互方式运行它)
尝试
import matplotlib
matplotlib.use('Agg')
见https://matplotlib.org/faq/howto_faq.html
Python sqlite3数据库已锁定 - python我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…
如何传播一个Python数组 - pythonThis question already has answers here: How do I concatenate two lists in Python? (28个答案) 2年前关闭。 在JS我可以做到这一点const a = [1,2,3,4] const b = [10, ...a] console.log(b) // [10,1,2,3,4] …
Python:传递记录器是个好主意吗? - python我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…
Python-Excel导出 - python我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…
Python pytz时区函数返回的时区为9分钟 - python由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…