metricsink

package module
v0.0.0-...-ad0cdb5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

README

Metric Collector for Go-Chassis

Build Status
This a metric collector for Go-Chassis which collects metrics of the microservices. It can collect metrics for each api's exposed by the micro-services. The same data can be exposed to Huawei CSE Governance Dashboard.

How to use

in main.go

import _ "github.com/huaweicse/cse-collector"

Introdction

The metrics collected by this collector is listed below:

attempts
errors
successes
failures
rejects
shortCircuits
timeouts
fallbackSuccesses
fallbackFailures
totalDuration
runDuration

It also collects data for each api's:

Name                 string  `json:"name"`
Desc                 string  `json:"desc"`
Qps                  float64 `json:"qps"`
Latency              int     `json:"latency"`
L995                 int     `json:"l995"`
L99                  int     `json:"l99"`
L90                  int     `json:"l90"`
L75                  int     `json:"l75"`
L50                  int     `json:"l50"`
L25                  int     `json:"l25"`
L5                   int     `json:"l5"`
Rate                 float64 `json:"rate"`
Total                int64   `json:"total"`
Failure              int64   `json:"failure"`
ShortCircuited       int64   `json:"shortCircuited"`
IsCircuitBreakerOpen bool    `json:"isCircuitBreakerOpen"`
SemaphoreRejected    int64   `json:"semaphoreRejected"`
ThreadPoolRejected   int64   `json:"threadPoolRejected"`
CountTimeout         int64   `json:"countTimeout"`

Configurations

You need to configure your microservice to send the data at regular interval to Huawei CSE Dashboard.

cse:
  monitor:
    client:
      serverUri: https://cse.cn-north-1.myhwclouds.com:443
      enable: true

Data Post

Every 2 sec data will be posted to monitoring server if serverUri is correct and enable is true

The data formate after post

[
    [
        {
            "time": 1526905902632,
            "appId": "default",
            "version": "0.0.1",
            "qps": 0.16,
            "latency": 0,
            "failureRate": 0,
            "total": 2,
            "breakerRateAgg": 0,
            "circuitBreakerOpen": false,
            "failure": 0,
            "shortCircuited": 0,
            "semaphoreRejected": 0,
            "threadPoolRejected": 0,
            "countTimeout": 0,
            "l995": 0,
            "l99": 0,
            "l90": 0,
            "l75": 0,
            "l50": 0,
            "l25": 0,
            "l5": 0,
            "instanceId": "6a0895085cf211e8bb850255ac105551",
            "thread": 11,
            "cpu": 4,
            "memory": {
                "heapAlloc": 2294040,
                "heapIdle": 1671168,
                "heapInUse": 3768320,
                "heapObjects": 19609,
                "heapReleased": 0,
                "heapSys": 5439488
            },
            "functionCount": 1,
            "customs": null,
            "name": "root1-ThinkPad-T440p"
        }
    ]
]

Data Flush

Every 10sec data will be flushed

[
    [
        {
            "time": 1526905933600,
            "appId": "default",
            "version": "0.0.1",
            "qps": 0,
            "latency": 0,
            "failureRate": 0,
            "total": 0,
            "breakerRateAgg": 0,
            "circuitBreakerOpen": false,
            "failure": 0,
            "shortCircuited": 0,
            "semaphoreRejected": 0,
            "threadPoolRejected": 0,
            "countTimeout": 0,
            "l995": 0,
            "l99": 0,
            "l90": 0,
            "l75": 0,
            "l50": 0,
            "l25": 0,
            "l5": 0,
            "instanceId": "6a0895085cf211e8bb850255ac105551",
            "thread": 11,
            "cpu": 4,
            "memory": {
                "heapAlloc": 2649632,
                "heapIdle": 1597440,
                "heapInUse": 3874816,
                "heapObjects": 24737,
                "heapReleased": 0,
                "heapSys": 5472256
            },
            "functionCount": 1,
            "customs": null,
            "name": "root1-ThinkPad-T440p"
        }
    ]
]

If perticular micro service has more than one instance and if request has been sent to perticular instance then only for that instance all the value should change.

Documentation

Index

Constants

View Source
const (
	PostRemoteTimeout = 20 * time.Second
	IdleConnsPerHost  = 100
	DefaultTimeout    = time.Second * 20
	MetricsPath       = "/csemonitor/metric"
	EnvProjectID      = "CSE_PROJECT_ID"
)

constant for the cse-collector

View Source
const (
	//HeaderUserName is a variable of type string
	HeaderUserName   = "x-user-name"
	HeaderDomainName = "x-domain-name"
	ContentType      = "Content-Type"
	Name             = "monitor"
)

constants for header parameters

Variables

View Source
var IsMonitoringConnected bool

IsMonitoringConnected is a boolean to keep an check if there exsist any succeful connection to monitoring Server

View Source
var (
	MetricServerPath = ""
)

variables for cse-collector

Functions

func InitializeCseCollector

func InitializeCseCollector(config *CseCollectorConfig, r metrics.Registry, app, version, service, env string)

InitializeCseCollector starts the CSE collector in a new Thread

func NewCseCollector

func NewCseCollector(name string) metricCollector.MetricCollector

NewCseCollector creates a new Collector Object

func TransportFor

func TransportFor(tlsconfig *tls.Config) http.RoundTripper

TransportFor creates an transport object with TLS information

Types

type CseCollector

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

CseCollector is a struct to keeps metric information of Http requests

func (*CseCollector) IncrementAttempts

func (c *CseCollector) IncrementAttempts()

IncrementAttempts function increments the number of calls to this circuit. This registers as a counter

func (*CseCollector) IncrementErrors

func (c *CseCollector) IncrementErrors()

IncrementErrors function increments the number of unsuccessful attempts. Attempts minus Errors will equal successes. Errors are result from an attempt that is not a success. This registers as a counter

func (*CseCollector) IncrementFailures

func (c *CseCollector) IncrementFailures()

IncrementFailures function increments the number of requests that fail. This registers as a counter

func (*CseCollector) IncrementFallbackFailures

func (c *CseCollector) IncrementFallbackFailures()

IncrementFallbackFailures function increments the number of failures that occurred during the execution of the fallback function. This registers as a counter

func (*CseCollector) IncrementFallbackSuccesses

func (c *CseCollector) IncrementFallbackSuccesses()

IncrementFallbackSuccesses function increments the number of successes that occurred during the execution of the fallback function. This registers as a counter

func (*CseCollector) IncrementRejects

func (c *CseCollector) IncrementRejects()

IncrementRejects function increments the number of requests that are rejected. This registers as a counter

func (*CseCollector) IncrementShortCircuits

func (c *CseCollector) IncrementShortCircuits()

IncrementShortCircuits function increments the number of requests that short circuited due to the circuit being open. This registers as a counter

func (*CseCollector) IncrementSuccesses

func (c *CseCollector) IncrementSuccesses()

IncrementSuccesses function increments the number of requests that succeed. This registers as a counter

func (*CseCollector) IncrementTimeouts

func (c *CseCollector) IncrementTimeouts()

IncrementTimeouts function increments the number of timeouts that occurred in the circuit breaker. This registers as a counter

func (*CseCollector) Reset

func (c *CseCollector) Reset()

Reset function is a noop operation in this collector.

func (*CseCollector) UpdateRunDuration

func (c *CseCollector) UpdateRunDuration(runDuration time.Duration)

UpdateRunDuration function updates the internal counter of how long the last run took. This registers as a timer

func (*CseCollector) UpdateTotalDuration

func (c *CseCollector) UpdateTotalDuration(timeSinceStart time.Duration)

UpdateTotalDuration function updates the internal counter of how long we've run for. This registers as a timer

type CseCollectorConfig

type CseCollectorConfig struct {
	// CseMonitorAddr is the http address of the csemonitor server
	CseMonitorAddr string
	// Headers for csemonitor server
	Header http.Header
	// TickInterval spcifies the period that this collector will send metrics to the server.
	TimeInterval time.Duration
	// Config structure to configure a TLS client for sending Metric data
	TLSConfig *tls.Config
}

CseCollectorConfig is a struct to keep monitoring information

type CseMonitorClient

type CseMonitorClient struct {
	Header http.Header
	URL    string
	Client *http.Client
}

CseMonitorClient is an object for storing client information

func NewCseMonitorClient

func NewCseMonitorClient(header http.Header, url string, tlsConfig *tls.Config, version string) *CseMonitorClient

NewCseMonitorClient creates an new client for monitoring

func (*CseMonitorClient) PostMetrics

func (cseMonitorClient *CseMonitorClient) PostMetrics(monitorData MonitorData) (err error)

PostMetrics is a functions which sends the monintoring data to monitoring Server

type InterfaceInfo

type InterfaceInfo struct {
	Name                 string  `json:"name"`
	Desc                 string  `json:"desc"`
	QPS                  float64 `json:"qps"`
	Latency              int     `json:"latency"`
	L995                 int     `json:"l995"`
	L99                  int     `json:"l99"`
	L90                  int     `json:"l90"`
	L75                  int     `json:"l75"`
	L50                  int     `json:"l50"`
	L25                  int     `json:"l25"`
	L5                   int     `json:"l5"`
	Rate                 float64 `json:"rate"`
	Total                int64   `json:"total"`
	Failure              int64   `json:"failure"`
	ShortCircuited       int64   `json:"shortCircuited"`
	IsCircuitBreakerOpen bool    `json:"circuitBreakerOpen"`
	SemaphoreRejected    int64   `json:"semaphoreRejected"`
	ThreadPoolRejected   int64   `json:"threadPoolRejected"`
	CountTimeout         int64   `json:"countTimeout"`
	FailureRate          float64 `json:"failureRate"`
	// contains filtered or unexported fields
}

InterfaceInfo is an object which store the monitoring information of a particular interface

type MonitorData

type MonitorData struct {
	AppID       string                 `json:"appId"`
	Version     string                 `json:"version"`
	Name        string                 `json:"name"`
	Environment string                 `json:"environment"`
	Instance    string                 `json:"instance"`
	Thread      int                    `json:"thread"`
	Customs     map[string]interface{} `json:"customs"` // ?
	Interfaces  []*InterfaceInfo       `json:"interfaces"`
	CPU         float64                `json:"cpu"`
	Memory      map[string]interface{} `json:"memory"`
	ServiceID   string                 `json:"serviceId"`
	InstanceID  string                 `json:"instanceId"`
}

MonitorData is an object which stores the monitoring information for an application

func NewMonitorData

func NewMonitorData() *MonitorData

NewMonitorData creates a new monitoring object

type Reporter

type Reporter struct {
	Registry       metrics.Registry
	CseMonitorAddr string
	Header         http.Header
	Interval       time.Duration
	Percentiles    []float64
	TLSConfig      *tls.Config
	// contains filtered or unexported fields
}

Reporter is a struct to store the registry address and different monitoring information

func NewReporter

func NewReporter(r metrics.Registry, addr string, header http.Header, interval time.Duration, tls *tls.Config, app, version, service, env string) *Reporter

NewReporter creates a new monitoring object for CSE type collections

func (*Reporter) Run

func (reporter *Reporter) Run()

Run creates a go_routine which runs continuously and capture the monitoring data

Jump to

Keyboard shortcuts

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