LoginSignup
5
1

More than 5 years have passed since last update.

GetWildの信号強度を解析し、音の大きさをMackerelでグラフ化する

Posted at

Mackerel Advent Calendar 2016の18日目です。

概要

内容

①flac2floatを使って、1分間に/tmp/soud_decode.logに値を出力させるコード(flac2float.go)を書く

package main

import (
  "io/ioutil"
  "log"
  "os"
  "strconv"
  "time"

  "github.com/sioncojp/flac2float"
)

const (
  filename = "/tmp/sound_decode.log"
)

func main() {
  decode := flac2float.New(os.Stdin, 1)
  values, err := decode.ReadSound()
  if err != nil {
    log.Fatalf("Error: %s", err)
  }
  for _, value := range values {
    ioutil.WriteFile(filename, []byte(strconv.FormatFloat(value, 'f', 12, 64)), 0644)
    time.Sleep(60 * time.Second)
  }
}

②Mackerel監視用スクリプトを書く

### 初期データ投入
$ echo 0 > /tmp/sound_decode.log

### 計測用スクリプトを書く
$ vim /tmp/get_wild_and_tough.sh

#!/bin/bash

name="GetWild"
monitor_time=`date +%s`
count=`cat /tmp/sound_decode.log`
echo -e "${name}\t${count}\t${monitor_time}"

③mackerel-agent.confを書いてreload。そのあとビルドしたコマンドを走らせる

### 書く
$ vim /etc/mackerel-agent/mackerel-agent.conf
[plugin.metrics.Playing_GetWild]
command = "/bin/bash /tmp/get_wild_and_tough.sh"

### reloadする
$ service mackerel-agent reload

### build後、走らせる
$ go build flac2float.go
$ nohup cat GET_WILD.flac | ./flac2float &

④結果

スクリーンショット 2016-12-15 1.18.54.png
* 音楽の秒数だけ足しました

Mackerelの良いところ

  • 先ほどみたいに全体を見ることもできるし、ポイント毎に細かくチェック出来るところが良いですね スクリーンショット 2016-12-15 1.34.47.png

最後に

  • なんでも可視化出来るMackerelすごい!
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1