common

package
v0.0.0-...-71a725b Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT-0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CatCommand              = "cat "
	AppOwnerCommand         = "ps -u -p "
	Namespace               = "CWAgent"
	Host                    = "host"
	InstallAgentVersionPath = "/opt/aws/amazon-cloudwatch-agent/bin/CWAGENT_VERSION"
)
View Source
const (
	ConfigOutputPath      = "/opt/aws/amazon-cloudwatch-agent/bin/config.json"
	AgentLogFile          = "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
	AgentCommonConfigFile = "/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml"
)
View Source
const MetricEndpoint = "4316/v1/metrics"
View Source
const SleepDuration = 5 * time.Second
View Source
const TMPAGENTPATH = "/tmp/agent_config.json"
View Source
const TracesEndpoint = "4316/v1/traces"

Variables

This section is empty.

Functions

func BuildListEntitiesForMetricRequest

func BuildListEntitiesForMetricRequest(body []byte, region string) (*http.Request, error)

This function builds and signs an ListEntitiesForMetric call, essentially trying to replicate this curl command:

curl -i -X POST monitoring.us-west-2.amazonaws.com -H 'Content-Type: application/json' \
  -H 'Content-Encoding: amz-1.0' \
  --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
  -H "x-amz-security-token: $AWS_SESSION_TOKEN" \
  --aws-sigv4 "aws:amz:us-west-2:monitoring" \
  -H 'X-Amz-Target: com.amazonaws.cloudwatch.v2013_01_16.CloudWatchVersion20130116.ListEntitiesForMetric' \
  -d '{
	   // sample request body:
    "Namespace": "CWAgent",
    "MetricName": "cpu_usage_idle",
    "Dimensions": [{"Name": "InstanceId", "Value": "i-0123456789012"}, { "Name": "cpu", "Value": "cpu-total"}]
  }'

func CopyFile

func CopyFile(pathIn string, pathOut string)

func CreateWindowsEvent

func CreateWindowsEvent(eventLogName string, eventLogLevel string, eventID string, msg string) error

func DeleteFile

func DeleteFile(filePathAbsolute string) error

func DownloadFromS3

func DownloadFromS3(bucket string, key string, destPath string) error

func GenerateLogConfig

func GenerateLogConfig(numberMonitoredLogs int, filePath string) error

GenerateLogConfig takes the number of logs to be monitored and applies it to the supplied config, It writes logs to be monitored of the form /tmp/testNUM.log where NUM is from 1 to number of logs requested to the supplied configuration DEFAULT CONFIG MUST BE SUPPLIED WITH AT LEAST ONE LOG BEING MONITORED (log being monitored will be overwritten - it is needed for json structure) returns the path of the config generated and a list of log stream names

func GenerateLogs

func GenerateLogs(configFilePath string, duration time.Duration, sendingInterval time.Duration, logLinesPerMinute int, validationLog []models.LogValidation) error

func GenerateWindowsEvents

func GenerateWindowsEvents(validationLog []models.LogValidation) error

func GetAnyEBSVolumeID

func GetAnyEBSVolumeID() (string, error)

GetAnyEBSVolumeID will return the volume ID of the first NVMe device found

func GetAnyInstanceStoreSerialID

func GetAnyInstanceStoreSerialID() (string, error)

GetAnyInstanceStoreSerialID returns the serial ID of the first NVMe instance store device found.

func GetLogFilePaths

func GetLogFilePaths(configPath string) ([]string, error)

GetLogFilePaths parses the cloudwatch agent config at the specified path and returns a list of the log files that the agent will monitor when using that config file

func InstallAgent

func InstallAgent(installerFilePath string) error

InstallAgent can determine the package manager based on the installer suffix.

func MkdirAll

func MkdirAll(path string) error

func ReadAgentLogfile

func ReadAgentLogfile(logfile string) string

func RecreateAgentLogfile

func RecreateAgentLogfile(logfile string)

func ReplaceLocalStackHostName

func ReplaceLocalStackHostName(pathIn string)

func ReplacePlaceholder

func ReplacePlaceholder(filePath, placeholder, value string) error

ReplacePlaceholder replaces a placeholder string with a value in the specified file using sed command. This centralizes placeholder replacement functionality used across tests.

func ReplacePlaceholders

func ReplacePlaceholders(filePath string, placeholders map[string]string) error

ReplacePlaceholders replaces multiple placeholders in a single file placeholders is a map where key is the placeholder and value is the replacement

func RunAsyncCommand

func RunAsyncCommand(cmd string) error

func RunCommand

func RunCommand(cmd string) (string, error)

func RunCommands

func RunCommands(commands []string) error

func RunShellScript

func RunShellScript(path string, args ...string) (string, error)

func SELinuxEnforced

func SELinuxEnforced() (bool, error)

func SendAppSignalMetrics

func SendAppSignalMetrics(duration time.Duration) error

func SendAppSignalsTraceMetrics

func SendAppSignalsTraceMetrics(duration time.Duration) error

func SendCollectDMetrics

func SendCollectDMetrics(metricPerInterval int, sendingInterval, duration time.Duration) error

func SendEMFMetrics

func SendEMFMetrics(metricPerInterval int, metricLogGroup, metricNamespace string, sendingInterval, duration time.Duration) error

func SendPrometheusMetrics

func SendPrometheusMetrics(config PrometheusConfig, agentCollectionDuration time.Duration) error

func SendStatsdMetrics

func SendStatsdMetrics(metricPerInterval int, metricDimension []string, sendingInterval, duration time.Duration) error

func StartAgent

func StartAgent(configOutputPath string, fatalOnFailure bool, ssm bool) error

func StartAgentWithCommand

func StartAgentWithCommand(configOutputPath string, fatalOnFailure bool, ssm bool, agentStartCommand string) error

func StartLogWrite

func StartLogWrite(configFilePath string, duration time.Duration, sendingInterval time.Duration, logLinesPerMinute int) error

StartLogWrite starts go routines to write logs to each of the logs that are monitored by CW Agent according to the config provided

func StartSendingMetrics

func StartSendingMetrics(receiver string, duration, sendingInterval time.Duration, metricPerInterval int, metricLogGroup, metricNamespace string) (err error)

StartSendingMetrics will generate metrics load based on the receiver (e.g 5000 statsd metrics per minute)

func StopAgent

func StopAgent()

func TouchFile

func TouchFile(filePathAbsolute string) error

func UninstallAgent

func UninstallAgent(pm PackageManager) error

func WriteFile

func WriteFile(filePath string, content string) error

Types

type PackageManager

type PackageManager int
const (
	RPM PackageManager = iota
	DEB
)

type PrometheusConfig

type PrometheusConfig struct {
	MetricCount    int           `json:"metric_count"`
	Port           int           `json:"port"`
	UpdateInterval time.Duration `json:"update_interval"`
	ScrapeInterval int           `json:"scrape_interval"`
	InstanceID     string        `json:"instance_id"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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