prometheus monitoring now more complete. Including a guid to uniquely identify agents and clients.
This commit is contained in:
parent
135fd081d8
commit
97d34424ca
@ -7,7 +7,6 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const NAMESPACE = "converge"
|
||||
@ -30,29 +29,36 @@ var (
|
||||
Name: "agent_info",
|
||||
Help: "A flexible gauge with dynamic labels, always set to 1",
|
||||
},
|
||||
[]string{"id", "os"}, // Label names
|
||||
)
|
||||
[]string{"guid", "id", "username", "hostname", "pwd", "os", "shell"}) // Label names
|
||||
|
||||
clientInfo = promauto.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: NAMESPACE,
|
||||
Name: "client_info",
|
||||
Help: "A flexible gauge with dynamic labels, always set to 1",
|
||||
},
|
||||
[]string{"id", "agentid"}, // Label names
|
||||
[]string{"guid", "id", "agentid", "sessiontype"}, // Label names
|
||||
)
|
||||
)
|
||||
|
||||
func agentLabels(agent models.Agent) prometheus.Labels {
|
||||
return prometheus.Labels{
|
||||
"id": agent.PublicId,
|
||||
"os": agent.AgentInfo.OS,
|
||||
"guid": agent.Guid,
|
||||
"id": agent.PublicId,
|
||||
"username": agent.AgentInfo.Username,
|
||||
"hostname": agent.AgentInfo.Hostname,
|
||||
"pwd": agent.AgentInfo.Pwd,
|
||||
"os": agent.AgentInfo.OS,
|
||||
"shell": agent.AgentInfo.Shell,
|
||||
}
|
||||
}
|
||||
|
||||
func clientLabels(client models.Client) prometheus.Labels {
|
||||
return prometheus.Labels{
|
||||
"id": strconv.Itoa(client.ClientId),
|
||||
"agentid": client.PublicId,
|
||||
"guid": client.Guid,
|
||||
"id": client.ClientId,
|
||||
"agentid": client.PublicId,
|
||||
"sessiontype": client.SessionType,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,10 @@ import (
|
||||
templates2 "converge/pkg/server/templates"
|
||||
"github.com/a-h/templ"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -79,6 +81,7 @@ func main() {
|
||||
|
||||
state := models.State{}
|
||||
agent := models.Agent{
|
||||
Guid: strconv.Itoa(rand.Int()),
|
||||
PublicId: "id",
|
||||
StartTime: time.Now().In(japan),
|
||||
AgentInfo: comms.AgentInfo{
|
||||
@ -92,6 +95,7 @@ func main() {
|
||||
}
|
||||
state.Agents = append(state.Agents, agent)
|
||||
client := models.Client{
|
||||
Guid: strconv.Itoa(rand.Int()),
|
||||
PublicId: "c1",
|
||||
ClientId: "3",
|
||||
StartTime: time.Now().In(japan),
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type Agent struct {
|
||||
Guid string
|
||||
PublicId string
|
||||
StartTime time.Time
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Guid string
|
||||
PublicId string
|
||||
ClientId string
|
||||
StartTime time.Time
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -33,6 +34,7 @@ type ClientConnection struct {
|
||||
func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.AgentInfo) *AgentConnection {
|
||||
return &AgentConnection{
|
||||
Agent: models.Agent{
|
||||
Guid: strconv.Itoa(rand.Int()),
|
||||
PublicId: publicId,
|
||||
StartTime: time.Now(),
|
||||
AgentInfo: agentInfo,
|
||||
@ -45,6 +47,7 @@ func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser,
|
||||
agentConn net.Conn) *ClientConnection {
|
||||
return &ClientConnection{
|
||||
Client: models.Client{
|
||||
Guid: strconv.Itoa(rand.Int()),
|
||||
PublicId: publicId,
|
||||
ClientId: strconv.Itoa(clientIdGenerator.IncrementAndGet()),
|
||||
StartTime: time.Now(),
|
||||
|
Loading…
Reference in New Issue
Block a user