linux - GNUPLOT 一个月中的非法日期

标签 linux time format gnuplot cpu

我正在尝试根据我的 stat.dat 文件制作图表,其中包含:

----system---- ----total-cpu-usage---- ------memory-usage----- -net/total-
     time     |usr sys idl wai hiq siq| used  buff  cach  free| recv  send
22-04 16:44:48|  0   0 100   0   0   0| 162M 57.1M  360M 3376M|   0     0
22-04 16:44:58|  0   0 100   0   0   0| 161M 57.1M  360M 3377M| 180B  317B

我有一个 gnu.sh 包含:

#!/usr/bin/gnuplot
set terminal png
set output "top.png"
set title "CPU usage"
set xlabel "time"
set ylabel "percentage"
set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
plot "stat.dat"  using 1:3 title "system" with lines, \
"stat.dat" using 1:2 title "user" with lines, \
"stat.dat" using 1:4 title "idle" with lines

当我运行 gnu 文件时,我收到此错误:

Could not find/open font when opening font "/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf", using internal non-scalable font
----system---- ----total-cpu-usage---- ------memory-usage----- -net/total...
stat.dat:1:"./gnu.sh", line 12: illegal day of month

是否有人熟悉此错误以及有帮助的解决方案?

最佳答案

在解析数据文件的第一行时,gnuplot 遇到了非法的月份。

在解析数据文件之前,您必须以某种方式跳过数据文件的前两行。使用版本 5.0 或 4.6.6,您可以使用新的 skip 选项来实现此目的。这会跳过数据文件开头的一些行而不解析它们(与 every 相对,它可以在 解析后跳过一些行,这仍然会给出一个错误):

set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
set style data lines
set border back
plot "stat.dat" using 1:4 skip 2 lw 3 title "system", \
     "" using 1:3 skip 2 lw 3 title "user", \
     "" using 1:5 skip 2 lw 3 title "idle"

另请注意,您的列计数有误。日期包含一个空格,因此当您引用以下值时,它算作两列。

或者,如果您没有 5.0 或 4.6.6 版本,您可以使用 tail 等外部工具来跳过前两行:

set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
set style data lines
set border back
plot "< tail -n +3 stat.dat" using 1:4 lw 3 title "system", \
     "" using 1:3 lw 3 title "user", \
     "" using 1:5 lw 3 title "idle"

关于linux - GNUPLOT 一个月中的非法日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804116/

相关文章:

r - 如何将十进制转换为 POSIX 时间

date - 如何更改 Groovy 日期格式

c - 如何为 Coldfire 工具链编译程序?

linux - 将输出重定向到命令结果给出的文件名

linux - 在连接到 Windows Server 2012 的 Linux 上使用 cURL 的 SingleSignOn

java - 计算两个 Java 日期实例之间的差异

c++ - 我如何使用 istream_iterator 将 unsigned char vector 转换为字符串?

c# - 如何在 C# 中显示一位小数的百分比并使用 string.Format 管理区域性?

c++ - 我如何以编程方式运行格式化磁盘?

linux - 这个sed有什么问题?