Added agent uid to the client info so that client and agent can be correlated in prometheus/grafana.

This commit is contained in:
Erik Brakkee 2024-08-10 18:57:57 +02:00
parent bd4e2c277b
commit fc92286998
5 changed files with 7 additions and 3 deletions

View File

@ -113,7 +113,6 @@ func (pubkeys *AuthorizedPublicKeys) monitorAuthorizedKeysFile(authorizedPublicK
return
}
base := filepath.Base(event.Name)
log.Println("CHANGE " + base + " " + authorizedPublicKeysFile + " " + filepath.Base(authorizedPublicKeysFile))
if base == filepath.Base(authorizedPublicKeysFile) {
keys, errorKeys := pubkeys.Parse()
for _, errorKey := range errorKeys {

View File

@ -64,6 +64,7 @@ var (
[]string{"guid",
"id",
"agentid",
"agentguid",
"sessiontype",
"username",
"hostname",
@ -91,6 +92,7 @@ func clientLabels(client models.Client) prometheus.Labels {
"guid": client.Guid,
"id": client.ClientId,
"agentid": client.PublicId,
"agentguid": client.AgentGuid,
"sessiontype": client.SessionType,
"username": client.EnvironmentInfo.Username,
"hostname": client.EnvironmentInfo.Hostname,

View File

@ -97,6 +97,7 @@ func main() {
client := models.Client{
Guid: strconv.Itoa(rand.Int()),
PublicId: "c1",
AgentGuid: "12342342",
ClientId: "3",
StartTime: time.Now().In(japan),
SessionType: "sftp",

View File

@ -9,6 +9,7 @@ type Client struct {
Guid string
PublicId string
ClientId string
AgentGuid string
StartTime time.Time
SessionType string
EnvironmentInfo comms.EnvironmentInfo

View File

@ -44,11 +44,12 @@ func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.En
}
func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser,
agentConn net.Conn) *ClientConnection {
agentConn net.Conn, agentGuid string) *ClientConnection {
return &ClientConnection{
Client: models.Client{
Guid: strconv.Itoa(rand.Int()),
PublicId: publicId,
AgentGuid: agentGuid,
ClientId: strconv.Itoa(clientIdGenerator.IncrementAndGet()),
StartTime: time.Now(),
},
@ -201,7 +202,7 @@ func (admin *Admin) addClient(publicId string, clientConn iowrappers2.ReadWriteA
log.Println("Sending connection information to agent")
client := NewClient(publicId, clientConn, agentConn)
client := NewClient(publicId, clientConn, agentConn, agent.Guid)
// Before using this connection for SSH we use it to send client metadata to the
// agent