Skip to content

syohex/mkr

 
 

Repository files navigation

mkr

Latest Version Build Status Go Documentation

mkr - Command Line Tool For Mackerel in Go.

DESCRIPTION

mkr is a command-line interface tool for Mackerel API written in Go language. mkr helps you to free your daily troublesome server operations and accelarates to leverage Mackerel and the Unix tools. mkr output format is JSON, so you can filter it by JSON processor such as jq.

INSTALLATION

$ go get github.com/mackerelio/mkr
$ go install github.com/mackerelio/mkr

Linux

# wget -O /usr/local/bin/mkr "https://github.com/mackerelio/mkr/releases/download/$(curl -sI https://github.com/mackerelio/mkr/releases/latest | awk -F'/' '/^Location:/{print $NF}' | tr -d '\r')/mkr_linux_amd64" && chmod +x /usr/local/bin/mkr

Mac

# wget -O /usr/local/bin/mkr "https://github.com/mackerelio/mkr/releases/download/$(curl -sI https://github.com/mackerelio/mkr/releases/latest | awk -F'/' '/^Location:/{print $NF}' | tr -d '\r')/mkr_darwin_amd64" && chmod +x /usr/local/bin/mkr

Linux (Docker)

https://registry.hub.docker.com/u/mackerel/mkr/

$ docker run mackerel/mkr --rm --entrypoint="cat" /go/bin/app > /usr/local/bin/mkr && chmod +x /usr/local/bin/mkr

USAGE

Set MACKEREL_APIKEY environment variable, but you don't have to set MACKEREL_APIKEY on your host running mackerel-agent. For more details, see below.

export MACKEREL_APIKEY=<Put your API key>

EXAMPLES

mkr status <hostId>
{
    "id": "2eQGEaLxiYU",
    "name": "myproxy001",
    "status": "standby",
    "roleFullnames": [
        "My-Service:proxy"
    ],
    "isRetired": false,
    "createdAt": "Nov 15, 2014 at 9:41pm (JST)"
}
mkr hosts --service My-Service --role proxy
[
    {
        "id": "2eQGEaLxiYU",
        "name": "myproxy001",
        "status": "standby",
        "roleFullnames": [
            "My-Service:proxy"
        ],
        "isRetired": false,
        "createdAt": "Nov 15, 2014 at 9:41pm (JST)"
    },
    {
        "id": "2eQGDXqtoXs",
        "name": "myproxy002",
        "status": "standby",
        "roleFullnames": [
            "My-Serviceg:proxy"
        ],
        "isRetired": false,
        "createdAt": "Nov 15, 2014 at 9:41pm (JST)"
    },
]

mkr hosts command has '-f' option to format the output.

mkr hosts -f '{{range .}}{{if (len .Interfaces)}}{{(index .Interfaces 0).IPAddress}}{{end}}{{"\t"}}{{.Name}}{{"\n"}}{{end}}'
10.0.1.1  myproxy001
10.0.1.2  myproxy002
...
mkr create --status working -R My-Service:db-master mydb001
mkr update --status maintenance --roleFullname My-Service:db-master <hostId>
cat <<EOF | mkr throw --host <hostId>
<name>  <time>  <value>
<name>  <time>  <value>
EOF
...

cat <<EOF | mkr throw --service My-Service
<name>  <time>  <value>
<name>  <time>  <value>
EOF
...
mkr fetch --name loadavg5 2eQGDXqtoXs
{
    "2eQGDXqtoXs": {
        "loadavg5": {
            "time": 1416061500,
            "value": 0.025
        }
    }
}
mkr retire <hostId> ...

Examples (on host running mackerel-agent)

You can omit specifing and MACKEREL_APIKEY. mkrrefers /var/lib/mackerel-agent/id and /etc/mackerel-agent/mackerel-agent.conf instead of specifing .

mkr status
mkr update --status maintenance <hostIds>...
mkr fetch -n loadavg5
cat <<EOF | mkr throw --host <hostId>
<name>  <time>  <value>
EOF
mkr retire

ADVANCED USAGE

$ mkr update --st working $(mkr hosts -s My-Service -r proxy | jq -r '.[].id')

CONTRIBUTION

  1. Fork (https://github.com/mackerelio/mkr/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

License

Copyright 2014 Hatena Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Command Line Tool for Mackerel (under development)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 92.7%
  • Makefile 5.5%
  • Shell 1.8%