sardine

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

README

sardine

Mackerel plugin metrics aggregator with CloudWatch.

Configuration

# config.toml

[plugin.metrics.memcached]
command = "mackerel-plugin-memcached --host localhost --port 11211"
dimensions = [
  "ClusterName=mycluster",
  "ClusterName=mycluster,AvailabilityZone=az-a"
] # "Name=Value[,Name=Value...]"
interval = "10s"
timeout  = "5s"

[plugin.metrics.xxxx]
command = "...."

[plugin.check.memcached]
namespace = "memcahed/check" # required
dimensions = ["ClusterName=mycluster"]
command = "memping -s localhost:11211"
$ sardine -config config.toml

AWS credentials for access to CloudWatch are read from environment variables or instance profile.

  • AWS_REGION: required. e.g. ap-northeast-1

How sardine works

sardine works as below.

  1. Execute command for each [plugin.metrics.*] sections.
    • default interval 60 sec.
  2. Put metrics got from command's output to CloudWatch metrics.
    • e.g. memcached.cmd.cmd_get 10.0 1512057958 put as
      • Namespace: memcached/cmd
      • MetricName: cmd_get
      • Value: 10.0
      • Timestamp: 2017-12-01T16:05:58Z
  3. Execute command for each [plugin.check.*] sections.
    • default interval 60 sec.
  4. Put a command's result to CloudWatch metrics.
    • e.g.
      • Namespace: memcached/check
      • MetricName: CheckFailed
      • Value: 1
      • Timestamp: 2017-12-01T16:05:58Z
    • exit status of command maps to CloudWatch metric name as below
      • 0 : CheckOK
      • 1 : CheckFailed
      • 2 : CheckWarning
      • other : CheckUnknown
    • metric Value is always 1

Author

Fujiwara Shunichiro fujiwara.shunichiro@gmail.com

License

Copyright 2017 Fujiwara Shunichiro

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

nless 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.

Documentation

Index

Constants

View Source
const (
	PluginPrefix = "custom."
)

Variables

View Source
var (
	Debug                 = false
	DefaultInterval       = time.Minute
	DefaultCommandTimeout = time.Minute
)

Functions

func Run

func Run(configPath string) error

Types

type CheckPlugin

type CheckPlugin struct {
	ID         string
	Namespace  string
	Command    string
	Timeout    time.Duration
	Interval   time.Duration
	Dimensions [][]*cloudwatch.Dimension
}

func (*CheckPlugin) Execute

func (cp *CheckPlugin) Execute(_ctx context.Context) (CheckResult, error)

func (*CheckPlugin) Run

func (cp *CheckPlugin) Run(ctx context.Context, ch chan *cloudwatch.PutMetricDataInput)

type CheckResult

type CheckResult int
const (
	CheckOK CheckResult = iota
	CheckFailed
	CheckWarning
	CheckUnknown
)

func (CheckResult) NewMetricDatum

func (r CheckResult) NewMetricDatum(ds []*cloudwatch.Dimension, ts time.Time) *cloudwatch.MetricDatum

func (CheckResult) String

func (i CheckResult) String() string

type CloudWatchDriver added in v0.1.0

type CloudWatchDriver struct {
	Dimensions [][]*cloudwatch.Dimension
	Ch         chan *cloudwatch.PutMetricDataInput
}

type Config

type Config struct {
	APIKey               string
	Plugin               map[string]map[string]*PluginConfig
	MetricPlugins        map[string]*MetricPlugin
	CheckPlugins         map[string]*CheckPlugin
	CustomIdentifierList sync.Map
	MackerelClient       *mackerel.Client
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(path string, ch chan *cloudwatch.PutMetricDataInput, mch chan []*mackerel.HostMetricValue) (*Config, error)

func (*Config) GetHostIDByCustomIdentifier added in v0.1.0

func (c *Config) GetHostIDByCustomIdentifier(customIdentifier string) (string, error)

type Dimension

type Dimension string

func (*Dimension) CloudWatchDimensions

func (d *Dimension) CloudWatchDimensions() ([]*cloudwatch.Dimension, error)

type MackerelDriver added in v0.1.0

type MackerelDriver struct {
	HostID string
	Ch     chan []*mackerel.HostMetricValue
}

type Metric

type Metric struct {
	Namespace string
	Name      string
	Value     float64
	Timestamp time.Time
}

func (*Metric) NewMackerelMetric added in v0.1.0

func (m *Metric) NewMackerelMetric(hostID string) *mackerel.HostMetricValue

func (*Metric) NewMetricDatum

func (m *Metric) NewMetricDatum(ds []*cloudwatch.Dimension) *cloudwatch.MetricDatum

type MetricPlugin

type MetricPlugin struct {
	ID           string
	Command      string
	Timeout      time.Duration
	Interval     time.Duration
	PluginDriver PluginDriver
}

func (*MetricPlugin) Execute

func (mp *MetricPlugin) Execute(_ctx context.Context) ([]*Metric, error)

func (*MetricPlugin) GraphDef added in v0.1.0

func (mp *MetricPlugin) GraphDef() (interface{}, error)

func (*MetricPlugin) Run

func (mp *MetricPlugin) Run(ctx context.Context)

type PluginConfig

type PluginConfig struct {
	Namespace        string
	Command          string
	Timeout          duration
	Interval         duration
	Dimensions       []*Dimension
	CustomIdentifier string `toml:"custom_identifier"`
}

func (*PluginConfig) NewCheckPlugin

func (pc *PluginConfig) NewCheckPlugin(id string) (*CheckPlugin, error)

func (*PluginConfig) NewMackerelMetricPlugin added in v0.1.0

func (pc *PluginConfig) NewMackerelMetricPlugin(conf *Config, id string, ch chan []*mackerel.HostMetricValue) (*MetricPlugin, error)

func (*PluginConfig) NewMetricPlugin

func (pc *PluginConfig) NewMetricPlugin(id string, ch chan *cloudwatch.PutMetricDataInput) (*MetricPlugin, error)

type PluginDriver added in v0.1.0

type PluginDriver interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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