collector

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

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

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 29 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

spring-cloud-monitor

Build Status GoDoc Documentation Sourcegraph GitHub release

一个基于eureka服务发现对微服务应用JVM和WEB请求指标、微服务运行状态的监控,并通过图形化来展示的小型轻量级监控系统。

特性

  • 服务发现
  • influxdb读写支持基于微服务名称的HASH算法分片
  • grafana支持influxdb分片导航
  • 微服务运行状态图
  • jvm监控图

架构

安装

依赖安装

spring-cloud-monitor安装依赖如下服务,请按照官网安装文档安装:

spring-cloud-monitor程序安装
编译安装

安装golang >1.9.x,执行build.sh编译.

$ cd /path/to/spring-cloud-monitor/app

$ ./build.sh

微服务健康状态图

微服务监控状态Dashboard中直接从redis(单机版直接从内存中)取出微服务列表,再根据微服务获取实例健康状态值。在Dashboard界面上设计了10种渐变颜色来说明服务的健康状态如下图所示:

从红色到绿色,分别来说明健康状态,红色表示所有服务已经不可用了,绿色代表所有服务可用,中间态表示部分服务可用,部分服务不可用。变红表示开始有些实例不可用了,变绿表示不可用实例开始恢复了。

并使用3个区间来分别表示1分钟、5分钟、15分钟服务健康状态,如下所示:

并计算所有实例1分钟的健康状态值的平均数来做为微服务的健康状态,如下所示,有一个实例已经挂了:

如下所示,所有实例已经挂了:

如下所示,其中一个实例刚刚在1分钟内down了:

如下所示,其中一个实例已经挂了快5分钟了:

如下所示,其中一个实例已经挂了快5分钟了,但已经开始恢复了:

如下所示,其中一个已经挂了的实例,在1分钟前恢复了:

如下所示,如果应用未开放/health(或者无法连接),显示会灰色:

监控图展示:

总体

平均响应时间:

每分钟调用次数(QPM):

部署实例状态图:

正常:

有2个实例不在线:

实例状态趋势图:

CPU处理平均核数和平均使用率:

Documentation

Index

Constants

View Source
const (
	CONF_METRICS_GROUP_PREFEX     = "metrics."
	KEY_EUREKA_URL                = "eureka.urls"
	KEY_EUREKA_DISCOVERY_INTERVAL = "eureka.interval"
	DISCOVERY_INTERVAL_DEFAULT    = 10 * time.Second

	CONF_INFLUX_URLS = "influx.urls"

	CONF_COLLECT_INTERVAL      = "collector.interval"
	DEFAULT_COLLECT_INTERVAL   = 10 * time.Second
	CONF_COLLECT_CRON_TEMPLATE = "%d/%d * * * * ?"
	LB_FACTOR                  = 10
)
View Source
const (
	CONF_METRICS_JVM_GROUP    = "metrics.jvm.group"
	CONF_METRICS_JVM_TEMPLATE = "metrics.jvm.%s"

	SERVICE_VALUE            = "doing"
	CONF_HEALTH_4XX_SLEEP    = "checker.health.4xx.sleep"
	DEFAULT_HEALTH_4XX_SLEEP = 10 * time.Minute

	HOSTS = "hosts,app=%s,host=%s status=%d"
)
View Source
const (
	HEALTH_TOTAL = "healths,app=%s up=%d,down=%d"
	HOSTS_STATUS = "hosts,app=%s,host=%s status=%d"
)
View Source
const (
	INFLUX_DB_DEFAULT              = "default_all"
	INFLUX_WRITE_URL_TEMPLATE      = "%s/write?db=%s"
	INFLUX_QUERY_GET_URL_TEMPLATE  = "%s/query?db=%s"
	INFLUX_QUERY_POST_URL_TEMPLATE = "%s/query"
	CREATE_DATABASE_TEMPLATE       = "CREATE DATABASE %s"
	DROP_DATABASE_TEMPLATE         = "DROP DATABASE %s"
)
View Source
const (
	CONF_EUREKA_URLS_TEMPLATE   = "eureka.urls"
	CONF_EUREKA_INTERVAL_SECOND = "eureka.interval.second"
	CONF_CHECK_INTERVAL_SECOND  = "checker.interval.second"
	//CONF_HEALTH_4XX_SLEEP       = "checker.health.4xx.sleep"
	CONF_REDIS_ENABLED  = "redis.enabled"
	CONF_REDIS_ADDR     = "redis.addr"
	CONF_REDIS_PASSWORD = "redis.password"
	CONF_REDIS_DB       = "redis.db"
	DEFAULT_REDIS_DB    = 0

	//DEFAULT_HEALTH_4XX_SLEEP = 10 * time.Minute
	DATE_FORMAT = "2006-01-02.15:04:05.999999"
	//
	REDIS_KEY_HEALTH_SERVICES = "health:services"
)
View Source
const (
	REQUEST_FORMAT     = "request,host=%s,api=%s res=%f,count=%f,interval=%f"
	APP_REQUEST_FORMAT = "app_request,app=%s res=%f,count=%f,interval=%f"
	METRICS_API_PREFIX = "gauge.servo.response"
)
View Source
const (
	APP_JVM_FORMAT = "jvm,host=%s "
)

Variables

This section is empty.

Functions

func Runes32

func Runes32(data []rune) uint32

Types

type AbstractExtractor

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

type Collector

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

func NewCollector

func NewCollector(conf kvs.ConfigSource) *Collector

func NewCollectorByFile

func NewCollectorByFile(name string) *Collector

func (*Collector) AddOrUpdateCollector

func (c *Collector) AddOrUpdateCollector(app *eureka.Application)

func (*Collector) GetJvmMetrics

func (iw *Collector) GetJvmMetrics()

func (*Collector) Start

func (e *Collector) Start()

func (*Collector) StartEureka

func (e *Collector) StartEureka(callbacks ...func(*eureka.Applications))

type Extractor

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

type HealthChecker

type HealthChecker struct {
	Services map[string]*Service
	// contains filtered or unexported fields
}

func NewHealthChecker

func NewHealthChecker(conf kvs.ConfigSource) *HealthChecker

func (*HealthChecker) GetServices

func (h *HealthChecker) GetServices() map[string]*Service

func (*HealthChecker) ResetServices

func (h *HealthChecker) ResetServices(services map[string]*Service) map[string]*Service

func (*HealthChecker) Start

func (h *HealthChecker) Start()

type Host

type Host struct {
	Id             string
	HomePageUrl    string
	HealthCheckUrl string
	// contains filtered or unexported fields
}

type Influx

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

func NewInflux

func NewInflux(urls []string) *Influx

func (*Influx) GetDbWriteUrl

func (iw *Influx) GetDbWriteUrl(appName, dbName string) string

func (*Influx) GetDefaultDbUrl

func (iw *Influx) GetDefaultDbUrl(appName string) string

type Instance

type Instance struct {
	Id     string `json:"-"`
	Name   string
	Status bool `json:"-"`
	//当前健康度,共10分,满10分表示ok,0表示全不ok
	//1,5,15分钟内的健康度
	Health1m       int `json:"1m"`
	Health5m       int `json:"5m"`
	Health15m      int `json:"15m"`
	HealthCheckUrl string

	InstanceInfo *eureka.InstanceInfo `json:"-"`
	// contains filtered or unexported fields
}

type JvmExtractor

type JvmExtractor struct {
	AbstractExtractor
	// contains filtered or unexported fields
}

func NewJvmExtractor

func NewJvmExtractor(serviceName, hostName, timestamp, metricUrl string, interval int, influx *Influx) *JvmExtractor

type KV

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

type MetricsGroup

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

type RequestExtractor

type RequestExtractor struct {
	AbstractExtractor
	// contains filtered or unexported fields
}

func NewRequestExtractor

func NewRequestExtractor(serviceName, hostName string, timestamp string, metricUrl string, influx *Influx) *RequestExtractor

type Service

type Service struct {
	Name   string
	Status bool
	//当前健康度,共10分,满10分表示ok,0表示全不ok
	//1,5,15分钟内的健康度
	Health1m  int
	Health5m  int
	Health15m int
	Instances []*Instance

	//config
	ServiceId string
	// contains filtered or unexported fields
}

func (*Service) HealthOk

func (h *Service) HealthOk(instance *Instance, url string) bool

func (*Service) Start

func (h *Service) Start()

type ServiceCollector

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

func NewServiceCollector

func NewServiceCollector(serviceName string, collector *Collector) *ServiceCollector

func (*ServiceCollector) AddHost

func (ca *ServiceCollector) AddHost(host *Host)

func (*ServiceCollector) AddOrUpdateHost

func (ca *ServiceCollector) AddOrUpdateHost(app *eureka.Application)

func (*ServiceCollector) HealthOk

func (iw *ServiceCollector) HealthOk(url string) bool

func (*ServiceCollector) Printf

func (ca *ServiceCollector) Printf(format string, v ...interface{})

func (*ServiceCollector) Start

func (ca *ServiceCollector) Start()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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