• Stars
    star
    111
  • Rank 305,251 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command Line Tool for Mackerel

mkr

Latest Version Build Status Go Documentation

mkr - Command Line Tool For Mackerel written in Go.

DESCRIPTION

mkr is a command-line interface tool for the Mackerel API written in Go. mkr helps to automate tedious daily server operations to best leverage Mackerel's and Unix's tools. mkr output format is JSON, so it can be filtered with a JSON processor such as jq.

INSTALLATION

apt / yum (for Linux)

CentOS 7 (or later)

curl -fsSL https://mackerel.io/file/script/setup-yum-v2.sh | sh
yum install mkr

Debian / Ubuntu

curl -fsSL https://mackerel.io/file/script/setup-apt-v2.sh | sh
apt-get install mkr

Amazon Linux 2 LTS

curl -fsSL https://mackerel.io/file/script/amznlinux/setup-yum-v2.sh | sh
yum install mkr

Amazon Linux

curl -fsSL https://mackerel.io/file/script/amznlinux/setup-yum.sh | sh
yum install mkr

Homebrew (for macOS)

You can also install from the brew rule we maintain, but we don't officially support the environment.

brew tap mackerelio/mackerel-agent
brew install mkr

Build from source

$ go install github.com/mackerelio/mkr@latest

USAGE

First the MACKEREL_APIKEY environment variable must be set. It is not necessary to set the MACKEREL_APIKEY on hosts 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": "2014-11-15T21:41:00+09:00"
}
mkr hosts --service My-Service --role proxy
[
    {
        "id": "2eQGEaLxiYU",
        "name": "myproxy001",
        "status": "standby",
        "roleFullnames": [
            "My-Service:proxy"
        ],
        "isRetired": false,
        "createdAt": "2014-11-15T21:41:00+09:00"
    },
    {
        "id": "2eQGDXqtoXs",
        "name": "myproxy002",
        "status": "standby",
        "roleFullnames": [
            "My-Service:proxy"
        ],
        "isRetired": false,
        "createdAt": "2014-11-15T21:41:00+09:00"
    },
]

The format of createdAt uses ISO-8601 in the current time zone.

The mkr hosts command has an '-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>  <value> <time>
<name>  <value> <time>
EOF
...

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

Examples (on hosts running mackerel-agent)

Specifying the and MACKEREL_APIKEY is not necessary because mkr refers to /var/lib/mackerel-agent/id and /etc/mackerel-agent/mackerel-agent.conf instead of specifying manually.

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

ADVANCED USAGE

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

Using Docker Image

https://hub.docker.com/r/mackerel/mkr/

$ docker run --rm --env MACKEREL_APIKEY=<API key> mackerel/mkr help

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.

More Repositories

1

mackerel-agent

mackerel-agent is an agent program to post your hosts' metrics to mackerel.io.
Go
422
star
2

go-osstat

OS system statistics library for Go
Go
365
star
3

go-check-plugins

Check Plugins for monitoring written in golang
Go
252
star
4

mackerel-agent-plugins

Plugins for mackerel-agent
Go
245
star
5

mackerel-client-go

Mackerel API Client in Go
Go
45
star
6

mackerel-client-ruby

Mackerel client implemented by Ruby
Ruby
41
star
7

fluent-plugin-mackerel

Fluent plugin to send metrics to mackerel.io
Ruby
38
star
8

ansible-mackerel-agent

An Ansible role for mackerel-agent. (development version)
Jinja
33
star
9

mackerel-container-agent

Monitoring agent of Mackerel for containers on container orchestration platforms.
Go
33
star
10

cookbook-mackerel-agent

Chef cookbook for mackerel-agent installation
Ruby
23
star
11

go-mackerel-plugin

Development helpers for mackerel agent plugin
Go
22
star
12

plugin-registry

Perl
16
star
13

go-mackerel-plugin-helper

Development helpers for mackerel agent plugin
Go
13
star
14

documents

Source markdown files of Mackerel documentation hosted on https://mackerel.io
13
star
15

checkers

Go
12
star
16

homebrew-mackerel-agent

homebrew tap to install mackerel-agent
Ruby
10
star
17

golib

Go
8
star
18

itamae-plugin-recipe-mackerel-agent

Ruby
8
star
19

mdg

mdg - Mackerel Dashboard Generator
Ruby
6
star
20

docker-mackerel-agent

Shell
6
star
21

mackerel-plugin-json

Go
5
star
22

hubot-mackerel-notifier

CoffeeScript
5
star
23

mackerel-crawler

Go
4
star
24

mackerel-plugin-aws-batch

Go
3
star
25

fluent-plugin-webhook-mackerel

fluentd input plugin for receiving Mackerel webhook
Ruby
2
star
26

graphite-docker

Graphite image for Docker
Python
1
star
27

check-aws-cloudwatch-logs-insights

yet another Amazon CloudWatch Logs check plugin with CloudWatch Logs Insights
Go
1
star
28

mackerel-plugin-gcp-compute-engine

Go
1
star
29

mackerel-plugin-sample

Sample plugin for mackerel.io agent
Go
1
star
30

mackerel-plugin-aws-ec2

Go
1
star
31

workflows

Reusable workflows for use in the mackerelio organization
1
star
32

mackerel-plugin-nvidia-smi

Go
1
star