Skip to content

Commit 5804553

Browse files
committed
system-monitor-server go mcp server
Signed-off-by: irapandey <[email protected]>
1 parent 785c607 commit 5804553

File tree

19 files changed

+3977
-0
lines changed

19 files changed

+3977
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Multi-stage build for system-monitor-server
2+
FROM golang:1.21-alpine AS builder
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache git ca-certificates tzdata
6+
7+
# Set working directory
8+
WORKDIR /app
9+
10+
# Copy go mod files
11+
COPY go.mod go.sum ./
12+
13+
# Download dependencies
14+
RUN go mod download
15+
16+
# Copy source code
17+
COPY . .
18+
19+
# Build the application
20+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o system-monitor-server ./cmd/server
21+
22+
# Final stage
23+
FROM alpine:latest
24+
25+
# Install runtime dependencies
26+
RUN apk --no-cache add ca-certificates tzdata
27+
28+
# Create non-root user
29+
RUN addgroup -g 1001 -S appgroup && \
30+
adduser -u 1001 -S appuser -G appgroup
31+
32+
# Set working directory
33+
WORKDIR /app
34+
35+
# Copy binary from builder stage
36+
COPY --from=builder /app/system-monitor-server .
37+
38+
# Copy configuration file
39+
COPY --from=builder /app/config.yaml .
40+
41+
# Create logs directory
42+
RUN mkdir -p /app/logs && chown -R appuser:appgroup /app
43+
44+
# Switch to non-root user
45+
USER appuser
46+
47+
# Expose port
48+
EXPOSE 8080
49+
50+
# Health check
51+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
52+
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
53+
54+
# Default command
55+
CMD ["./system-monitor-server", "-transport=http", "-port=8080", "-log-level=info"]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# System Monitor Server Makefile
2+
# This Makefile provides common build, test, and development tasks
3+
4+
.PHONY: help build test clean run install deps lint fmt vet
5+
6+
# Default target
7+
help:
8+
@echo "Available targets:"
9+
@echo " build - Build the system-monitor-server binary"
10+
@echo " test - Run all tests"
11+
@echo " clean - Clean build artifacts"
12+
@echo " run - Run the server in stdio mode"
13+
@echo " install - Install the binary to GOPATH/bin"
14+
@echo " deps - Download and verify dependencies"
15+
@echo " lint - Run linters"
16+
@echo " fmt - Format code"
17+
@echo " vet - Run go vet"
18+
@echo " docker - Build Docker image"
19+
@echo " examples - Run example commands"
20+
21+
# Build the binary
22+
build:
23+
@echo "Building system-monitor-server..."
24+
@go build -o system-monitor-server ./cmd/server
25+
@echo "Build complete: system-monitor-server"
26+
27+
# Run tests
28+
test:
29+
@echo "Running tests..."
30+
@go test -v -race -coverprofile=coverage.out ./...
31+
@go tool cover -html=coverage.out -o coverage.html
32+
@echo "Test coverage report: coverage.html"
33+
34+
# Clean build artifacts
35+
clean:
36+
@echo "Cleaning build artifacts..."
37+
@rm -f system-monitor-server
38+
@rm -f coverage.out coverage.html
39+
@go clean
40+
41+
# Run the server in stdio mode
42+
run: build
43+
@echo "Running system-monitor-server in stdio mode..."
44+
@./system-monitor-server -log-level=info
45+
46+
# Install the binary
47+
install: build
48+
@echo "Installing system-monitor-server..."
49+
@go install ./cmd/server
50+
@echo "Installed to: $(shell go env GOPATH)/bin/system-monitor-server"
51+
52+
# Download dependencies
53+
deps:
54+
@echo "Downloading dependencies..."
55+
@go mod download
56+
@go mod verify
57+
@echo "Dependencies downloaded and verified"
58+
59+
# Run linters
60+
lint:
61+
@echo "Running linters..."
62+
@if command -v golangci-lint >/dev/null 2>&1; then \
63+
golangci-lint run; \
64+
else \
65+
echo "golangci-lint not found, installing..."; \
66+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
67+
golangci-lint run; \
68+
fi
69+
70+
# Format code
71+
fmt:
72+
@echo "Formatting code..."
73+
@go fmt ./...
74+
@if command -v goimports >/dev/null 2>&1; then \
75+
goimports -w .; \
76+
else \
77+
echo "goimports not found, installing..."; \
78+
go install golang.org/x/tools/cmd/goimports@latest; \
79+
goimports -w .; \
80+
fi
81+
82+
# Run go vet
83+
vet:
84+
@echo "Running go vet..."
85+
@go vet ./...
86+
87+
# Build Docker image
88+
docker:
89+
@echo "Building Docker image..."
90+
@docker build -t system-monitor-server:latest .
91+
@echo "Docker image built: system-monitor-server:latest"
92+
93+
# Run example commands
94+
examples: build
95+
@echo "Running example commands..."
96+
@echo ""
97+
@echo "1. Get system metrics:"
98+
@echo 'echo '"'"'{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_system_metrics","arguments":{}},"id":1}'"'"' | ./system-monitor-server'
99+
@echo ""
100+
@echo "2. List processes:"
101+
@echo 'echo '"'"'{"jsonrpc":"2.0","method":"tools/call","params":{"name":"list_processes","arguments":{"sort_by":"cpu","limit":5}},"id":2}'"'"' | ./system-monitor-server'
102+
@echo ""
103+
@echo "3. Check service health:"
104+
@echo 'echo '"'"'{"jsonrpc":"2.0","method":"tools/call","params":{"name":"check_service_health","arguments":{"services":[{"name":"web","type":"http","target":"http://localhost:8080/health"}]}},"id":3}'"'"' | ./system-monitor-server'
105+
106+
# Development server with hot reload
107+
dev:
108+
@echo "Starting development server with hot reload..."
109+
@if command -v air >/dev/null 2>&1; then \
110+
air; \
111+
else \
112+
echo "air not found, installing..."; \
113+
go install github.com/cosmtrek/air@latest; \
114+
air; \
115+
fi
116+
117+
# Generate mocks for testing
118+
mocks:
119+
@echo "Generating mocks..."
120+
@if command -v mockgen >/dev/null 2>&1; then \
121+
mockgen -source=internal/metrics/system.go -destination=internal/metrics/mocks/system_mock.go; \
122+
mockgen -source=internal/metrics/process.go -destination=internal/metrics/mocks/process_mock.go; \
123+
mockgen -source=internal/monitor/health_checker.go -destination=internal/monitor/mocks/health_checker_mock.go; \
124+
mockgen -source=internal/monitor/log_monitor.go -destination=internal/monitor/mocks/log_monitor_mock.go; \
125+
else \
126+
echo "mockgen not found, installing..."; \
127+
go install github.com/golang/mock/mockgen@latest; \
128+
mockgen -source=internal/metrics/system.go -destination=internal/metrics/mocks/system_mock.go; \
129+
mockgen -source=internal/metrics/process.go -destination=internal/metrics/mocks/process_mock.go; \
130+
mockgen -source=internal/monitor/health_checker.go -destination=internal/monitor/mocks/health_checker_mock.go; \
131+
mockgen -source=internal/monitor/log_monitor.go -destination=internal/monitor/mocks/log_monitor_mock.go; \
132+
fi
133+
134+
# Benchmark tests
135+
bench:
136+
@echo "Running benchmarks..."
137+
@go test -bench=. -benchmem ./...
138+
139+
# Security scan
140+
security:
141+
@echo "Running security scan..."
142+
@if command -v gosec >/dev/null 2>&1; then \
143+
gosec ./...; \
144+
else \
145+
echo "gosec not found, installing..."; \
146+
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest; \
147+
gosec ./...; \
148+
fi
149+
150+
# All checks
151+
check: fmt vet lint test security
152+
@echo "All checks passed!"
153+
154+
# Release build
155+
release: clean
156+
@echo "Building release binaries..."
157+
@GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o system-monitor-server-linux-amd64 ./cmd/server
158+
@GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o system-monitor-server-darwin-amd64 ./cmd/server
159+
@GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o system-monitor-server-windows-amd64.exe ./cmd/server
160+
@echo "Release binaries built:"
161+
@ls -la system-monitor-server-*

0 commit comments

Comments
 (0)