<commit_before># go-runtime-metrics
Collect golang runtime metrics, pushing to [InfluxDB](https://www.influxdata.com/time-series-platform/influxdb/) or pulling with [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/). Inspired by https://github.com/bmhatfield/go-runtime-metrics

## Installation

    go get -u github.com/tevjef/go-runtime-metrics
    
## Push Usage

This library can be configured to push metrics directly to InfluxDB.

```go
import (
	metrics "github.com/tevjef/go-runtime-metrics"
)

func main() {
	err := metrics.RunCollector(metrics.DefaultConfig)
	
	if err != nil {
	   // handle error
	}
}
	
```

Once imported and running, you can expect a number of Go runtime metrics to be sent to InfluxDB. 
An example of what this looks like when configured to work with [Grafana](http://grafana.org/):

![](/grafana.png)

## Pull Usage via [expvar](https://golang.org/pkg/expvar/)

Package [expvar](https://golang.org/pkg/expvar/) provides a standardized interface to public variables. This library provides an exported InfluxDB formatted variable with a few other benefits: 

* Metric names are easily parsed by regexp.
* Lighter than the standard library memstat expvar
* Includes stats for `cpu.cgo_calls`, `cpu.goroutines` and timing of the last GC pause with `mem.gc.pause`.
* Works out the box with Telegraf's [InfluxDB input plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/influxdb)

Import this library's expvar package with `import _ "github.com/tevjef/go-runtime-metrics/expvar"` to export a variable with default configurations.
```json
{
  "/go/bin/binary": {
    "name": "go_runtime_metrics",<commit_msg>Add link to Grafana dashboard<commit_after># go-runtime-metrics
Collect golang runtime metrics, pushing to [InfluxDB](https://www.influxdata.com/time-series-platform/influxdb/) or pulling with [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/). Inspired by https://github.com/bmhatfield/go-runtime-metrics

## Installation

    go get -u github.com/tevjef/go-runtime-metrics
    
## Push Usage

This library can be configured to push metrics directly to InfluxDB.

```go
import (
	metrics "github.com/tevjef/go-runtime-metrics"
)

func main() {
	err := metrics.RunCollector(metrics.DefaultConfig)
	
	if err != nil {
	   // handle error
	}
}
	
```

Once imported and running, you can expect a number of Go runtime metrics to be sent to InfluxDB. 
An example of what this looks like when configured to work with [Grafana](http://grafana.org/):

![](/grafana.png)

[Download Dashboard](https://grafana.net/dashboards/1144)

## Pull Usage via [expvar](https://golang.org/pkg/expvar/)

Package [expvar](https://golang.org/pkg/expvar/) provides a standardized interface to public variables. This library provides an exported InfluxDB formatted variable with a few other benefits: 

* Metric names are easily parsed by regexp.
* Lighter than the standard library memstat expvar
* Includes stats for `cpu.cgo_calls`, `cpu.goroutines` and timing of the last GC pause with `mem.gc.pause`.
* Works out the box with Telegraf's [InfluxDB input plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/influxdb)

Import this library's expvar package with `import _ "github.com/tevjef/go-runtime-metrics/expvar"` to export a variable with default configurations.
```json
{
  "/go/bin/binary": {
    "name": "go_runtime_metrics",
{'fraction_non_alphanumeric': 0.11568799298860649, 'fraction_numerical': 0.0011685655857434998, 'mean_word_length': 4.409162717219589, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 13, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5573525', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1045, 'n_words': 327}