mackerelnullbridge

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 10 Imported by: 0

README

mackerel-null-bridge

Latest GitHub release Github Actions test Go Report Card License

A command line tool for filling missing metric values on Mackerel.

Description

When sending error metrics, etc., you may be forced to send them intermittently. When monitoring such intermittent metrics in Mackerel, alerts may not close automatically. This tool is designed to be run periodically, so it will fetch the values of the specified metrics not more than 15 minutes apart and interpolate the missing values. As a result, it expects to close alerts automatically, even for intermittent metrics.

Note: As of v0.0.0, only service metrics are still supported. This is because I can't think of any case where intermittent values are sent in the host metric.

Install

binary packages

Releases.

Homebrew tap
$ brew install mashiike/tap/mackerel-null-bridge

Usage

as CLI command
$mackerel-null-bridge
NAME:
   mackerel-null-bridge - A command line tool for filling missing metric values on Mackerel.

USAGE:
   mackerel-null-bridge --config <config file> --apikey <Mackerel APIKEY>

VERSION:
   0.0.0

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --apikey value, -k value  for access mackerel API (default: *********) [$MACKEREL_APIKEY]
   --config value, -c value  config file path, can set multiple [$CONFIG_FILE]
   --deploy                  deploy flag (cli only) (default: false)
   --dry-run                 dry-run flag (lambda only) (default: false) [$DRY_RUN]
   --log-level value         output log level (default: info) [$LOG_LEVEL]
   --help, -h                show help (default: false)
   --version, -v             print the version (default: false)
as AWS Lambda function

mackerel-null-bridge binary also runs as AWS Lambda function. mackerel-null-bridge implicitly behaves as a run command when run as a bootstrap with a Lambda Function

CLI options can be specified from environment variables. For example, when MACKEREL_APIKEY environment variable is set, the value is set to -apikey option.

Example Lambda functions configuration.

{
  "FunctionName": "mackerel-null-bridge",
  "Environment": {
    "Variables": {
      "CONFIG_FILE": "config.yaml",
      "MACKEREL_APIKEY": "<Mackerel API KEY>"
    }
  },
  "Handler": "bootstrap",
  "MemorySize": 128,
  "Role": "arn:aws:iam::0123456789012:role/lambda-function",
  "Runtime": "provided.al2",
  "Timeout": 300
}
Configuration file

YAML format.

required_version: ">=0.0.0"

targets:
  - service: prod
    metric_name: hoge.fuga.piyo
    value: 0.0
    delay_seconds: 300

Special Thanks

@handlename gave me the idea to name this tool.

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillConst

func FillConst(from, to int64, values []mackerel.MetricValue, name string, fillValue interface{}) ([]*mackerel.MetricValue, error)

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(cfg *Config, apikey string, deploy bool) *App

func (*App) Run

func (app *App) Run(ctx context.Context) error

type Config

type Config struct {
	RequiredVersion string `yaml:"required_version" json:"required_version"`

	Targets []*TargetConfig `yaml:"targets" json:"targets"`
	// contains filtered or unexported fields
}

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a default configuration.

func (*Config) Load

func (c *Config) Load(paths ...string) error

Load loads configuration file from file paths.

func (*Config) Restrict

func (c *Config) Restrict() error

Restrict restricts a configuration.

func (*Config) ValidateVersion

func (c *Config) ValidateVersion(version string) error

ValidateVersion validates a version satisfies required_version.

type DryRunMackerelClient

type DryRunMackerelClient struct {
	MackerelClient
}

func (DryRunMackerelClient) PostServiceMetricValues

func (c DryRunMackerelClient) PostServiceMetricValues(serviceName string, metricValues []*mackerel.MetricValue) error

type MackerelClient

type MackerelClient interface {
	FetchServiceMetricValues(serviceName string, metricName string, from int64, to int64) ([]mackerel.MetricValue, error)
	PostServiceMetricValues(serviceName string, metricValues []*mackerel.MetricValue) error
}

func NewMackerelClient

func NewMackerelClient(apikey string, deploy bool) MackerelClient

type ServiceMetric

type ServiceMetric struct {
	ServiceName  string
	MetricName   string
	DefaultValue interface{}
	DelaySeconds int64
	// contains filtered or unexported fields
}

func (*ServiceMetric) FillConst

func (m *ServiceMetric) FillConst(ctx context.Context, from int64, to int64) error

type TargetConfig

type TargetConfig struct {
	Service      string      `yaml:"service" json:"service"`
	MetricName   string      `yaml:"metric_name" json:"metric_name"`
	Value        interface{} `yaml:"value" json:"value"`
	DelaySeconds int64       `yaml:"delay_seconds" json:"delay_seconds"`
}

func (*TargetConfig) Restrict

func (c *TargetConfig) Restrict() error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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