Documentation ¶
Overview ¶
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling ¶
Copyright 2018-2021 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling. Library interface goes here.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn) Copyright 2019 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling ¶
Copyright 2018-2021 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling ¶
Copyright 2018-2021 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package cynic monitors you from the ceiling.
Copyright 2018 Simon Symeonidis (psyomn)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func Start(session Session)
- type AlertFunc
- type AlertMessage
- type Alerter
- type Event
- func (s *Event) AddHook(fn HookSignature)
- func (s *Event) Delete()
- func (s *Event) Execute()
- func (s *Event) GetAbsExpiry() int64
- func (s *Event) GetOffset() int
- func (s *Event) GetSecs() int
- func (s *Event) ID() uint64
- func (s *Event) Immediate(val bool)
- func (s *Event) IsDeleted() bool
- func (s *Event) IsImmediate() bool
- func (s *Event) IsRepeating() bool
- func (s *Event) NumHooks() int
- func (s *Event) Repeat(rep bool)
- func (s *Event) SetAbsExpiry(ts int64)
- func (s *Event) SetDataRepo(repo *StatusCache)
- func (s *Event) SetExtra(extra interface{})
- func (s *Event) SetOffset(offset int)
- func (s *Event) SetSecs(secs int)
- func (s *Event) String() string
- func (s *Event) UniqStr() string
- type EventBuilder
- type EventQueue
- type HookParameters
- type HookSignature
- type Planner
- type Session
- type SnapshotConfig
- type SnapshotStore
- type StatusCache
- func (s *StatusCache) Delete(key string)
- func (s *StatusCache) Get(key string) (interface{}, error)
- func (s *StatusCache) GetPort() int
- func (s *StatusCache) NumEntries() (count int)
- func (s *StatusCache) Start()
- func (s *StatusCache) Stop()
- func (s *StatusCache) Update(key string, value interface{})
- func (s *StatusCache) WithSnapshots(config *SnapshotConfig)
Constants ¶
const ( // StopEvent is the signal to stop the running querying event. StopEvent = iota // AddEvent adds a event to a running cynic instance. AddEvent // DeleteEvent removes a event from a running cynic instance. DeleteEvent )
const ( // StatusPort is the default port the status http server will // respond on. StatusPort = "9999" // DefaultStatusEndpoint is where the default status json can // be retrieved from. DefaultStatusEndpoint = "/status/" )
const VERSION string = "2.4.1"
VERSION is the version of the current package. Update with every new tag/release.
Variables ¶
var ErrStatusValueNotFound = fmt.Errorf("could not find required value")
Functions ¶
Types ¶
type AlertFunc ¶
type AlertFunc = func([]AlertMessage)
AlertFunc defines the hook signature for alert messages.
type AlertMessage ¶
type AlertMessage struct { Response interface{} `json:"response_text"` Now string `json:"now"` CynicHostname string `json:"cynic_hostname"` }
AlertMessage defines a simple alert structure that can be used by users of the library, and decide how to show information about the alerts.
type Alerter ¶
type Alerter struct { Ch chan AlertMessage // contains filtered or unexported fields }
Alerter is an entity that ticks, and if there are alert messages, will fire up behavior.
func AlerterNew ¶
AlerterNew creates a new alerter.
type Event ¶
type Event struct { Label string // contains filtered or unexported fields }
Event is some event that should be executed in a specified amount of time. There are no real time guarantees. - A event is an action - A event can have many:
- hooks (that can act as contracts)
- A event may be bound to a data repository/cache.
func (*Event) AddHook ¶
func (s *Event) AddHook(fn HookSignature)
AddHook appends a hook to the event.
func (*Event) IsImmediate ¶
IsImmediate returns true if event is immediate.
func (*Event) IsRepeating ¶
IsRepeating says whether a event repeats or not.
func (*Event) SetAbsExpiry ¶
SetAbsExpiry sets the timestamp that the event is supposed to expire on.
func (*Event) SetDataRepo ¶
func (s *Event) SetDataRepo(repo *StatusCache)
SetDataRepo sets where the data processed should be stored in.
func (*Event) SetExtra ¶
func (s *Event) SetExtra(extra interface{})
SetExtra state you may want passed to hooks.
type EventBuilder ¶
type EventBuilder struct {
// contains filtered or unexported fields
}
EventBuilder is a helper to set properties to a lot of events. For example, if you have 10 events you want to run within 100 seconds, you can use this builder in oder to disperse everything over 10 seconds.
func EventBuilderNew ¶
func EventBuilderNew(events []Event) EventBuilder
EventBuilderNew creates a new events builder. Simple configurations. If you want something more complex, you should do it on your own.
func (*EventBuilder) Build ¶
func (s *EventBuilder) Build() (Session, bool)
Build takes all the things you gave the builder, puts them together, and gives you a session object to do whatever you will with it.
func (*EventBuilder) DistributeEvents ¶
func (s *EventBuilder) DistributeEvents(maxTime int)
DistributeEvents over a max time interval.
func (*EventBuilder) Repeatable ¶
func (s *EventBuilder) Repeatable()
Repeatable will mark all events as repeatable.
type EventQueue ¶
type EventQueue []*Event
EventQueue is a priority queue that sorts events that are to happen via their absolute expiry.
func (EventQueue) Len ¶
func (pq EventQueue) Len() int
func (EventQueue) Less ¶
func (pq EventQueue) Less(i, j int) bool
func (*EventQueue) PeekID ¶
func (pq *EventQueue) PeekID() (uint64, bool)
PeekID returns the id of the event at root.
func (*EventQueue) PeekTimestamp ¶
func (pq *EventQueue) PeekTimestamp() (int64, bool)
PeekTimestamp gives the timestamp at the root of the heap.
func (*EventQueue) Push ¶
func (pq *EventQueue) Push(x interface{})
Push inserts an event into the priority queue.
func (EventQueue) Swap ¶
func (pq EventQueue) Swap(i, j int)
type HookParameters ¶
type HookParameters struct { // Planner is access to the planner that the hook executes // on. The user for example, should be able to add more events // through a hook. Planner *Planner // Status exposes the status repo. It acts as a repository for // hooks to store information after execution. Status *StatusCache // Extra is meant to be used by the user for any extra state // that needs to be passed to the hooks. Extra interface{} }
HookParameters is any state that should be passed to the hook.
type HookSignature ¶
type HookSignature = func(*HookParameters) (bool, interface{})
HookSignature specifies what the event hooks should look like.
type Planner ¶
type Planner struct {
// contains filtered or unexported fields
}
Planner is a structure that manages events inserted with expiration timestamps. The underlying data structures are magic, and you shouldn't care about them, unless you're opening up the hatch and stuff.
func (*Planner) Delete ¶
Delete marks a Event to be deleted. Returns true if event found and marked for deletion, false if not.
func (*Planner) GetAlerter ¶
GetAlerter gets the assigned alerter of planner.
func (*Planner) SetAlerter ¶
SetAlerter sets the alerter.
type Session ¶
type Session struct { Events []Event StatusCache *StatusCache Alerter *Alerter SnapshotConfig *SnapshotConfig }
Session is the configuration a cynic instance requires to start running and working.
type SnapshotConfig ¶
SnapshotConfig is the configuration for the snapshots to be taken
type SnapshotStore ¶
SnapshotStore is storage of states of the map at different times
func (*SnapshotStore) String ¶
func (s *SnapshotStore) String() string
String stringifies the contents of SnapshotStore
type StatusCache ¶
type StatusCache struct {
// contains filtered or unexported fields
}
StatusCache stores any sort of information that is possibly retrieved or calculated by events. A server can be started to retrieve information in the map in json format.
func StatusServerNew ¶
func StatusServerNew(host, port, root string) StatusCache
StatusServerNew creates a new status server for cynic.
func (*StatusCache) Delete ¶
func (s *StatusCache) Delete(key string)
Delete removes an entry from the sync map.
func (*StatusCache) Get ¶
func (s *StatusCache) Get(key string) (interface{}, error)
Get gets the value inside the contract results.
func (*StatusCache) GetPort ¶
func (s *StatusCache) GetPort() int
GetPort this will return the port where the server was started. This is useful if you assign port 0 when initializing.
func (*StatusCache) NumEntries ¶
func (s *StatusCache) NumEntries() (count int)
NumEntries returns the number of entries in the map.
func (*StatusCache) Start ¶
func (s *StatusCache) Start()
Start starts all services associated with status caches. This includes the web interface if enabled, and the dumping of statuses in files.
func (*StatusCache) Update ¶
func (s *StatusCache) Update(key string, value interface{})
Update updates the information about all the contracts that are running on different endpoints.
func (*StatusCache) WithSnapshots ¶
func (s *StatusCache) WithSnapshots(config *SnapshotConfig)
WithSnapshots will make the cache dump snapshots of the data with given intervals when the service starts.