4. グラフ 日本語文字化け修正
グラフのホスト名や凡例の部分は、それぞれの言語に対応したフォントを別途用意する必要があります。フォントのダウンロードと設定方法について説明します。
フォントのダウンロード
Webインターフェースの言語を日本語にしても、グラフの日本語で表示される部分が文字化けしてしまいます。
これは、グラフ用に指定されているフォントが、日本語に対応していないためです。
Ubuntu Linuxの場合、インストールされているフォントの調べ方や、利用できるパッケージについて、以下のサイトにわかりやすい説明があります。
日本語の場合、IPAというフリーのフォントを使うのが一般的なようです。それをインストールします。
$ sudo apt-get install fonts-ipafont
ダウンロードされたファイルは、fc-listコマンドで確認できます。
$ fc-list | grep IPA /usr/share/fonts/opentype/ipafont-mincho/ipam.ttf: IPAMincho,IPA明朝:style=Regular /usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf: IPAPGothic,IPA Pゴシック:style=Regular /usr/share/fonts/opentype/ipafont-mincho/ipamp.ttf: IPAPMincho,IPA P明朝:style=Regular /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf: IPAGothic,IPAゴシック:style=Regular /usr/share/fonts/truetype/fonts-japanese-mincho.ttf: IPAMincho,IPA明朝:style=Regular /usr/share/fonts/truetype/fonts-japanese-gothic.ttf: IPAGothic,IPAゴシック:style=Regular
フォントの置き換え
ダウンロードしたフォント、Zabbixがグラフで使用するファイルは、PHPのコンフィグファイルで指定されています。
$ ls -SN /usr/share/zabbix/include/defines.inc.php (略) 46 define('ZBX_FONTPATH', realpath('fonts')); // where to search for font (GD > 2.0.18) 47 define('ZBX_GRAPH_FONT_NAME', 'graphfont'); // font file name (略)
フォントファイル自体は、シンボリックリンクで指定されています。
$ ls -l /usr/share/zabbix/fonts/graphfont.ttf lrwxrwxrwx 1 root root 38 Jan 3 10:22 /usr/share/zabbix/fonts/graphfont.ttf -> /etc/alternatives/zabbix-frontend-font $ ls -l /etc/alternatives/zabbix-frontend-font lrwxrwxrwx 1 root root 47 Jan 3 10:44 /etc/alternatives/zabbix-frontend-font -> /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
このシンボリックリンクのソースファイル名を直接書き換えても変更できますが、alternativeという仕組みで管理されているようなので、そちらの作法に従って変更します。update-alternatives --installというコマンドを使用します。ファイルのパスが入っていてちょっと長いですが、そのままコピペしてください。
$ sudo update-alternatives --install /usr/share/zabbix/fonts/graphfont.ttf zabbix-frontend-font /usr/share/fonts/truetype/fonts-japanese-gothic.ttf 20
update-alternatives --query コマンドで設定内容を確認します。
$ sudo update-alternatives --query zabbix-frontend-font Name: zabbix-frontend-font Link: /usr/share/zabbix/fonts/graphfont.ttf Status: manual Best: /usr/share/fonts/truetype/fonts-japanese-gothic.ttf Value: /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf Alternative: /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf Priority: 10 Alternative: /usr/share/fonts/truetype/fonts-japanese-gothic.ttf Priority: 20
PrIorityの数字が大きいほうが、優先的に使用されます。
これでグラフを再表示すると、日本語が表示されるようになります。
ただ、この状態でWebインターフェースを英語にすると、アルファベットはあまりきれいなフォントではないです。
フォントを切り替える場合は、update-alternatives --config コマンドで変更します。
$ sudo update-alternatives --config zabbix-frontend-font There are 2 choices for the alternative zabbix-frontend-font (providing /usr/share/zabbix/fonts/graphfont.ttf). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/share/fonts/truetype/fonts-japanese-gothic.ttf 20 auto mode 1 /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf 10 manual mode 2 /usr/share/fonts/truetype/fonts-japanese-gothic.ttf 20 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 ←英語のフォントを指定 update-alternatives: using /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf to provide /usr/share/zabbix/fonts/graphfont.ttf (zabbix-frontend-font) in manual mode
これで、最初に使っていたフォントに戻ります。