Mackerel [カスタムメトリック取得]

# 目的
* 標準メトリック以外のメトリックを取得する
    * Apacheのカスタムメトリックを取得する

# 方法
* Mackerel公式Pluginを使用
    * [mackerel-agent-plugins](https://github.com/mackerelio/mackerel-agent-plugins)
        * [README](https://github.com/mackerelio/mackerel-agent-plugins#installation)を見て、環境毎に設定する

# 確認

* システムメトリック

```bash
# curl -X GET -H "X-Api-Key: *************" https://mackerel.io/api/v0/hosts/******/metric-names | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   839  100   839    0     0   4801      0 --:--:-- --:--:-- --:--:--  4821
{
  "names": [
    "cpu.guest.percentage",
    "cpu.idle.percentage",
    "cpu.iowait.percentage",
    "cpu.irq.percentage",
    "cpu.nice.percentage",
    "cpu.softirq.percentage",
    "cpu.steal.percentage",
    "cpu.system.percentage",
    "cpu.user.percentage",
    "disk.xvda.reads.delta",
    "disk.xvda.writes.delta",
    "disk.xvda1.reads.delta",
    "disk.xvda1.writes.delta",
    "filesystem.xvda1.size",
    "filesystem.xvda1.used",
    "interface.eth0.rxBytes.delta",
    "interface.eth0.txBytes.delta",
    "loadavg5",
    "memory.active",
    "memory.available",
    "memory.buffers",
    "memory.cached",
    "memory.free",
    "memory.inactive",
    "memory.swap_cached",
    "memory.swap_free",
    "memory.swap_total",
    "memory.total",
    "memory.used"
  ]
}
```


# 設定
*  Usage
    *  [mackerel-plugin-apache2](https://github.com/mackerelio/mackerel-agent-plugins/tree/master/mackerel-plugin-apache2#usage)
*  conf

```bash:/etc/httpd/conf.d/mackerel_apache2.conf
Listen 1080
ExtendedStatus On
<VirtualHost 127.0.0.1:1080>
    <Location /server-status>
        SetHandler server-status
        Order deny,allow
        Deny from all
        Allow from localhost
    </Location>
</VirtualHost>
```
```bash:/etc/mackerel-agent/mackerel-agent.conf
--- mackerel-agent.conf	2016-09-07 11:28:56.428350098 +0900
+++ mackerel-agent.conf.orig	2016-09-06 19:36:14.908554933 +0900
@@ -20,9 +20,6 @@
 #   By default, the plugin accesses to http://127.0.0.1/server-status?auto
 # [plugin.metrics.apache2]
 # command = "mackerel-plugin-apache2"
-[plugin.metrics.apache2]
-command = "/usr/bin/mackerel-plugin-apache2 -p 1080"
-type = "metric"
 
 # Plugin for EC2 CPU Credit
 # [plugin.metrics.aws-ec2_cpucredit]
```

* 適用
* 
```bash
# systemctl restart httpd;systemctl restart mackerel-agent
```

* excute

```bash
# /usr/bin/./mackerel-plugin-apache2 -p 1080
apache2.scoreboard.score-_	4.000000	1473224125
apache2.scoreboard.score-.	251.000000	1473224125
apache2.workers.busy_workers	1.000000	1473224125
apache2.workers.idle_workers	4.000000	1473224125
apache2.bytes.bytes_sent	0.000000	1473224125
apache2.req.requests	8.571429	1473224125
```

* 確認
    * カスタムメトリックスが増えている

```bash
# curl -X GET -H "X-Api-Key: *************" https://mackerel.io/api/v0/hosts/******/metric-names | jq '.'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   839  100   839    0     0   5327      0 --:--:-- --:--:-- --:--:--  5310
{
  "names": [
    "cpu.guest.percentage",
    "cpu.idle.percentage",
    "cpu.iowait.percentage",
    "cpu.irq.percentage",
    "cpu.nice.percentage",
    "cpu.softirq.percentage",
    "cpu.steal.percentage",
    "cpu.system.percentage",
    "cpu.user.percentage",
    "custom.apache2.bytes.bytes_sent",
    "custom.apache2.req.requests",
    "custom.apache2.scoreboard.score-.",
    "custom.apache2.scoreboard.score-_",
    "custom.apache2.workers.busy_workers",
    "custom.apache2.workers.idle_workers",
    "disk.xvda.reads.delta",
    "disk.xvda.writes.delta",
    "disk.xvda1.reads.delta",
    "disk.xvda1.writes.delta",
    "filesystem.xvda1.size,
    "filesystem.xvda1.used",
    "interface.eth0.rxBytes.delta",
    "interface.eth0.txBytes.delta",
    "loadavg5",
    "memory.active",
    "memory.available",
    "memory.buffers",
    "memory.cached",
    "memory.free",
    "memory.inactive",
    "memory.swap_cached",
    "memory.swap_free",
    "memory.swap_total",
    "memory.total",
    "memory.used"
  ]
}

```