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