bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/memcached_unix.go (about)

     1  // +build !windows
     2  
     3  package collectors
     4  
     5  import (
     6  	"strconv"
     7  	"strings"
     8  
     9  	"bosun.org/metadata"
    10  	"bosun.org/opentsdb"
    11  	"bosun.org/util"
    12  )
    13  
    14  func init() {
    15  	collectors = append(collectors, &IntervalCollector{F: c_memcached_stats})
    16  }
    17  
    18  var memcachedMeta = map[string]MetricMeta{
    19  	"accepting_conns": {
    20  		RateType: metadata.Gauge,
    21  		Unit:     metadata.Bool,
    22  		Desc:     "Indicates if the memcache instance is currently accepting connections.",
    23  	},
    24  	"auth_cmds": {
    25  		RateType: metadata.Counter,
    26  		Unit:     metadata.Operation,
    27  		Desc:     "The number of authentication commands handled (includes both success or failure).",
    28  	},
    29  	"auth_errors": {
    30  		RateType: metadata.Counter,
    31  		Unit:     metadata.Operation,
    32  		Desc:     "The number of of failed authentications.",
    33  	},
    34  	"bytes_read": {
    35  		Metric:   "bytes",
    36  		TagSet:   opentsdb.TagSet{"type": "read"},
    37  		RateType: metadata.Counter,
    38  		Unit:     metadata.Bytes,
    39  		Desc:     "The total number of bytes read from the network.",
    40  	},
    41  	"bytes_written": {
    42  		Metric:   "bytes",
    43  		TagSet:   opentsdb.TagSet{"type": "write"},
    44  		RateType: metadata.Counter,
    45  		Unit:     metadata.Bytes,
    46  		Desc:     "The total number of bytes written to the network.",
    47  	},
    48  	"cas_badval": {
    49  		RateType: metadata.Counter,
    50  		Unit:     metadata.Operation,
    51  		Desc:     "The number of CAS requests for which a key was found, but the CAS value did not match.",
    52  	},
    53  	"cas_hits": {
    54  		RateType: metadata.Counter,
    55  		Unit:     metadata.Operation,
    56  		Desc:     "The number of successful CAS requests.",
    57  	},
    58  	"cas_misses": {
    59  		RateType: metadata.Counter,
    60  		Unit:     metadata.Operation,
    61  		Desc:     "The number of CAS requests against missing keys.",
    62  	},
    63  	"cmd_flush": {
    64  		RateType: metadata.Counter,
    65  		Unit:     metadata.Operation,
    66  		Desc:     "The cumulative number of flush requests.",
    67  	},
    68  	"cmd_set": {
    69  		RateType: metadata.Counter,
    70  		Unit:     metadata.Operation,
    71  		Desc:     "The cumulative number of storage requests.",
    72  	},
    73  	"cmd_get": {
    74  		RateType: metadata.Counter,
    75  		Unit:     metadata.Operation,
    76  		Desc:     "The cumulative number of retrieval requests.",
    77  	},
    78  	"conn_yields": {
    79  		RateType: metadata.Counter,
    80  		Unit:     metadata.Yield,
    81  		Desc:     "The number of times any connection yielded to another due to hitting the memcached -R limit.",
    82  	},
    83  	"connection_structures": {
    84  		RateType: metadata.Gauge,
    85  		Unit:     "Connection Structures",
    86  		Desc:     "The number of connection structures allocated by the server.",
    87  	},
    88  	"curr_connections": {
    89  		RateType: metadata.Gauge,
    90  		Unit:     metadata.Connection,
    91  		Desc:     "The current number of open connections.",
    92  	},
    93  	"curr_items": {
    94  		RateType: metadata.Gauge,
    95  		Unit:     metadata.Item,
    96  		Desc:     "The current number of items in the cache.",
    97  	},
    98  	"decr_hits": {
    99  		Metric:   "commands",
   100  		TagSet:   opentsdb.TagSet{"type": "decr", "cache": "hit"},
   101  		RateType: metadata.Counter,
   102  		Unit:     metadata.Operation,
   103  		Desc:     "The total number of decr command cache hits (decr decreases a stored value by 1).",
   104  	},
   105  	"decr_misses": {
   106  		Metric:   "commands",
   107  		TagSet:   opentsdb.TagSet{"type": "decr", "cache": "miss"},
   108  		RateType: metadata.Counter,
   109  		Unit:     metadata.Operation,
   110  		Desc:     "The total number of decr command cache misses (decr decreases a stored value by 1).",
   111  	},
   112  	"incr_hits": {
   113  		Metric:   "commands",
   114  		TagSet:   opentsdb.TagSet{"type": "incr", "cache": "hit"},
   115  		RateType: metadata.Counter,
   116  		Unit:     metadata.Operation,
   117  		Desc:     "The total number of incr command cache hits (incr increases a stored value by 1).",
   118  	},
   119  	"incr_misses": {
   120  		Metric:   "commands",
   121  		TagSet:   opentsdb.TagSet{"type": "incr", "cache": "miss"},
   122  		RateType: metadata.Counter,
   123  		Unit:     metadata.Operation,
   124  		Desc:     "The total number of incr command cache misses (incr increases a stored value by 1).",
   125  	},
   126  	"get_hits": {
   127  		Metric:   "commands",
   128  		TagSet:   opentsdb.TagSet{"type": "get", "cache": "hit"},
   129  		RateType: metadata.Counter,
   130  		Unit:     metadata.Operation,
   131  		Desc:     "The total number of successful get commands (cache hits) since startup.",
   132  	},
   133  	"get_misses": {
   134  		Metric:   "commands",
   135  		TagSet:   opentsdb.TagSet{"type": "get", "cache": "miss"},
   136  		RateType: metadata.Counter,
   137  		Unit:     metadata.Operation,
   138  		Desc:     "The total number of failed get requests because nothing was cached for this key or the cached value was too old.",
   139  	},
   140  	"delete_hits": {
   141  		Metric:   "commands",
   142  		TagSet:   opentsdb.TagSet{"type": "delete", "cache": "hit"},
   143  		RateType: metadata.Counter,
   144  		Unit:     metadata.Operation,
   145  		Desc:     "The total number of successful delete commands (cache hits) since startup.",
   146  	},
   147  	"delete_misses": {
   148  		Metric:   "commands",
   149  		TagSet:   opentsdb.TagSet{"type": "delete", "cache": "miss"},
   150  		RateType: metadata.Counter,
   151  		Unit:     metadata.Operation,
   152  		Desc:     "The total number of delete commands for keys not existing within the cache.",
   153  	},
   154  	"evictions": {
   155  		RateType: metadata.Counter,
   156  		Unit:     metadata.Eviction,
   157  		Desc:     "The Number of objects removed from the cache to free up memory for new items because Memcached reached it's maximum memory setting (limit_maxbytes).",
   158  	},
   159  	"limit_maxbytes": {
   160  		Metric:   "cache_limit",
   161  		RateType: metadata.Gauge,
   162  		Unit:     metadata.Bytes,
   163  		Desc:     "The max allowed size of the cache.",
   164  	},
   165  	"bytes": {
   166  		Metric:   "cache_size",
   167  		RateType: metadata.Gauge,
   168  		Unit:     metadata.Bytes,
   169  		Desc:     "The current size of the cache.",
   170  	},
   171  	"listen_disabled_num": {
   172  		Metric:   "failed_connections",
   173  		RateType: metadata.Counter,
   174  		Unit:     metadata.Connection,
   175  		Desc:     "The number of denied connection attempts because memcached reached it's configured connection limit.",
   176  	},
   177  	"threads": {
   178  		RateType: metadata.Gauge,
   179  		Unit:     metadata.Thread,
   180  		Desc:     "The current number of threads.",
   181  	},
   182  	"total_connections": {
   183  		RateType: metadata.Counter,
   184  		Unit:     metadata.Connection,
   185  		Desc:     "The total number of successful connect attempts.",
   186  	},
   187  	"total_items": {
   188  		RateType: metadata.Counter,
   189  		Unit:     metadata.Item,
   190  		Desc:     "The total number of items ever stored.",
   191  	},
   192  }
   193  
   194  func c_memcached_stats() (opentsdb.MultiDataPoint, error) {
   195  	var md opentsdb.MultiDataPoint
   196  	const metric = "memcached."
   197  	util.ReadCommand(func(line string) error {
   198  		f := strings.Fields(line)
   199  		if len(f) != 2 {
   200  			return nil
   201  		}
   202  		v, err := strconv.ParseFloat(f[1], 64)
   203  		if err != nil {
   204  			return nil
   205  		}
   206  		if m, ok := memcachedMeta[f[0]]; ok {
   207  			name := f[0]
   208  			if m.Metric != "" {
   209  				name = m.Metric
   210  			}
   211  			Add(&md, metric+name, v, m.TagSet, m.RateType, m.Unit, m.Desc)
   212  		}
   213  		return nil
   214  	}, "memcached-tool", "127.0.0.1:11211", "stats")
   215  	return md, nil
   216  }