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 ¶
- Constants
- func Action(id int)
- func Configured()
- func Error(id int)
- func Installed()
- func LogActionDaily(id int)
- func LogRunningDaily()
- func Misconfigured()
- func Running()
- func SetAgentProperties(ap *cpb.AgentProperties)
- func SetCloudProperties(cp *iipb.CloudProperties)
- func Started()
- func Stopped()
- func Uninstalled()
- func Updated(version string)
- type Logger
- func (l *Logger) Action(id int)
- func (l *Logger) Configured()
- func (l *Logger) Error(id int)
- func (l *Logger) Installed()
- func (l *Logger) Misconfigured()
- func (l *Logger) Running()
- func (l *Logger) Started()
- func (l *Logger) Stopped()
- func (l *Logger) Uninstalled()
- func (l *Logger) Updated(version string)
- type Status
- type TimeSource
Examples ¶
Constants ¶
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.
const ( UnknownAction = iota CollectWLMMetrics CollectHostMetrics CollectProcessMetrics CollectHANAMonitoringMetrics HANADiskSnapshot SSLModeOnHANAMonitoring )
Agent wide action mappings.
Variables ¶
This section is empty.
Functions ¶
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 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 Uninstalled ¶
func Uninstalled()
Uninstalled uses the standard logger to log the UNINSTALLED 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) Error ¶
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) Misconfigured ¶
func (l *Logger) Misconfigured()
Misconfigured logs the MISCONFIGURED status.
func (*Logger) Uninstalled ¶
func (l *Logger) Uninstalled()
Uninstalled logs the UNINSTALLED 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.