macaroni

package module
v0.0.0-...-256a76a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2019 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

macaroni

macaroni is a reporter for Songmu/horenso.

macaroni has following functions.

  • Slack reporter
    • Post a result of command to Slack.
    • When running in Amazon ECS, reports an information of cluster, task ARN and container name
  • Mackerel metric reporter.
    • Post service or host metrics
      • error
      • elapsed time

Usage

$ horenso --reporter=macaroni -- my-batch-command

Installation

Homebrew
$ brew install fujiwara/tap/macaroni
ghg
$ ghg get fujiwara/macaroni

Built binaries are available on gihub releases. https://github.com/fujiwara/macaroni/releases

go get
$ go get github.com/fujiwara/macaroni/cmd/macaroni

Configuration

Environment variables customize behaviors for macaroni.

All of configurations are defined by environment variables.

Slack reporter

Slack reporter posts a report as a message to Slack.

SLACK_ENDPOINT: Incoming Webhook URL. (required)

SLACK_CHANNEL: Channel name. (requried)

When SLACK_ENDPOINT or SLACK_CHANNEL are empty, Slack reporter becomes to disabled.

SLACK_USERNAME: Username. (default: webhook name)

SLACK_MEMTION: Mentions in a report message. (e.g @here)

SLACK_ICON_EMOJI: Icon emoji.

SLACK_PASTEBIN_CMD: When specified, macaroni invokes the value as command and writes horenso report.Output into that command's stdin. Then report.Output is replaced by the command's output.

SLACK_MUTE_ON_NORMAL: Do not report when horenso command exit nomrally.

Mackerel reporter

Mackerel reporter posts a report as metrics to Mackerel.

Metrics have two values as below.

  1. {prefix}.error.{name}: When report.ExitCode is non zero, that value becomes to 1, otherwise 0.
  2. {prefix}.elapsed.{name}: An elapsed time as seconds. (report.EndAt - report.StartAt).

MACKEREL_TARGET: A target (Mackerel Host or Service) to post metrics. (required)

  • host:[HostID] Post a report as host metrics. HostID is optional. When it is not specified (MACKEREL_TARGTE=host:), HostID is determined by mackerel-agent config.
  • service:[ServiceName] Post a report as service metrics. ServiceName is required.

When MACKEREL_TARGET is empty, Mackerel reporter becomes to disabled.

MACKEREL_METRIC_NAME_PREFIX: A prefix of report metrics. (default: horenso.report)

MACKEREL_METRIC_NAME: A name of report metrics. (default: report.Command =~ s/[^0-9a-zA-Z_-]/_/g).

MACKEREL_APIKEY: API key. When the value is not specified, macaroni tries to read API key from mackerel-agent config.

LICENSE

The MIT License (MIT)

Copyright (c) 2019 FUJIWARA Shunichiro.

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Variables

View Source
var (
	DefaultMetricNamePrefix   = "horenso.report"
	MetricNameNoramlizeRegexp = regexp.MustCompile(`[^0-9a-zA-Z_-]`)
	MetricNameTruncateRegexp  = regexp.MustCompile(`_{2,}`)
)
View Source
var CommandTimeout = 60 * time.Second
View Source
var MaxOutputLength = 1000
View Source
var Revision = "HEAD"

Functions

func Run

func Run(conf *Config, src io.Reader) error

Types

type Attachment

type Attachment struct {
	Fallback string  `json:"fallback"`
	Color    string  `json:"color"`
	Fields   []Field `json:"fields"`
}

type Config

type Config struct {
	Slack    *SlackConfig
	Mackerel *MackerelConfig
}

func BuildConfig

func BuildConfig() *Config

type ECSContainerMetadata

type ECSContainerMetadata struct {
	DockerID      string            `json:"DockerId"`
	Name          string            `json:"Name"`
	DockerName    string            `json:"DockerName"`
	Image         string            `json:"Image"`
	ImageID       string            `json:"ImageID"`
	Labels        map[string]string `json:"Labels"`
	DesiredStatus string            `json:"DesiredStatus"`
	KnownStatus   string            `json:"KnownStatus"`
	Limits        struct {
		CPU    int `json:"CPU"`
		Memory int `json:"Memory"`
	} `json:"Limits"`
	CreatedAt time.Time `json:"CreatedAt"`
	StartedAt time.Time `json:"StartedAt"`
	Type      string    `json:"Type"`
	Networks  []struct {
		NetworkMode   string   `json:"NetworkMode"`
		IPv4Addresses []string `json:"IPv4Addresses"`
	} `json:"Networks"`
}

type ECSMetadata

type ECSMetadata struct {
	Cluster       string
	TaskARN       string
	ContainerName string
}

type ECSTaskMetadata

type ECSTaskMetadata struct {
	Cluster       string `json:"Cluster"`
	TaskARN       string `json:"TaskARN"`
	Family        string `json:"Family"`
	Revision      string `json:"Revision"`
	DesiredStatus string `json:"DesiredStatus"`
	KnownStatus   string `json:"KnownStatus"`
	Containers    []struct {
		DockerID      string            `json:"DockerId"`
		Name          string            `json:"Name"`
		DockerName    string            `json:"DockerName"`
		Image         string            `json:"Image"`
		ImageID       string            `json:"ImageID"`
		Labels        map[string]string `json:"Labels"`
		DesiredStatus string            `json:"DesiredStatus"`
		KnownStatus   string            `json:"KnownStatus"`
		Limits        struct {
			CPU    int `json:"CPU"`
			Memory int `json:"Memory"`
		} `json:"Limits"`
		CreatedAt time.Time `json:"CreatedAt"`
		StartedAt time.Time `json:"StartedAt"`
		Type      string    `json:"Type"`
		Networks  []struct {
			NetworkMode   string   `json:"NetworkMode"`
			IPv4Addresses []string `json:"IPv4Addresses"`
		} `json:"Networks"`
	} `json:"Containers"`
	PullStartedAt time.Time `json:"PullStartedAt"`
	PullStoppedAt time.Time `json:"PullStoppedAt"`
}

type Field

type Field struct {
	Title string `json:"title"`
	Value string `json:"value"`
}

type MackerelConfig

type MackerelConfig struct {
	ApiKey           string
	MetricNamePrefix string
	MetricName       string
	Service          string
	HostID           string
}

type Payload

type Payload struct {
	Text        string       `json:"text"`
	Channel     string       `json:"channel"`
	LinkNames   int          `json:"link_names"`
	Username    string       `json:"username,omitempty"`
	IconEmoji   string       `json:"icon_emoji,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

type SlackConfig

type SlackConfig struct {
	Endpoint     string
	Username     string
	IconEmoji    string
	Channel      string
	Mention      string
	PasteBinCmd  string
	MuteOnNormal bool
}

Directories

Path Synopsis
cmd
macaroni command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址