Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

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

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すごい!
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?