---
title: RateCounter
summary: RateCounter is a named counter that can be incremented and queried.
url: https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/struct.RateCounter/
---

**Kind:** Struct  
**Module:** [erl](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/)  
**Package:** compute-sdk-go v1.11.0  
**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L116

```go
type RateCounter struct {
	// contains filtered or unexported fields
}
```

RateCounter is a named counter that can be incremented and queried.

## Methods

### Increment

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L130

```go
func (rc *RateCounter) Increment(entry string, delta uint32) error
```

Increment increments the rate counter for this entry by the given
delta value.  The minimum value is 0 and the maximum is 1000.

**Parameters**

- `entry`: `string`
- `delta`: `uint32`

**Returns**

`error`

### LookupCount

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L147

```go
func (rc *RateCounter) LookupCount(entry string, duration CounterDuration) (uint32, error)
```

LookupCount returns the estimated number of events in the given
duration for this entry.  The duration represents a discrete window,
not a continuous one.  See [CounterDuration](https://www.fastly.com/documentation/reference/compute/sdks/go/compute-sdk-go/erl/type.CounterDuration/) for more details.

**Parameters**

- `entry`: `string`
- `duration`: `CounterDuration`

**Returns**

`(uint32, error)`

```go
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
	rc := erl.OpenRateCounter("requests")

	rc.Increment(r.RemoteAddr, 1)

	count, err := rc.LookupCount(r.RemoteAddr, erl.CounterDuration60s)
	if err != nil {
		w.WriteHeader(fsthttp.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, "Estimated count over the past 60 seconds: %d requests\n", count)
})
```

### LookupRate

**Source:** https://github.com/fastly/compute-sdk-go/blob/d6bf71b04516ed72d6018cab6fff701a865f86e5/erl/erl.go#L136

```go
func (rc *RateCounter) LookupRate(entry string, window RateWindow) (uint32, error)
```

LookupRate returns the rate of events per second over the given rate
window for this entry.

**Parameters**

- `entry`: `string`
- `window`: `RateWindow`

**Returns**

`(uint32, error)`

```go
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
	rc := erl.OpenRateCounter("requests")

	rc.Increment(r.RemoteAddr, 1)

	rate, err := rc.LookupRate(r.RemoteAddr, erl.RateWindow60s)
	if err != nil {
		w.WriteHeader(fsthttp.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, "Rate over the past 60 seconds: %d requests per second\n", rate)
})
```
