npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codelook/codebox-registry

v0.1.1

Published

Service registry and monitoring for Codebox deployed applications

Readme

@codelook/codebox-registry

专为 Codebox 设计的服务注册中心和监控系统,用于管理通过 Codebox 部署的应用程序。

功能特性

  • 🔍 服务注册与发现:自动记录和管理所有已部署的服务
  • 💓 健康检查:定期检查服务健康状态,支持自定义检查间隔
  • 🎮 生命周期管理:启动、停止、重启、销毁服务
  • 📊 监控指标:追踪服务运行时间、错误率、响应时间等
  • 🌐 RESTful API:提供完整的 HTTP API 接口
  • 💾 持久化存储:使用 SQLite 存储服务信息和历史记录
  • 📡 事件追踪:记录所有服务状态变更和操作历史

安装

npm install @codelook/codebox-registry

快速开始

作为库使用

import { ServiceRegistry, ServiceType, ServiceStatus } from '@codelook/codebox-registry';

// 创建注册中心实例
const registry = new ServiceRegistry({
  api: {
    enabled: true,
    port: 9091
  }
});

// 启动注册中心
await registry.start();

// 注册一个服务
await registry.registerService({
  id: 'srv-001',
  projectId: 'proj-001',
  serverId: 'server-001',
  deploymentId: 'deploy-001',
  name: 'my-api-service',
  type: ServiceType.Docker,
  host: 'localhost',
  port: 3000,
  url: 'http://localhost:3000',
  status: ServiceStatus.Running,
  version: '1.0.0',
  deployedAt: new Date().toISOString(),
  healthCheck: {
    enabled: true,
    endpoint: 'http://localhost:3000/health',
    interval: 30000,
    timeout: 5000,
    retries: 3
  }
});

// 获取服务状态
const stats = registry.getStatistics();
console.log(stats);

CLI 使用

# 启动服务注册中心
service-registry start --port 9091

# 列出所有服务
service-registry list

# 查看统计信息
service-registry stats

# 手动健康检查
service-registry check srv-001

# 清理旧数据
service-registry cleanup --days 30

API 接口

服务管理

# 获取所有服务
GET /api/services

# 获取单个服务
GET /api/services/:id

# 注册新服务
POST /api/services

# 更新服务
PUT /api/services/:id

# 删除服务
DELETE /api/services/:id

服务操作

# 启动服务
POST /api/services/:id/start

# 停止服务
POST /api/services/:id/stop

# 重启服务
POST /api/services/:id/restart

# 销毁服务(需要确认)
POST /api/services/:id/destroy
{
  "confirm": true
}

健康检查

# 执行健康检查
POST /api/services/:id/health-check

# 批量健康检查
POST /api/health-check/all

监控数据

# 获取服务事件
GET /api/services/:id/events

# 获取操作历史
GET /api/services/:id/operations

# 获取统计信息
GET /api/stats

配置选项

interface RegistryConfig {
  database: {
    type: 'sqlite' | 'postgres';
    path?: string; // SQLite 数据库路径
    connectionString?: string; // PostgreSQL 连接字符串
  };
  healthCheck: {
    enabled: boolean;
    defaultInterval: number; // 默认检查间隔(毫秒)
    defaultTimeout: number; // 默认超时时间(毫秒)
    defaultRetries: number; // 默认重试次数
  };
  api: {
    enabled: boolean;
    port: number;
    host: string;
    auth?: {
      enabled: boolean;
      token?: string;
    };
  };
  monitoring: {
    retentionDays: number; // 数据保留天数
    metricsInterval: number; // 指标更新间隔(毫秒)
  };
}

与 Codebox 集成

codebox-registry 专为与 Codebox 部署工具无缝集成而设计:

// 在 codebox 中集成
import { ServiceRegistry } from '@codelook/codebox-registry';

// 部署成功后自动注册
const registry = new ServiceRegistry();
await registry.registerService({
  id: `srv-${Date.now()}`,
  projectId: project.id,
  serverId: server.id,
  deploymentId: deployment.id,
  name: project.name,
  type: project.type,
  host: server.host,
  port: deployment.port,
  url: `http://${server.host}:${deployment.port}`,
  status: 'running',
  version: deployment.version,
  deployedAt: new Date().toISOString()
});

数据模型

DeployedService

interface DeployedService {
  id: string;
  projectId: string;
  serverId: string;
  deploymentId: string;
  name: string;
  type: ServiceType;
  host: string;
  port?: number;
  url: string;
  healthCheck?: HealthCheckConfig;
  status: ServiceStatus;
  version: string;
  deployedAt: string;
  lastHealthCheck?: string;
  lastStatusChange?: string;
  metrics?: ServiceMetrics;
  metadata?: Record<string, any>;
  tags?: string[];
}

ServiceMetrics

interface ServiceMetrics {
  uptime: number; // 运行时间(秒)
  requestCount: number;
  errorCount: number;
  errorRate: number;
  lastResponseTime?: number; // 最后响应时间(毫秒)
  avgResponseTime: number;
  healthChecksPassed: number;
  healthChecksFailed: number;
}

License

MIT