Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rajnandan1 committed Mar 6, 2024
1 parent 165120d commit 18ec672
Showing 1 changed file with 68 additions and 61 deletions.
129 changes: 68 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,12 @@

The `tripper` is a lightweight, 0 dependencies package that provides functionality for monitoring the status of a circuit. It allows you to track the success and failure counts of events and determine if a circuit should be open or closed based on configurable thresholds. This can be useful in scenarios where you want to implement circuit breaker patterns or manage the availability of services.

## Constants

- `ThresholdCount` represents a threshold type based on count.
- `ThresholdPercentage` represents a threshold type based on percentage.

## Types

### Monitor

The `Monitor` struct represents a monitoring entity that tracks the status of a circuit. It contains the following fields:

- `Name`: Name of the monitor.
- `CircuitOpen`: Indicates whether the circuit is open or closed.
- `LastCapturedAt`: Timestamp of the last captured event.
- `CircuitOpenedSince`: Timestamp when the circuit was opened.
- `FailureCount`: Number of failures recorded.
- `SuccessCount`: Number of successes recorded.
- `Threshold`: Threshold value for triggering circuit open.
- `ThresholdType`: Type of threshold (e.g., percentage, count).
- `MinimumCount`: Minimum number of events required for monitoring.
- `IntervalInSeconds`: Interval in seconds for monitoring (should be non-zero and a multiple of 60).

## Functions

### AddMonitor
### Installation

```go
func AddMonitor(monitor Monitor) error
```bash
go get github.com/rajnandan1/go-tripper
```

`AddMonitor` adds a new monitor to the circuits map. It checks if a monitor with the given name already exists. It also validates the threshold type and threshold value. If the minimum count or interval is invalid, it returns an error. If the interval is not a multiple of 60, it returns an error.

### UpdateMonitorStatusByName

```go
func UpdateMonitorStatusByName(name string, success bool) (*Monitor, error)
```

`UpdateMonitorStatusByName` updates the status of a monitor by its name. It takes the name of the monitor and a boolean indicating the success status. It returns the updated monitor and an error, if any.

### IsCircuitOpen

```go
func IsCircuitOpen(name string) (bool, error)
```

`IsCircuitOpen` checks if a circuit with the given name is open or closed. It returns a boolean indicating whether the circuit is open or closed, and an error if the circuit does not exist.

### GetMonitorByName

```go
func GetMonitorByName(name string) (*Monitor, error)
```

`GetMonitorByName` retrieves a monitor by its name. It returns the monitor if found, otherwise it returns an error.

### GetAllMonitors

```go
func GetAllMonitors() map[string]*Monitor
```

`GetAllMonitors` returns a map of all monitors.

## How to Use

1. Import the `tripper` package into your Go code:
Expand Down Expand Up @@ -139,3 +81,68 @@ for name, monitor := range monitors {
// Process each monitor
}
```


## Constants

- `ThresholdCount` represents a threshold type based on count.
- `ThresholdPercentage` represents a threshold type based on percentage.

## Types

### Monitor

The `Monitor` struct represents a monitoring entity that tracks the status of a circuit. It contains the following fields:

- `Name`: Name of the monitor.
- `CircuitOpen`: Indicates whether the circuit is open or closed.
- `LastCapturedAt`: Timestamp of the last captured event.
- `CircuitOpenedSince`: Timestamp when the circuit was opened.
- `FailureCount`: Number of failures recorded.
- `SuccessCount`: Number of successes recorded.
- `Threshold`: Threshold value for triggering circuit open.
- `ThresholdType`: Type of threshold (e.g., percentage, count).
- `MinimumCount`: Minimum number of events required for monitoring.
- `IntervalInSeconds`: Interval in seconds for monitoring (should be non-zero and a multiple of 60).

## Functions

### AddMonitor

```go
func AddMonitor(monitor Monitor) error
```

`AddMonitor` adds a new monitor to the circuits map. It checks if a monitor with the given name already exists. It also validates the threshold type and threshold value. If the minimum count or interval is invalid, it returns an error. If the interval is not a multiple of 60, it returns an error.

### UpdateMonitorStatusByName

```go
func UpdateMonitorStatusByName(name string, success bool) (*Monitor, error)
```

`UpdateMonitorStatusByName` updates the status of a monitor by its name. It takes the name of the monitor and a boolean indicating the success status. It returns the updated monitor and an error, if any.

### IsCircuitOpen

```go
func IsCircuitOpen(name string) (bool, error)
```

`IsCircuitOpen` checks if a circuit with the given name is open or closed. It returns a boolean indicating whether the circuit is open or closed, and an error if the circuit does not exist.

### GetMonitorByName

```go
func GetMonitorByName(name string) (*Monitor, error)
```

`GetMonitorByName` retrieves a monitor by its name. It returns the monitor if found, otherwise it returns an error.

### GetAllMonitors

```go
func GetAllMonitors() map[string]*Monitor
```

`GetAllMonitors` returns a map of all monitors.

0 comments on commit 18ec672

Please sign in to comment.