2014-08-08 03:01:55 +00:00
package daemon
import (
"os"
"runtime"
2015-03-10 18:25:47 +00:00
"time"
2014-08-08 03:01:55 +00:00
2014-10-24 22:11:48 +00:00
log "github.com/Sirupsen/logrus"
2015-02-04 21:22:38 +00:00
"github.com/docker/docker/autogen/dockerversion"
2014-08-08 03:01:55 +00:00
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/parsers/operatingsystem"
2014-10-24 22:48:23 +00:00
"github.com/docker/docker/pkg/system"
2014-08-08 03:01:55 +00:00
"github.com/docker/docker/registry"
"github.com/docker/docker/utils"
)
2015-03-25 07:44:12 +00:00
func ( daemon * Daemon ) CmdInfo ( job * engine . Job ) error {
2014-08-08 03:01:55 +00:00
images , _ := daemon . Graph ( ) . Map ( )
var imgcount int
if images == nil {
imgcount = 0
} else {
imgcount = len ( images )
}
kernelVersion := "<unknown>"
if kv , err := kernel . GetKernelVersion ( ) ; err == nil {
kernelVersion = kv . String ( )
}
operatingSystem := "<unknown>"
if s , err := operatingsystem . GetOperatingSystem ( ) ; err == nil {
operatingSystem = s
}
if inContainer , err := operatingsystem . IsContainerized ( ) ; err != nil {
2014-07-24 20:37:44 +00:00
log . Errorf ( "Could not determine if daemon is containerized: %v" , err )
2014-08-08 03:01:55 +00:00
operatingSystem += " (error determining if containerized)"
} else if inContainer {
operatingSystem += " (containerized)"
}
2014-10-24 22:48:23 +00:00
meminfo , err := system . ReadMemInfo ( )
if err != nil {
log . Errorf ( "Could not read system memory info: %v" , err )
}
2014-08-08 03:01:55 +00:00
// if we still have the original dockerinit binary from before we copied it locally, let's return the path to that, since that's more intuitive (the copied path is trivial to derive by hand given VERSION)
initPath := utils . DockerInitPath ( "" )
if initPath == "" {
// if that fails, we'll just return the path from the daemon
initPath = daemon . SystemInitPath ( )
}
cjob := job . Eng . Job ( "subscribers_count" )
env , _ := cjob . Stdout . AddEnv ( )
if err := cjob . Run ( ) ; err != nil {
2015-03-25 07:44:12 +00:00
return err
2014-08-08 03:01:55 +00:00
}
2014-10-07 01:54:52 +00:00
registryJob := job . Eng . Job ( "registry_config" )
registryEnv , _ := registryJob . Stdout . AddEnv ( )
if err := registryJob . Run ( ) ; err != nil {
2015-03-25 07:44:12 +00:00
return err
2014-10-07 01:54:52 +00:00
}
registryConfig := registry . ServiceConfig { }
if err := registryEnv . GetJson ( "config" , & registryConfig ) ; err != nil {
2015-03-25 07:44:12 +00:00
return err
2014-10-07 01:54:52 +00:00
}
2014-08-08 03:01:55 +00:00
v := & engine . Env { }
2014-12-11 12:56:21 +00:00
v . SetJson ( "ID" , daemon . ID )
2014-08-08 03:01:55 +00:00
v . SetInt ( "Containers" , len ( daemon . List ( ) ) )
v . SetInt ( "Images" , imgcount )
v . Set ( "Driver" , daemon . GraphDriver ( ) . String ( ) )
v . SetJson ( "DriverStatus" , daemon . GraphDriver ( ) . Status ( ) )
v . SetBool ( "MemoryLimit" , daemon . SystemConfig ( ) . MemoryLimit )
v . SetBool ( "SwapLimit" , daemon . SystemConfig ( ) . SwapLimit )
v . SetBool ( "IPv4Forwarding" , ! daemon . SystemConfig ( ) . IPv4ForwardingDisabled )
v . SetBool ( "Debug" , os . Getenv ( "DEBUG" ) != "" )
v . SetInt ( "NFd" , utils . GetTotalUsedFds ( ) )
v . SetInt ( "NGoroutines" , runtime . NumGoroutine ( ) )
2015-03-10 18:25:47 +00:00
v . Set ( "SystemTime" , time . Now ( ) . Format ( time . RFC3339Nano ) )
2014-08-08 03:01:55 +00:00
v . Set ( "ExecutionDriver" , daemon . ExecutionDriver ( ) . Name ( ) )
v . SetInt ( "NEventsListener" , env . GetInt ( "count" ) )
v . Set ( "KernelVersion" , kernelVersion )
v . Set ( "OperatingSystem" , operatingSystem )
v . Set ( "IndexServerAddress" , registry . IndexServerAddress ( ) )
2014-10-07 01:54:52 +00:00
v . SetJson ( "RegistryConfig" , registryConfig )
2014-08-08 03:01:55 +00:00
v . Set ( "InitSha1" , dockerversion . INITSHA1 )
v . Set ( "InitPath" , initPath )
2014-10-24 22:48:23 +00:00
v . SetInt ( "NCPU" , runtime . NumCPU ( ) )
v . SetInt64 ( "MemTotal" , meminfo . MemTotal )
2014-12-03 23:29:54 +00:00
v . Set ( "DockerRootDir" , daemon . Config ( ) . Root )
2015-03-03 03:15:17 +00:00
if http_proxy := os . Getenv ( "http_proxy" ) ; http_proxy != "" {
v . Set ( "HttpProxy" , http_proxy )
}
if https_proxy := os . Getenv ( "https_proxy" ) ; https_proxy != "" {
v . Set ( "HttpsProxy" , https_proxy )
}
if no_proxy := os . Getenv ( "no_proxy" ) ; no_proxy != "" {
v . Set ( "NoProxy" , no_proxy )
}
2014-11-17 19:23:41 +00:00
if hostname , err := os . Hostname ( ) ; err == nil {
2014-12-11 12:56:21 +00:00
v . SetJson ( "Name" , hostname )
2014-11-17 19:23:41 +00:00
}
2014-11-20 18:36:05 +00:00
v . SetList ( "Labels" , daemon . Config ( ) . Labels )
2014-08-08 03:01:55 +00:00
if _ , err := v . WriteTo ( job . Stdout ) ; err != nil {
2015-03-25 07:44:12 +00:00
return err
2014-08-08 03:01:55 +00:00
}
2015-03-25 07:44:12 +00:00
return nil
2014-08-08 03:01:55 +00:00
}