usagemetrics

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package usagemetrics provides logging utility for the operational status of the GC SAP Agent.

Example (CustomLogger)
package main

import (
	"github.com/GoogleCloudPlatform/sapagent/internal/usagemetrics"
	"github.com/jonboulle/clockwork"

	cpb "github.com/GoogleCloudPlatform/sapagent/protos/configuration"

	iipb "github.com/GoogleCloudPlatform/sapagent/protos/instanceinfo"
)

func main() {
	// Alternatively, a custom Logger instance can be instantiated.
	agentProps := &cpb.AgentProperties{
		/* AgentProperties configuration omitted */
		LogUsageMetrics: false, // Do not log in examples.
	}
	cloudProps := &iipb.CloudProperties{ /* CloudProperties configuration omitted */ }
	logger := usagemetrics.NewLogger(agentProps, cloudProps, clockwork.NewRealClock())

	// Then, the methods on the logger can be used to report a formatted User-Agent header
	// to a compute server API endpoint.
	logger.Running() // Logs a header of: "sap-core-eng/<AgentName>/<AgentVersion>/<Image OS-Version>/RUNNING"
}
Output:

Example (StandardLogger)
package main

import (
	"github.com/GoogleCloudPlatform/sapagent/internal/usagemetrics"

	cpb "github.com/GoogleCloudPlatform/sapagent/protos/configuration"

	iipb "github.com/GoogleCloudPlatform/sapagent/protos/instanceinfo"
)

func main() {
	// If using the standard logger exposed by the package, first configure its properties.
	usagemetrics.SetAgentProperties(&cpb.AgentProperties{
		/* AgentProperties configuration omitted */
		LogUsageMetrics: false, // Do not log in examples.
	})
	usagemetrics.SetCloudProperties(&iipb.CloudProperties{
		/* CloudProperties configuration omitted */
	})

	// Then, the top-level package functions can be used to report a formatted User-Agent header
	// to a compute server API endpoint.
	usagemetrics.Running() // Logs a header of: "sap-core-eng/<AgentName>/<AgentVersion>/<Image OS-Version>/RUNNING"
}
Output:

Index

Examples

Constants

View Source
const (
	UnknownError = iota
	CloudPropertiesNotSet
	GCEServiceCreateFailure
	MetricClientCreateFailure
	QueryClientCreateFailure
	BareMetalCloudPropertiesNotSet
	LocalHTTPListenerCreateFailure
	ConfigFileReadFailure
	MalformedConfigFile
	WLMMetricCollectionFailure
	ProcessMetricsMetricClientCreateFailure
	NoSAPInstancesFound
	HANAMonitoringCollectionFailure
	HANAMonitoringConfigReadFailure
	MalformedHANAMonitoringConfigFile
	MalformedDefaultHANAMonitoringQueriesFile
	AgentMetricsServiceCreateFailure
	HeartbeatMonitorCreateFailure
	HeartbeatMonitorRegistrationFailure
	SnapshotDBNotReadyFailure
	DiskSnapshotCreateFailure
	DiskSnapshotFailedDBNotComplete
	DiskSnapshotDoneDBNotComplete
	CollectionDefinitionLoadFailure
	CollectionDefinitionValidateFailure
	WLMServiceCreateFailure
)

Agent wide error code mappings.

View Source
const (
	UnknownAction = iota
	CollectWLMMetrics
	CollectHostMetrics
	CollectProcessMetrics
	CollectHANAMonitoringMetrics
	HANADiskSnapshot
	SSLModeOnHANAMonitoring
)

Agent wide action mappings.

Variables

This section is empty.

Functions

func Action

func Action(id int)

Action uses the standard logger to log the ACTION status.

func Configured

func Configured()

Configured uses the standard logger to log the CONFIGURED status.

func Error

func Error(id int)

Error uses the standard logger to log the ERROR status. This status is reported at most once per day.

Any calls to Error should have an id mapping in this mapping sheet: go/sap-core-eng-tool-mapping.

func Installed

func Installed()

Installed uses the standard logger to log the INSTALLED status.

func LogActionDaily

func LogActionDaily(id int)

LogActionDaily uses the standard logger to log the ACTION once a day. Should be called exactly once for each ACTION code.

func LogRunningDaily

func LogRunningDaily()

LogRunningDaily log that the agent is running once a day.

func Misconfigured

func Misconfigured()

Misconfigured uses the standard logger to log the MISCONFIGURED status.

func Running

func Running()

Running uses the standard logger to log the RUNNING status. This status is reported at most once per day.

func SetAgentProperties

func SetAgentProperties(ap *cpb.AgentProperties)

SetAgentProperties sets the configured agent properties on the standard logger.

func SetCloudProperties

func SetCloudProperties(cp *iipb.CloudProperties)

SetCloudProperties sets the configured cloud properties on the standard logger.

func Started

func Started()

Started uses the standard logger to log the STARTED status.

func Stopped

func Stopped()

Stopped uses the standard logger to log the STOPPED status.

func Uninstalled

func Uninstalled()

Uninstalled uses the standard logger to log the UNINSTALLED status.

func Updated

func Updated(version string)

Updated uses the standard logger to log the UPDATED status.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

A Logger is used to report the status of the agent to an internal metadata server.

func NewLogger

func NewLogger(agentProps *configpb.AgentProperties, cloudProps *instancepb.CloudProperties, timeSource TimeSource) *Logger

NewLogger creates a new Logger with an initialized hash map of Status to a last called timestamp.

func (*Logger) Action

func (l *Logger) Action(id int)

Action logs the ACTION status.

func (*Logger) Configured

func (l *Logger) Configured()

Configured logs the CONFIGURED status.

func (*Logger) Error

func (l *Logger) Error(id int)

Error logs the ERROR status.

Any calls to Error should have an id mapping in this mapping sheet: go/sap-core-eng-tool-mapping.

func (*Logger) Installed

func (l *Logger) Installed()

Installed logs the INSTALLED status.

func (*Logger) Misconfigured

func (l *Logger) Misconfigured()

Misconfigured logs the MISCONFIGURED status.

func (*Logger) Running

func (l *Logger) Running()

Running logs the RUNNING status.

func (*Logger) Started

func (l *Logger) Started()

Started logs the STARTED status.

func (*Logger) Stopped

func (l *Logger) Stopped()

Stopped logs the STOPPED status.

func (*Logger) Uninstalled

func (l *Logger) Uninstalled()

Uninstalled logs the UNINSTALLED status.

func (*Logger) Updated

func (l *Logger) Updated(version string)

Updated logs the UPDATED status.

type Status

type Status string

Status enumerates the supported usage logging statuses.

const (
	StatusRunning       Status = "RUNNING"
	StatusStarted       Status = "STARTED"
	StatusStopped       Status = "STOPPED"
	StatusConfigured    Status = "CONFIGURED"
	StatusMisconfigured Status = "MISCONFIGURED"
	StatusError         Status = "ERROR"
	StatusInstalled     Status = "INSTALLED"
	StatusUpdated       Status = "UPDATED"
	StatusUninstalled   Status = "UNINSTALLED"
	StatusAction        Status = "ACTION"
)

The following status values are supported.

type TimeSource

type TimeSource interface {
	Now() time.Time
	Since(t time.Time) time.Duration
}

The TimeSource interface is a wrapper around time functionality needed for usage metrics logging. A fake TimeSource can be supplied by tests to ensure test stability.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL