maprobe

package module
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2025 License: MIT Imports: 55 Imported by: 1

README

maprobe

Mackerel external probe / aggregate agent.

Description

maprobe is an external probe / aggregate agent with Mackerel.

maprobe agent works as below.

for probes
  1. Fetch hosts information from Mackerel API.
    • Filtered service and role.
  2. For each hosts, execute probes (ping, tcp, http, command).
    • expand place holder in configuration {{ .Host }} as Mackerel host struct.
    • {{ .Host.IPAddress.eth0 }} expand to e.g. 192.168.1.1
  3. Posts host metrics to Mackerel (and/or OpenTelemetry metrics endpoint if configured).
  4. Iterates these processes each 60 sec.
for aggregates
  1. Fetch hosts information from Mackerel API.
    • Filtered service and role.
  2. For each hosts, fetch specified host metrics to calculates these metrics by functions.
  3. Post theses aggregated metrics as Mackerel service metrics.
  4. Iterates these processes each 60 sec.

Install

Binary packages

GitHub releases

Docker

DockerHub

Usage

usage: maprobe [<flags>] <command> [<args> ...]

Flags:
  --help              Show context-sensitive help (also try --help-long and --help-man).
  --log-level="info"  log level

Commands:
  help [<command>...]
    Show help.

  agent [<flags>]
    Run agent

  once [<flags>]
    Run once

  ping [<flags>] <address>
    Run ping probe

  tcp [<flags>] <host> <port>
    Run TCP probe

  http [<flags>] <url>
    Run HTTP probe

  grpc [<flags>] <address>
    Run gRPC probe

  firehose-endpoint [<flags>]
    Run Firehose HTTP endpoint
agent / once

MACKEREL_APIKEY environment variable is required.

$ maprobe agent --help
usage: maprobe agent [<flags>]

Run agent

Flags:
      --help              Show context-sensitive help (also try --help-long and --help-man).
      --log-level="info"  log level
  -c, --config=CONFIG     configuration file path or URL(http|s3)

--config accepts a local file path or URL(http, https or s3 scheme). maprobe checks the config is modified, and reload in run time.

Defaults of --config and --log-level will be overrided from envrionment variables (CONFIG and LOG_LEVEL).

agent runs maprobe forever, once runs maprobe once.

Example Configuration for probes
post_probed_metrics: false   # when false, do not post host metrics to Mackerel. only dump to [info] log.
probes:
  - service: '{{ env "SERVICE" }}'   # expand environment variable
    role: server
    ping:
      address: '{{ .Host.IPAddresses.eth0 }}'

  - service: production
    role: webserver
    http:
      url: 'http://{{ .Host.CustomIdentifier }}/api/healthcheck'
      method: POST
      headers:
        Content-Type: application/json
      body: '{"hello":"world"}'
      expect_pattern: 'ok'

  - service: production
    role: redis
    tcp:
      host: '{{ .Host.IPAddress.eth0 }}'
      port: 6379
      send: "PING\n"
      expect_pattern: "PONG"
      quit: "QUIT\n"
    command:
      command:
        - "mackerel-plugin-redis"
        - "-host={{ .Host.IPAddress.eth0 }}"
        - "-tempfile=/tmp/redis-{{ .Host.ID }}"
    attributes: # supoort OpenTelemetry attributes
      - service.namespaece: redis
      - host.name: "{{ .Host.Name }}"

  - service: production
    role: api
    grpc:
      address: '{{ .Host.IPAddress.eth0 }}:50051'
      grpc_service: "api.v1.UserService"
      metadata:
        authorization: "Bearer {{ env "API_TOKEN" }}"
      tls: true

  - service: production
    service_metric: true # post metrics as service metrics
    http:
      url: 'https://example.net/api/healthcheck'
      post: GET
      headers:
        Content-Type: application/json
      body: '{"hello":"world"}'
      expect_pattern: 'ok'

destination:
  mackerel:
    enabled: true # default true
  otel:
    enabled: true # default false
    endpoint: localhost:4317
    insecure: true
OpenTelemetry metrics endpoint support

destination.otel.enabled: true enables to post metrics to OpenTelemetry metrics endpoint. maprobe uses the gRPC protocol to send metrics.

destination:
  mackerel:
    enabled: false # disable mackerel host/service metrics
  otel:
    enabled: true
    endpoint: localhost:4317
    insecure: true
    resource_attributes: # OpenTelemetry resource attributes (for all metrics)
      deployment.environment.name: production
    stats_attributes: # for maprobe internal metrics
      service.name: maprobe
      service.namespace: my-namespace

Extra attributes can be added to metrics by attributes in probe configuration.

By default, maprobe adds service.name and host.id attributes to metrics.

probes:
  - service: production
    role: redis
    command:
      command:
        - "mackerel-plugin-redis"
        - "-host={{ .Host.IPAddress.eth0 }}"
        - "-tempfile=/tmp/redis-{{ .Host.ID }}"
    attributes: # extra attributes
      - service.namespace: redis
      - host.name: "{{ .Host.Name }}"
Service metrics support in probes

service_metric: true in probe configuration enables to post metrics as service metrics.

probes:
  - service: production
    service_metric: true # post metrics as service metrics
    # ...

In this case, .Host is not available in probe configuration.

Backup metrics using Amazon Kinesis Firehose

When Mackerel API is down, maprobe can backup corrected metrics to Amazon Kinesis Firehose.

backup:
  firehose_stream_name: your-maprobe-backup

If maprobe cannot post metrics to Mackerel API, maprobe posts these metrics to Firehose stream as backup.

maprobe agent --with-firehose-endpoint or maprobe firehose-endpoint runs HTTP server for Firehose HTTP Endpoint.

You can configure the Firehose stream that send data to HTTP endpoint to maprobe's http server.

[maprobe] -XXX-> [Mackerel]
          \
        (backup)
            \---> [Firehose](buffer and retry) -(ELB)-> [maprobe HTTP] --> [Mackerel]

Firehose HTTP Endpoint has paths below.

  • /post : Post metrics endpoint. "Access key" must be same the as MACKEREL_APIKEY which set in maprobe.
  • /ping : Always return 200 OK (for health check).

maprobe accepts Firehose HTTP requests and the metrics will send to Mackerel API (when available).

Ping

Ping probe sends ICMP ping to the address.

ping:
  address: "192.168.1.1"      # Hostname or IP address (required)
  count: 5                    # Iteration count (default 3)
  timeout: "500ms"            # Timeout to ping response (default 1 sec)
  metric_key_prefix:          # default ping

Ping probe generates the following metrics.

  • ping.count.success (count)
  • ping.count.failure (count)
  • ping.rtt.min (seconds)
  • ping.rtt.max (seconds)
  • ping.rtt.avg (seconds)
TCP

TCP probe connects to host:port by TCP (or TLS).

tcp:
  host: "memcached.example.com" # Hostname or IP Address (required)
  port: 11211                   # Port number (required)
  timeout: 10s                  # Seconds of timeout (default 5)
  send: "VERSION\n"             # String to send to the server
  quit: "QUIT\n"                # String to send server to initiate a clean close of the connection"
  expect_pattern: "^VERSION 1"  # Regexp pattern to expect in server response
  tls: false                    # Use TLS for connection
  no_check_certificate: false   # Do not check certificate
  metric_key_prefix:            # default tcp

TCP probe generates the following metrics.

  • tcp.check.ok (0 or 1)
  • tcp.elapsed.seconds (seconds)
  • tcp.certificate.expires_in_days (days until TLS certificate expires, only for TLS connections)
HTTP

HTTP probe sends a HTTP request to url.

http:
  url: "http://example.com/"     # URL
  method: "GET"                  # Method of request (default GET)
  headers:                       # Map of request header
    Foo: "bar"
  body: ""                       # Body of request
  expect_pattern: "ok"           # Regexp pattern to expect in server response
  timeout: 10s                   # Seconds of request timeout (default 15)
  no_check_certificate: false    # Do not check certificate
  metric_key_prefix:             # default http

HTTP probe generates the following metrics.

  • http.check.ok (0 or 1)
  • http.response_time.seconds (seconds)
  • http.status.code (100~)
  • http.content.length (bytes)
  • http.certificate.expires_in_days (days until SSL/TLS certificate expires, only for HTTPS URLs)

When a status code is grather than 400, http.check.ok set to 0.

gRPC

gRPC probe checks the health of a gRPC service using the standard gRPC Health Checking Protocol.

grpc:
  address: "localhost:50051"     # gRPC server address (required)
  grpc_service: ""               # Service name for health check (empty for overall server health)
  timeout: 10s                   # Timeout (default 10s)
  tls: false                     # Use TLS for connection
  no_check_certificate: false    # Do not check certificate
  metadata:                      # gRPC metadata (for authentication, etc.)
    authorization: "Bearer token"
  metric_key_prefix:             # default grpc

gRPC probe generates the following metrics.

  • grpc.check.ok (0 or 1)
  • grpc.elapsed.seconds (seconds)
  • grpc.status.code (gRPC status code, 0 = OK)

The probe uses the standard gRPC Health Checking Protocol. When grpc_service is empty, it checks the overall server health. When specified, it checks the health of that specific service.

Command

Command probe executes command which outputs like Mackerel metric plugin.

command:
  command: "/path/to/metric-command -option=foo" # execute command
  timeout: "5s"                      # Seconds of command timeout (default 15)
  graph_defs: true                   # Post graph definitions to Mackerel (default false)
  env:  # environment variables for command execution
    FOO: foo
    BAR: bar

command accepts both a single string value and an array value. If an array value is passed, these are not processed by shell.

command:
  command:
    - "/path/to/metric-command"
    - "-option=foo"
  timeout: "5s"                      # Seconds of command timeout (default 15)
  graph_defs: true                   # Post graph definitions to Mackerel (default false)

Command probe handles command's output as host metric.

When graph_defs is true, maprobe runs a command with MACKEREL_AGENT_PLUGIN_META=1 environment variables and post graph definitions to Mackerel at first time.

If the command does not return a valid graph definitions output, that is ignored.

See also ホストのカスタムメトリックを投稿する - Mackerel ヘルプ.

Additional attributes for metrics

The command probe supports additional attributes for metrics.

If the command returns extra columns in key=value format at the end of each line, these will be treated as attributes for the metric.

For example, if the command outputs like below:

foo.bar	42	1755681797	key1=value1	key2=value2

The parsed metric will have the following attributes:

  • key1: value1
  • key2: value2

These attributes will be sent to the OpenTelemetry metrics endpoint only.

Example Configuration for aggregates
post_aggregated_metrics: false   # when false, do not post service metrics to Mackerel. only dump to [info] log.
aggregates:
  - service: production
    role: app-server
    metrics:
      - name: cpu.user.percentage
        outputs:
          - func: sum
            name: cpu.user.sum_percentage
          - func: avg
            name: cpu.user.avg_percentage
      - name: cpu.idle.percentage
        outputs:
          - func: sum
            name: cpu.idle.sum_percentage
          - func: avg
            name: cpu.idle.avg_percentage

This configuration posts service metrics (for service "production") as below.

  • cpu.user.sum_percentage = sum(cpu.user.percentage) of production:app-server
  • cpu.user.avg_percentage = avg(cpu.user.percentage) of production:app-server
  • cpu.idle.sum_percentage = sum(cpu.idle.percentage) of production:app-server
  • cpu.idle.avg_percentage = avg(cpu.idle.percentage) of production:app-server
functions for aggregates

Following functions are available to aggregate host metrics.

  • sum
  • min / minimum
  • max / maximum
  • avg / average
  • median
  • count

Author

Fujiwara Shunichiro fujiwara.shunichiro@gmail.com

License

Copyright 2018 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 CustomPrefix = "custom."

Variables

View Source
var (
	DefaultGRPCTimeout         = 10 * time.Second
	DefaultGRPCMetricKeyPrefix = "grpc"
)
View Source
var (
	DefaultHTTPTimeout         = 15 * time.Second
	DefaultHTTPMetricKeyPrefix = "http"
)
View Source
var (
	MaxConcurrency         = 100
	MaxClientConcurrency   = 5
	PostMetricBufferLength = 100
	ProbeInterval          = 60 * time.Second
	MackerelAPIKey         string
	MackerelOtelEndpoint   = "otlp.mackerelio.com:4317"
)
View Source
var (
	DefaultPingTimeout    = time.Second
	DefaultPingCount      = 3
	DefaultPingMetricName = "ping"
)
View Source
var (
	DefaultTCPTimeout         = 5 * time.Second
	DefaultTCPMaxBytes        = 32 * 1024
	DefaultTCPMetricKeyPrefix = "tcp"
)
View Source
var DefaultCommandTimeout = 15 * time.Second
View Source
var Version = "v0.10.4"

Functions

func GetSSMParameter added in v0.5.1

func GetSSMParameter(ctx context.Context, name string) (string, error)

func Main added in v0.8.0

func Main(ctx context.Context, args []string) error

Main is the main entry point that handles CLI parsing and command execution

func Run

func Run(ctx context.Context, wg *sync.WaitGroup, configPath string, once bool) error

func RunFirehoseEndpoint added in v0.4.0

func RunFirehoseEndpoint(ctx context.Context, wg *sync.WaitGroup, port int)

RunFirehoseEndpoint runs Firehose HTTP endpoint server.

func SetupLogger added in v0.8.0

func SetupLogger(logLevel, logFormat string)

SetupLogger configures structured logging

Types

type AgentCmd added in v0.8.0

type AgentCmd struct {
	Config               string `short:"c" help:"configuration file path or URL(http|s3)" env:"CONFIG"`
	WithFirehoseEndpoint bool   `help:"run with firehose HTTP endpoint server"`
	Port                 int    `help:"firehose HTTP endpoint listen port" default:"8080"`
}

AgentCmd represents the agent command that runs continuously

type AggregateDefinition added in v0.2.0

type AggregateDefinition struct {
	Service  exString        `yaml:"service"`
	Role     exString        `yaml:"role"`
	Roles    []exString      `yaml:"roles"`
	Statuses []exString      `yaml:"statuses"`
	Metrics  []*MetricConfig `yaml:"metrics"`
}

type Attribute added in v0.7.0

type Attribute struct {
	Service string
	HostID  string
	Extra   map[string]string
}

func (*Attribute) Otel added in v0.7.0

func (a *Attribute) Otel() *otelattribute.Set

func (*Attribute) SetExtra added in v0.7.0

func (a *Attribute) SetExtra(ex map[string]string, host *mackerel.Host)

func (Attribute) String added in v0.7.0

func (a Attribute) String() string

type BackupConfig added in v0.4.0

type BackupConfig struct {
	FirehoseStreamName string `yaml:"firehose_stream_name"`
}

type CLI added in v0.8.0

type CLI struct {
	LogLevel    string `name:"log-level" help:"log level" default:"info" env:"LOG_LEVEL"`
	LogFormat   string `name:"log-format" help:"log format (text|json)" default:"text" enum:"text,json" env:"LOG_FORMAT"`
	GopsEnabled bool   `name:"gops" help:"enable gops agent" default:"false" env:"GOPS"`

	Version          VersionCmd          `cmd:"" help:"Show version"`
	Agent            AgentCmd            `cmd:"" help:"Run agent"`
	Once             OnceCmd             `cmd:"" help:"Run once"`
	Lambda           LambdaCmd           `cmd:"" help:"Run on AWS Lambda like once mode"`
	Ping             PingCmd             `cmd:"" help:"Run ping probe"`
	TCP              TCPCmd              `cmd:"" help:"Run TCP probe"`
	HTTP             HTTPCmd             `cmd:"" help:"Run HTTP probe"`
	GRPC             GRPCCmd             `cmd:"" help:"Run gRPC probe"`
	FirehoseEndpoint FirehoseEndpointCmd `cmd:"" help:"Run Firehose HTTP endpoint"`
}

CLI defines the command line interface structure for Kong

type Channels added in v0.7.0

type Channels struct {
	ServiceMetrics chan ServiceMetric
	HostMetrics    chan HostMetric
	OtelMetrics    chan Metric
	Destination    *DestinationConfig
}

func NewChannels added in v0.7.0

func NewChannels(dst *DestinationConfig) *Channels

func (*Channels) Close added in v0.7.0

func (ch *Channels) Close()

func (*Channels) SendAggregatedMetric added in v0.7.0

func (ch *Channels) SendAggregatedMetric(m ServiceMetric)

func (*Channels) SendHostMetric added in v0.7.0

func (ch *Channels) SendHostMetric(m HostMetric)

func (*Channels) SendServiceMetric added in v0.7.0

func (ch *Channels) SendServiceMetric(m ServiceMetric)

type Client added in v0.4.0

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

func (*Client) FindHosts added in v0.4.0

func (client *Client) FindHosts(p *mackerel.FindHostsParam) ([]*mackerel.Host, error)

func (*Client) PostHostMetricValues added in v0.4.0

func (c *Client) PostHostMetricValues(ctx context.Context, mvs []*mackerel.HostMetricValue) error

func (*Client) PostServiceMetricValues added in v0.4.0

func (c *Client) PostServiceMetricValues(ctx context.Context, serviceName string, mvs []*mackerel.MetricValue) error

type CommandProbe

type CommandProbe struct {
	Command   []string
	Timeout   time.Duration
	GraphDefs bool
	// contains filtered or unexported fields
}

func (*CommandProbe) GetGraphDefs added in v0.1.0

func (p *CommandProbe) GetGraphDefs() (*GraphsOutput, error)

func (*CommandProbe) MetricName

func (p *CommandProbe) MetricName(name string) string

func (*CommandProbe) PostGraphDefs added in v0.1.0

func (p *CommandProbe) PostGraphDefs(client *mackerel.Client, pc *CommandProbeConfig) error

func (*CommandProbe) Run

func (p *CommandProbe) Run(ctx context.Context) (ms Metrics, err error)

func (*CommandProbe) String

func (p *CommandProbe) String() string

func (*CommandProbe) TempDir added in v0.3.5

func (p *CommandProbe) TempDir() string

type CommandProbeConfig

type CommandProbeConfig struct {
	RawCommand interface{} `yaml:"command"`

	Timeout   time.Duration     `yaml:"timeout"`
	GraphDefs bool              `yaml:"graph_defs"`
	Env       map[string]string `yaml:"env"`
	// contains filtered or unexported fields
}

func (*CommandProbeConfig) GenerateProbe

func (pc *CommandProbeConfig) GenerateProbe(host *mackerel.Host, client *mackerel.Client) (Probe, error)

type Config

type Config struct {
	Probes            []*ProbeDefinition `yaml:"probes"`
	PostProbedMetrics bool               `yaml:"post_probed_metrics"`

	Aggregates            []*AggregateDefinition `yaml:"aggregates"`
	PostAggregatedMetrics bool                   `yaml:"post_aggregated_metrics"`

	ProbeOnly *bool `yaml:"probe_only"` // deprecated

	Backup      *BackupConfig      `yaml:"backup"`
	Destination *DestinationConfig `yaml:"destination"`
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(ctx context.Context, location string) (*Config, string, error)

func (*Config) String added in v0.0.1

func (c *Config) String() string

type DestinationConfig added in v0.7.0

type DestinationConfig struct {
	Mackerel *MackerelConfig `yaml:"mackerel"`
	Otel     *OtelConfig     `yaml:"otel"`
}

type FirehoseEndpointCmd added in v0.8.0

type FirehoseEndpointCmd struct {
	Port int `short:"p" help:"Listen port" default:"8080"`
}

FirehoseEndpointCmd represents the firehose endpoint command for HTTP server

type GRPCCmd added in v0.9.0

type GRPCCmd struct {
	Address            string            `arg:"" help:"gRPC server address (host:port)" required:""`
	GRPCService        string            `short:"s" name:"service" help:"gRPC service name for health check"`
	Timeout            time.Duration     `short:"t" help:"Timeout"`
	NoCheckCertificate bool              `short:"k" help:"Do not check certificate"`
	Metadata           map[string]string `short:"m" name:"metadata" help:"gRPC metadata" placeholder:"key:value"`
	HostID             string            `short:"i" help:"Mackerel host ID"`
	TLS                bool              `help:"Use TLS"`
}

GRPCCmd represents the gRPC command for standalone gRPC probe

type GRPCProbe added in v0.9.0

type GRPCProbe struct {
	Address            string
	GRPCService        string
	Timeout            time.Duration
	TLS                bool
	NoCheckCertificate bool
	Metadata           map[string]string
	// contains filtered or unexported fields
}

func (*GRPCProbe) HostID added in v0.9.0

func (p *GRPCProbe) HostID() string

func (*GRPCProbe) MetricName added in v0.9.0

func (p *GRPCProbe) MetricName(name string) string

func (*GRPCProbe) Run added in v0.9.0

func (p *GRPCProbe) Run(ctx context.Context) (ms Metrics, err error)

func (*GRPCProbe) String added in v0.9.0

func (p *GRPCProbe) String() string

type GRPCProbeConfig added in v0.9.0

type GRPCProbeConfig struct {
	Address            string            `yaml:"address"`
	GRPCService        string            `yaml:"grpc_service"`
	Timeout            time.Duration     `yaml:"timeout"`
	TLS                bool              `yaml:"tls"`
	NoCheckCertificate bool              `yaml:"no_check_certificate"`
	Metadata           map[string]string `yaml:"metadata"`
	MetricKeyPrefix    string            `yaml:"metric_key_prefix"`
}

func (*GRPCProbeConfig) GenerateProbe added in v0.9.0

func (pc *GRPCProbeConfig) GenerateProbe(host *mackerel.Host) (Probe, error)

type Graph added in v0.1.0

type Graph struct {
	Label   string            `json:"label"`
	Unit    string            `json:"unit"`
	Metrics []GraphDefsMetric `json:"metrics"`
}

type GraphDefsMetric added in v0.1.0

type GraphDefsMetric struct {
	Name    string `json:"name"`
	Label   string `json:"label"`
	Stacked bool   `json:"stacked"`
}

type GraphsOutput added in v0.1.0

type GraphsOutput struct {
	Graphs map[string]Graph `json:"graphs"`
}

type HTTPCmd added in v0.8.0

type HTTPCmd struct {
	URL                string            `arg:"" help:"URL" required:""`
	Method             string            `short:"m" help:"Request method" default:"GET"`
	Body               string            `short:"b" help:"Request body"`
	ExpectPattern      string            `short:"e" name:"expect" help:"Regexp pattern to expect in server response"`
	Timeout            time.Duration     `short:"t" help:"Timeout"`
	NoCheckCertificate bool              `short:"k" help:"Do not check certificate"`
	Headers            map[string]string `short:"H" name:"header" help:"Request headers" placeholder:"Header: Value"`
	HostID             string            `short:"i" help:"Mackerel host ID"`
}

HTTPCmd represents the HTTP command for standalone HTTP probe

type HTTPProbe

type HTTPProbe struct {
	URL                string
	Method             string
	Headers            map[string]string
	Body               string
	ExpectPattern      *regexp.Regexp
	Timeout            time.Duration
	NoCheckCertificate bool
	// contains filtered or unexported fields
}

func (*HTTPProbe) HostID

func (p *HTTPProbe) HostID() string

func (*HTTPProbe) MetricName

func (p *HTTPProbe) MetricName(name string) string

func (*HTTPProbe) Run

func (p *HTTPProbe) Run(ctx context.Context) (ms Metrics, err error)

func (*HTTPProbe) String

func (p *HTTPProbe) String() string

type HTTPProbeConfig

type HTTPProbeConfig struct {
	URL                string            `yaml:"url"`
	Method             string            `yaml:"method"`
	Headers            map[string]string `yaml:"headers"`
	Body               string            `yaml:"body"`
	ExpectPattern      string            `yaml:"expect_pattern"`
	Timeout            time.Duration     `yaml:"timeout"`
	NoCheckCertificate bool              `yaml:"no_check_certificate"`
	MetricKeyPrefix    string            `yaml:"metric_key_prefix"`
}

func (*HTTPProbeConfig) GenerateProbe

func (pc *HTTPProbeConfig) GenerateProbe(host *mackerel.Host) (Probe, error)

type HostMetric added in v0.2.0

type HostMetric struct {
	HostID string
	Metric
}

func (HostMetric) HostMetricValue added in v0.2.0

func (m HostMetric) HostMetricValue() *mackerel.HostMetricValue

func (HostMetric) String added in v0.2.0

func (m HostMetric) String() string

type HostMetrics added in v0.2.0

type HostMetrics []HostMetric

func (HostMetrics) String added in v0.2.0

func (ms HostMetrics) String() string

type LambdaCmd added in v0.8.0

type LambdaCmd struct {
	Config string `short:"c" help:"configuration file path or URL(http|s3)" env:"CONFIG"`
}

LambdaCmd represents the lambda command that runs on AWS Lambda

type MackerelConfig added in v0.7.0

type MackerelConfig struct {
	Enabled bool `yaml:"enabled"`
}

type Metric

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

func (Metric) HostMetric added in v0.6.0

func (m Metric) HostMetric(hostID string) HostMetric

func (Metric) Otel added in v0.7.0

func (m Metric) Otel() otelmetricdata.Metrics

func (Metric) OtelString added in v0.7.0

func (m Metric) OtelString() string

func (Metric) ServiceMetric added in v0.6.0

func (m Metric) ServiceMetric(service string) ServiceMetric

func (Metric) String

func (m Metric) String() string

type MetricConfig added in v0.2.0

type MetricConfig struct {
	Name    exString        `yaml:"name"`
	Outputs []*OutputConfig `yaml:"outputs"`
}

type Metrics

type Metrics []Metric

func (Metrics) String

func (ms Metrics) String() string

type OnceCmd added in v0.8.0

type OnceCmd struct {
	Config string `short:"c" help:"configuration file path or URL(http|s3)" env:"CONFIG"`
}

OnceCmd represents the once command that runs probes once and exits

type OtelConfig added in v0.7.0

type OtelConfig struct {
	Enabled            bool              `yaml:"enabled"`
	Endpoint           string            `yaml:"endpoint"`
	Insecure           bool              `yaml:"insecure"`
	ResourceAttributes map[string]string `yaml:"resource_attributes"`
	StatsAttributes    map[string]string `yaml:"stats_attributes"`
}

type OtelMetric added in v0.7.0

type OtelMetric interface {
	ServiceMetric | HostMetric
}

type OutputConfig added in v0.2.0

type OutputConfig struct {
	Func     exString `yaml:"func"`
	Name     exString `yaml:"name"`
	EmitZero bool     `yaml:"emit_zero"`
	// contains filtered or unexported fields
}

type PingCmd added in v0.8.0

type PingCmd struct {
	Address string        `arg:"" help:"Hostname or IP address" required:""`
	Count   int           `short:"c" help:"Iteration count"`
	Timeout time.Duration `short:"t" help:"Timeout to ping response"`
	HostID  string        `short:"i" help:"Mackerel host ID"`
}

PingCmd represents the ping command for standalone ping probe

type PingProbe

type PingProbe struct {
	Address string
	Count   int
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*PingProbe) MetricName

func (p *PingProbe) MetricName(name string) string

func (*PingProbe) Run

func (p *PingProbe) Run(ctx context.Context) (Metrics, error)

func (*PingProbe) String

func (p *PingProbe) String() string

type PingProbeConfig

type PingProbeConfig struct {
	Address         string        `yaml:"address"`
	Count           int           `yaml:"count"`
	Timeout         time.Duration `yaml:"timeout"`
	MetricKeyPrefix string        `yaml:"metric_key_prefix"`
}

func (*PingProbeConfig) GenerateProbe

func (pc *PingProbeConfig) GenerateProbe(host *mackerel.Host) (Probe, error)

type Probe

type Probe interface {
	Run(ctx context.Context) (Metrics, error)
	MetricName(string) string
}

type ProbeConfig

type ProbeConfig interface {
	GenerateProbe(host *mackerel.Host) (Probe, error)
}

type ProbeDefinition

type ProbeDefinition struct {
	Service  exString   `yaml:"service"`
	Role     exString   `yaml:"role"`
	Roles    []exString `yaml:"roles"`
	Statuses []exString `yaml:"statuses"`

	IsServiceMetric bool `yaml:"service_metric"`

	Ping    *PingProbeConfig    `yaml:"ping"`
	TCP     *TCPProbeConfig     `yaml:"tcp"`
	HTTP    *HTTPProbeConfig    `yaml:"http"`
	Command *CommandProbeConfig `yaml:"command"`
	GRPC    *GRPCProbeConfig    `yaml:"grpc"`

	Attributes map[string]string `yaml:"attributes"`
}

func (*ProbeDefinition) GenerateProbes

func (pd *ProbeDefinition) GenerateProbes(host *mackerel.Host, client *mackerel.Client) []Probe

func (*ProbeDefinition) RunHostProbes added in v0.6.0

func (pd *ProbeDefinition) RunHostProbes(ctx context.Context, client *Client, stats *StatsCollector) []HostMetric

func (*ProbeDefinition) RunProbes added in v0.6.0

func (pd *ProbeDefinition) RunProbes(ctx context.Context, client *Client, chs *Channels, stats *StatsCollector, wg *sync.WaitGroup)

func (*ProbeDefinition) RunServiceProbes added in v0.6.0

func (pd *ProbeDefinition) RunServiceProbes(ctx context.Context, client *Client, stats *StatsCollector) []ServiceMetric

func (*ProbeDefinition) Validate added in v0.6.0

func (pd *ProbeDefinition) Validate() error

type ServiceMetric added in v0.2.0

type ServiceMetric struct {
	Service string
	Metric
}

func (ServiceMetric) MetricValue added in v0.2.0

func (m ServiceMetric) MetricValue() *mackerel.MetricValue

func (ServiceMetric) String added in v0.2.0

func (m ServiceMetric) String() string

type ServiceMetrics added in v0.2.0

type ServiceMetrics []ServiceMetric

func (ServiceMetrics) String added in v0.2.0

func (ms ServiceMetrics) String() string

type StatsCollector added in v0.8.0

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

StatsCollector manages maprobe internal metrics

func NewStatsCollector added in v0.8.0

func NewStatsCollector(provider *otelsdkmetric.MeterProvider, attrs map[string]string) (*StatsCollector, error)

NewStatsCollector creates a new StatsCollector

func (*StatsCollector) RecordMetricCollected added in v0.8.0

func (s *StatsCollector) RecordMetricCollected(ctx context.Context)

RecordMetricCollected records that a metric was collected

func (*StatsCollector) RecordProbeExecution added in v0.8.0

func (s *StatsCollector) RecordProbeExecution(ctx context.Context, probe Probe, probeErr error)

RecordProbeExecution records a probe execution result

func (*StatsCollector) SetProbeConfigs added in v0.8.0

func (s *StatsCollector) SetProbeConfigs(count int64)

SetProbeConfigs sets the number of configured probes

func (*StatsCollector) SetTargetCounts added in v0.8.0

func (s *StatsCollector) SetTargetCounts(hosts, services int64)

SetTargetCounts sets the number of target hosts and services

type TCPCmd added in v0.8.0

type TCPCmd struct {
	Host               string        `arg:"" help:"Hostname or IP address" required:""`
	Port               string        `arg:"" help:"Port number" required:""`
	Send               string        `short:"s" help:"String to send to the server"`
	Quit               string        `short:"q" help:"String to send server to initiate a clean close of the connection"`
	Timeout            time.Duration `short:"t" help:"Timeout"`
	ExpectPattern      string        `short:"e" name:"expect" help:"Regexp pattern to expect in server response"`
	NoCheckCertificate bool          `short:"k" help:"Do not check certificate"`
	HostID             string        `short:"i" help:"Mackerel host ID"`
	TLS                bool          `help:"Use TLS"`
}

TCPCmd represents the TCP command for standalone TCP probe

type TCPProbe

type TCPProbe struct {
	Host               string
	Port               string
	Send               string
	Quit               string
	MaxBytes           int
	ExpectPattern      *regexp.Regexp
	Timeout            time.Duration
	TLS                bool
	NoCheckCertificate bool
	// contains filtered or unexported fields
}

func (*TCPProbe) HostID

func (p *TCPProbe) HostID() string

func (*TCPProbe) MetricName

func (p *TCPProbe) MetricName(name string) string

func (*TCPProbe) Run

func (p *TCPProbe) Run(ctx context.Context) (ms Metrics, err error)

func (*TCPProbe) String

func (p *TCPProbe) String() string

type TCPProbeConfig

type TCPProbeConfig struct {
	Host               string        `yaml:"host"`
	Port               string        `yaml:"port"`
	Timeout            time.Duration `yaml:"timeout"`
	Send               string        `yaml:"send"`
	Quit               string        `yaml:"quiet"`
	MaxBytes           int           `yaml:"max_bytes"`
	ExpectPattern      string        `yaml:"expect_pattern"`
	TLS                bool          `yaml:"tls"`
	NoCheckCertificate bool          `yaml:"no_check_certificate"`
	MetricKeyPrefix    string        `yaml:"metric_key_prefix"`
}

func (*TCPProbeConfig) GenerateProbe

func (pc *TCPProbeConfig) GenerateProbe(host *mackerel.Host) (Probe, error)

type VersionCmd added in v0.8.0

type VersionCmd struct{}

VersionCmd represents the version command

Directories

Path Synopsis
cmd
maprobe command

Jump to

Keyboard shortcuts

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