rderoldan1 / usagewatch_ext

Extended version of usagewatch
MIT License
21 stars 9 forks source link

invalid byte sequence in UTF-8 #4

Closed chip-and-dail closed 10 years ago

chip-and-dail commented 10 years ago

screen

work: <%= @usw.uw_cpuused %> not work: <%= @usw.uw_diskused_perc %>

why?

P.S.

Distributor ID: Debian Release: 7.4 Codename: wheezy

rderoldan1 commented 10 years ago

Any comment?

chip-and-dail commented 10 years ago

sorry, update comment

rderoldan1 commented 10 years ago

Can you run this in IRB?

 df = `df --total`
 df.split(" ").last.to_f.round(2)
chip-and-dail commented 10 years ago

1.9.3-p545 :001 > df = df --total => "Файловая система 1K-блоков Использовано Доступно Использовано% Cмонтировано в\n/dev/ploop34820p1 15479792 3323852 11369612 23% /\nnone 2097152 4 2097148 1% /dev\nnone 419432 1100 418332 1% /run\nnone 5120 0 5120 0% /run/lock\nnone 1677720 0 1677720 0% /run/shm\nnone 102400 0 102400 0% /run/user\ntotal 19781616 3324956 15670332 18%\n" 1.9.3-p545 :002 > df.split(" ").last.to_f.round(2) => 18.0 1.9.3-p545 :003 >

rderoldan1 commented 10 years ago

It run in the server?, because this is the code that returns the uw_diskused_perc, Probably the lang config is generating the error

chip-and-dail commented 10 years ago

yes, it's in the server

rderoldan1 commented 10 years ago

please, run in the terminal

$ env

wich lang is have you ?, in my case LANG=en_US.UTF-8

chip-and-dail commented 10 years ago

LANG=ru_RU.KOI8-R

chip-and-dail commented 10 years ago

what i must do?

chip-and-dail commented 10 years ago

complete

df = `df --total`.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
df.split(" ").last.to_f.round(2)

by http://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences

rderoldan1 commented 10 years ago

Hey @chip-and-dail excuse me for the delay, looks like your shell lang is not compatible with sub by default, if we replace all no utf-8 characters, probably some info will be lost. Even though, almost all linux methods are inherited from https://github.com/nethacker/usagewatch, so we have two options,

  1. Submit an issue in the original gem
  2. Overwrite this method here, but, you should submit a pull request, and all test should be ok, because I have production code, almost for a year with out any problem (http://status.cooperativas.co)
chip-and-dail commented 10 years ago

Yes, I'm overwrited. Thanks!